Improved const correctness, fixed thread safety bug.

[SVN r34774]
This commit is contained in:
John Maddock
2006-07-29 16:01:48 +00:00
parent d3b885e20b
commit 65347f0f7f
3 changed files with 26 additions and 24 deletions

View File

@ -35,16 +35,16 @@ template <class Key, class Object>
class object_cache
{
public:
typedef std::pair< ::boost::shared_ptr<Object>, Key const*> value_type;
typedef std::pair< ::boost::shared_ptr<Object const>, Key const*> value_type;
typedef std::list<value_type> list_type;
typedef typename list_type::iterator list_iterator;
typedef std::map<Key, list_iterator> map_type;
typedef typename map_type::iterator map_iterator;
typedef typename list_type::size_type size_type;
static boost::shared_ptr<Object> get(const Key& k, size_type max_cache_size);
static boost::shared_ptr<Object const> get(const Key& k, size_type max_cache_size);
private:
static boost::shared_ptr<Object> do_get(const Key& k, size_type max_cache_size);
static boost::shared_ptr<Object const> do_get(const Key& k, size_type max_cache_size);
struct data
{
@ -58,7 +58,7 @@ private:
};
template <class Key, class Object>
boost::shared_ptr<Object> object_cache<Key, Object>::get(const Key& k, size_type max_cache_size)
boost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, size_type max_cache_size)
{
#ifdef BOOST_HAS_THREADS
static boost::static_mutex mut = BOOST_STATIC_MUTEX_INIT;
@ -80,7 +80,7 @@ boost::shared_ptr<Object> object_cache<Key, Object>::get(const Key& k, size_type
}
template <class Key, class Object>
boost::shared_ptr<Object> object_cache<Key, Object>::do_get(const Key& k, size_type max_cache_size)
boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k, size_type max_cache_size)
{
typedef typename object_cache<Key, Object>::data object_data;
typedef typename map_type::size_type map_size_type;
@ -115,7 +115,7 @@ boost::shared_ptr<Object> object_cache<Key, Object>::do_get(const Key& k, size_t
// if we get here then the item is not in the cache,
// so create it:
//
boost::shared_ptr<Object> result(new Object(k));
boost::shared_ptr<Object const> result(new Object(k));
//
// Add it to the list, and index it:
//

View File

@ -407,12 +407,12 @@ public:
typedef charT char_type;
//cpp_regex_traits_implementation();
cpp_regex_traits_implementation(const std::locale& l)
: cpp_regex_traits_char_layer<charT>(l), m_is(&m_sbuf)
: cpp_regex_traits_char_layer<charT>(l)
{
init();
}
cpp_regex_traits_implementation(const cpp_regex_traits_base<charT>& l)
: cpp_regex_traits_char_layer<charT>(l), m_is(&m_sbuf)
: cpp_regex_traits_char_layer<charT>(l)
{
init();
}
@ -439,8 +439,6 @@ public:
string_type lookup_collatename(const charT* p1, const charT* p2) const;
string_type transform_primary(const charT* p1, const charT* p2) const;
string_type transform(const charT* p1, const charT* p2) const;
re_detail::parser_buf<charT> m_sbuf; // buffer for parsing numbers.
std::basic_istream<charT> m_is; // stream for parsing numbers.
private:
std::map<int, std::string> m_error_strings; // error messages indexed by numberic ID
std::map<string_type, char_class_type> m_custom_class_names; // character class names
@ -816,7 +814,7 @@ bool cpp_regex_traits_implementation<charT>::isctype(const charT c, char_class_t
template <class charT>
inline boost::shared_ptr<cpp_regex_traits_implementation<charT> > create_cpp_regex_traits(const std::locale& l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
inline boost::shared_ptr<const cpp_regex_traits_implementation<charT> > create_cpp_regex_traits(const std::locale& l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
{
cpp_regex_traits_base<charT> key(l);
return ::boost::object_cache<cpp_regex_traits_base<charT>, cpp_regex_traits_implementation<charT> >::get(key, 5);
@ -954,7 +952,7 @@ public:
static std::string get_catalog_name();
private:
boost::shared_ptr<re_detail::cpp_regex_traits_implementation<charT> > m_pimpl;
boost::shared_ptr<const re_detail::cpp_regex_traits_implementation<charT> > m_pimpl;
//
// catalog name handler:
//
@ -969,17 +967,21 @@ private:
template <class charT>
int cpp_regex_traits<charT>::toi(const charT*& first, const charT* last, int radix)const
{
re_detail::parser_buf<charT> sbuf; // buffer for parsing numbers.
std::basic_istream<charT> is(&sbuf); // stream for parsing numbers.
// we do NOT want to parse any thousands separators inside the stream:
last = std::find(first, last, BOOST_USE_FACET(std::numpunct<charT>, m_pimpl->m_is.getloc()).thousands_sep());
m_pimpl->m_sbuf.pubsetbuf(const_cast<charT*>(static_cast<const charT*>(first)), static_cast<std::streamsize>(last-first));
m_pimpl->m_is.clear();
if(std::abs(radix) == 16) m_pimpl->m_is >> std::hex;
else if(std::abs(radix) == 8) m_pimpl->m_is >> std::oct;
else m_pimpl->m_is >> std::dec;
last = std::find(first, last, BOOST_USE_FACET(std::numpunct<charT>, is.getloc()).thousands_sep());
sbuf.pubsetbuf(const_cast<charT*>(static_cast<const charT*>(first)), static_cast<std::streamsize>(last-first));
is.clear();
if(std::abs(radix) == 16) is >> std::hex;
else if(std::abs(radix) == 8) is >> std::oct;
else is >> std::dec;
int val;
if(m_pimpl->m_is >> val)
if(is >> val)
{
first = first + ((last - first) - m_pimpl->m_sbuf.in_avail());
first = first + ((last - first) - sbuf.in_avail());
return val;
}
else

View File

@ -166,7 +166,7 @@ public:
{
return ::boost::re_detail::w32_tolower(c, this->m_locale);
}
bool isctype(boost::uint32_t mask, charT c)
bool isctype(boost::uint32_t mask, charT c)const
{
return ::boost::re_detail::w32_is(this->m_locale, mask, c);
}
@ -263,7 +263,7 @@ public:
{
return m_lower_map[static_cast<unsigned char>(c)];
}
bool isctype(boost::uint32_t mask, char c)
bool isctype(boost::uint32_t mask, char c)const
{
return m_type_map[static_cast<unsigned char>(c)] & mask;
}
@ -540,7 +540,7 @@ typename w32_regex_traits_implementation<charT>::char_class_type
template <class charT>
boost::shared_ptr<w32_regex_traits_implementation<charT> > create_w32_regex_traits(::boost::re_detail::lcid_type l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
boost::shared_ptr<const w32_regex_traits_implementation<charT> > create_w32_regex_traits(::boost::re_detail::lcid_type l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
{
// TODO: create a cache for previously constructed objects.
return boost::object_cache< ::boost::re_detail::lcid_type, w32_regex_traits_implementation<charT> >::get(l, 5);
@ -654,7 +654,7 @@ public:
static std::string get_catalog_name();
private:
boost::shared_ptr<re_detail::w32_regex_traits_implementation<charT> > m_pimpl;
boost::shared_ptr<const re_detail::w32_regex_traits_implementation<charT> > m_pimpl;
//
// catalog name handler:
//