forked from boostorg/regex
Remove a lot of boost dependencies and workarounds.
This commit is contained in:
@ -19,14 +19,24 @@
|
||||
#ifndef BOOST_REGEX_OBJECT_CACHE_HPP
|
||||
#define BOOST_REGEX_OBJECT_CACHE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/regex/config.hpp>
|
||||
#ifdef BOOST_REGEX_CXX03
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#define BOOST_REGEX_SHARED_PTR_NS boost
|
||||
#else
|
||||
#include <memory>
|
||||
#define BOOST_REGEX_SHARED_PTR_NS std
|
||||
#endif
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#ifdef BOOST_HAS_THREADS
|
||||
#ifdef BOOST_REGEX_CXX03
|
||||
#include <boost/regex/pending/static_mutex.hpp>
|
||||
#else
|
||||
#include <mutex>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost{
|
||||
@ -35,16 +45,16 @@ template <class Key, class Object>
|
||||
class object_cache
|
||||
{
|
||||
public:
|
||||
typedef std::pair< ::boost::shared_ptr<Object const>, Key const*> value_type;
|
||||
typedef std::pair< BOOST_REGEX_SHARED_PTR_NS::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 const> get(const Key& k, size_type l_max_cache_size);
|
||||
static BOOST_REGEX_SHARED_PTR_NS::shared_ptr<Object const> get(const Key& k, size_type l_max_cache_size);
|
||||
|
||||
private:
|
||||
static boost::shared_ptr<Object const> do_get(const Key& k, size_type l_max_cache_size);
|
||||
static BOOST_REGEX_SHARED_PTR_NS::shared_ptr<Object const> do_get(const Key& k, size_type l_max_cache_size);
|
||||
|
||||
struct data
|
||||
{
|
||||
@ -62,13 +72,13 @@ private:
|
||||
#pragma warning(disable: 4702)
|
||||
#endif
|
||||
template <class Key, class Object>
|
||||
boost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, size_type l_max_cache_size)
|
||||
BOOST_REGEX_SHARED_PTR_NS::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, size_type l_max_cache_size)
|
||||
{
|
||||
#ifdef BOOST_HAS_THREADS
|
||||
#ifdef BOOST_REGEX_CXX03
|
||||
static boost::static_mutex mut = BOOST_STATIC_MUTEX_INIT;
|
||||
|
||||
boost::static_mutex::scoped_lock l(mut);
|
||||
if(l)
|
||||
if (l)
|
||||
{
|
||||
return do_get(k, l_max_cache_size);
|
||||
}
|
||||
@ -78,7 +88,12 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, siz
|
||||
//
|
||||
::boost::throw_exception(std::runtime_error("Error in thread safety code: could not acquire a lock"));
|
||||
#if defined(BOOST_NO_UNREACHABLE_RETURN_DETECTION) || defined(BOOST_NO_EXCEPTIONS)
|
||||
return boost::shared_ptr<Object>();
|
||||
return BOOST_REGEX_SHARED_PTR_NS::shared_ptr<Object>();
|
||||
#endif
|
||||
#else
|
||||
static std::mutex mut;
|
||||
std::lock_guard<std::mutex> l(mut);
|
||||
return do_get(k, l_max_cache_size);
|
||||
#endif
|
||||
#else
|
||||
return do_get(k, l_max_cache_size);
|
||||
@ -89,7 +104,7 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, siz
|
||||
#endif
|
||||
|
||||
template <class Key, class Object>
|
||||
boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k, size_type l_max_cache_size)
|
||||
BOOST_REGEX_SHARED_PTR_NS::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k, size_type l_max_cache_size)
|
||||
{
|
||||
typedef typename object_cache<Key, Object>::data object_data;
|
||||
typedef typename map_type::size_type map_size_type;
|
||||
@ -112,11 +127,11 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k,
|
||||
temp.splice(temp.end(), s_data.cont, mpos->second);
|
||||
// and now place it at the end of the list:
|
||||
s_data.cont.splice(s_data.cont.end(), temp, temp.begin());
|
||||
BOOST_ASSERT(*(s_data.cont.back().second) == k);
|
||||
BOOST_REGEX_ASSERT(*(s_data.cont.back().second) == k);
|
||||
// update index with new position:
|
||||
mpos->second = --(s_data.cont.end());
|
||||
BOOST_ASSERT(&(mpos->first) == mpos->second->second);
|
||||
BOOST_ASSERT(&(mpos->first) == s_data.cont.back().second);
|
||||
BOOST_REGEX_ASSERT(&(mpos->first) == mpos->second->second);
|
||||
BOOST_REGEX_ASSERT(&(mpos->first) == s_data.cont.back().second);
|
||||
}
|
||||
return s_data.cont.back().first;
|
||||
}
|
||||
@ -124,7 +139,7 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k,
|
||||
// if we get here then the item is not in the cache,
|
||||
// so create it:
|
||||
//
|
||||
boost::shared_ptr<Object const> result(new Object(k));
|
||||
BOOST_REGEX_SHARED_PTR_NS::shared_ptr<Object const> result(new Object(k));
|
||||
//
|
||||
// Add it to the list, and index it:
|
||||
//
|
||||
@ -132,9 +147,9 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k,
|
||||
s_data.index.insert(std::make_pair(k, --(s_data.cont.end())));
|
||||
s_data.cont.back().second = &(s_data.index.find(k)->first);
|
||||
map_size_type s = s_data.index.size();
|
||||
BOOST_ASSERT(s_data.index[k]->first.get() == result.get());
|
||||
BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
|
||||
BOOST_ASSERT(s_data.index.find(k)->first == k);
|
||||
BOOST_REGEX_ASSERT(s_data.index[k]->first.get() == result.get());
|
||||
BOOST_REGEX_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
|
||||
BOOST_REGEX_ASSERT(s_data.index.find(k)->first == k);
|
||||
if(s > l_max_cache_size)
|
||||
{
|
||||
//
|
||||
@ -152,7 +167,7 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k,
|
||||
++pos;
|
||||
// now remove the items from our containers,
|
||||
// then order has to be as follows:
|
||||
BOOST_ASSERT(s_data.index.find(*(condemmed->second)) != s_data.index.end());
|
||||
BOOST_REGEX_ASSERT(s_data.index.find(*(condemmed->second)) != s_data.index.end());
|
||||
s_data.index.erase(*(condemmed->second));
|
||||
s_data.cont.erase(condemmed);
|
||||
--s;
|
||||
@ -160,13 +175,13 @@ boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k,
|
||||
else
|
||||
++pos;
|
||||
}
|
||||
BOOST_ASSERT(s_data.index[k]->first.get() == result.get());
|
||||
BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
|
||||
BOOST_ASSERT(s_data.index.find(k)->first == k);
|
||||
BOOST_REGEX_ASSERT(s_data.index[k]->first.get() == result.get());
|
||||
BOOST_REGEX_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
|
||||
BOOST_REGEX_ASSERT(s_data.index.find(k)->first == k);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
#undef BOOST_REGEX_SHARED_PTR_NS
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user