~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to libs/boost-lib/boost/regex/pending/object_cache.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
class object_cache
36
36
{
37
37
public:
38
 
   typedef std::pair< ::boost::shared_ptr<Object>, Key const*> value_type;
 
38
   typedef std::pair< ::boost::shared_ptr<Object const>, Key const*> value_type;
39
39
   typedef std::list<value_type> list_type;
40
40
   typedef typename list_type::iterator list_iterator;
41
41
   typedef std::map<Key, list_iterator> map_type;
42
42
   typedef typename map_type::iterator map_iterator;
43
43
   typedef typename list_type::size_type size_type;
44
 
   static boost::shared_ptr<Object> get(const Key& k, size_type max_cache_size);
 
44
   static boost::shared_ptr<Object const> get(const Key& k, size_type max_cache_size);
45
45
 
46
46
private:
47
 
   static boost::shared_ptr<Object> do_get(const Key& k, size_type max_cache_size);
 
47
   static boost::shared_ptr<Object const> do_get(const Key& k, size_type max_cache_size);
48
48
 
49
49
   struct data
50
50
   {
58
58
};
59
59
 
60
60
template <class Key, class Object>
61
 
boost::shared_ptr<Object> object_cache<Key, Object>::get(const Key& k, size_type max_cache_size)
 
61
boost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, size_type max_cache_size)
62
62
{
63
63
#ifdef BOOST_HAS_THREADS
64
64
   static boost::static_mutex mut = BOOST_STATIC_MUTEX_INIT;
73
73
   // for now just throw, but we should never really get here...
74
74
   //
75
75
   ::boost::throw_exception(std::runtime_error("Error in thread safety code: could not acquire a lock"));
 
76
#ifdef BOOST_NO_UNREACHABLE_RETURN_DETECTION
76
77
   return boost::shared_ptr<Object>();
 
78
#endif
77
79
#else
78
80
   return do_get(k, max_cache_size);
79
81
#endif
80
82
}
81
83
 
82
84
template <class Key, class Object>
83
 
boost::shared_ptr<Object> object_cache<Key, Object>::do_get(const Key& k, size_type max_cache_size)
 
85
boost::shared_ptr<Object const> object_cache<Key, Object>::do_get(const Key& k, size_type max_cache_size)
84
86
{
85
87
   typedef typename object_cache<Key, Object>::data object_data;
86
 
   typedef typename list_type::size_type list_size_type;
 
88
   typedef typename map_type::size_type map_size_type;
87
89
   static object_data s_data;
88
90
 
89
91
   //
115
117
   // if we get here then the item is not in the cache,
116
118
   // so create it:
117
119
   //
118
 
   boost::shared_ptr<Object> result(new Object(k));
 
120
   boost::shared_ptr<Object const> result(new Object(k));
119
121
   //
120
122
   // Add it to the list, and index it:
121
123
   //
122
 
   s_data.cont.push_back(value_type(result, 0));
 
124
   s_data.cont.push_back(value_type(result, static_cast<Key const*>(0)));
123
125
   s_data.index.insert(std::make_pair(k, --(s_data.cont.end())));
124
126
   s_data.cont.back().second = &(s_data.index.find(k)->first);
125
 
   list_size_type s = s_data.cont.size();
 
127
   map_size_type s = s_data.index.size();
126
128
   BOOST_ASSERT(s_data.index[k]->first.get() == result.get());
127
129
   BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
128
130
   BOOST_ASSERT(s_data.index.find(k)->first == k);