PageRenderTime 57ms CodeModel.GetById 12ms app.highlight 41ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/interprocess/containers/container/detail/multiallocation_chain.hpp

http://hadesmem.googlecode.com/
C++ Header | 245 lines | 170 code | 63 blank | 12 comment | 0 complexity | a7f0455240fd1902a6507d1b7474062d MD5 | raw file
  1//////////////////////////////////////////////////////////////////////////////
  2//
  3// (C) Copyright Ion Gaztanaga 2005-2009. Distributed under the Boost
  4// Software License, Version 1.0. (See accompanying file
  5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6//
  7// See http://www.boost.org/libs/container for documentation.
  8//
  9//////////////////////////////////////////////////////////////////////////////
 10
 11#ifndef BOOST_CONTAINERS_DETAIL_MULTIALLOCATION_CHAIN_HPP
 12#define BOOST_CONTAINERS_DETAIL_MULTIALLOCATION_CHAIN_HPP
 13
 14#include "config_begin.hpp"
 15#include INCLUDE_BOOST_CONTAINER_CONTAINER_FWD_HPP
 16#include INCLUDE_BOOST_CONTAINER_DETAIL_UTILITIES_HPP
 17#include INCLUDE_BOOST_CONTAINER_DETAIL_TYPE_TRAITS_HPP
 18#include INCLUDE_BOOST_CONTAINER_DETAIL_TRANSFORM_ITERATOR_HPP
 19#include <boost/intrusive/slist.hpp>
 20#include <boost/pointer_to_other.hpp>
 21#include INCLUDE_BOOST_CONTAINER_MOVE_HPP
 22
 23namespace boost {
 24namespace container {
 25namespace containers_detail {
 26
 27template<class VoidPointer>
 28class basic_multiallocation_chain
 29{
 30   private:
 31   typedef bi::slist_base_hook<bi::void_pointer<VoidPointer>
 32                        ,bi::link_mode<bi::normal_link>
 33                        > node;
 34
 35   typedef bi::slist< node
 36                    , bi::linear<true>
 37                    , bi::cache_last<true>
 38                    > slist_impl_t;
 39   slist_impl_t slist_impl_;
 40
 41   static node & to_node(VoidPointer p)
 42   {  return *static_cast<node*>(static_cast<void*>(containers_detail::get_pointer(p))); }
 43
 44   BOOST_MOVE_MACRO_MOVABLE_BUT_NOT_COPYABLE(basic_multiallocation_chain)
 45
 46   public:
 47
 48
 49   typedef VoidPointer  void_pointer;
 50   typedef typename slist_impl_t::iterator iterator;
 51
 52   basic_multiallocation_chain()
 53      :  slist_impl_()
 54   {}
 55
 56   basic_multiallocation_chain(BOOST_MOVE_MACRO_RV_REF(basic_multiallocation_chain) other)
 57      :  slist_impl_()
 58   {  slist_impl_.swap(other.slist_impl_); }
 59
 60   basic_multiallocation_chain& operator=(BOOST_MOVE_MACRO_RV_REF(basic_multiallocation_chain) other)
 61   {
 62      basic_multiallocation_chain tmp(BOOST_CONTAINER_MOVE_NAMESPACE::move(other));
 63      this->swap(tmp);
 64      return *this;
 65   }
 66
 67   bool empty() const
 68   {  return slist_impl_.empty(); }
 69
 70   std::size_t size() const
 71   {  return slist_impl_.size();  }
 72
 73   iterator before_begin()
 74   {  return slist_impl_.before_begin(); }
 75
 76   iterator begin()
 77   {  return slist_impl_.begin(); }
 78
 79   iterator end()
 80   {  return slist_impl_.end(); }
 81
 82   iterator last()
 83   {  return slist_impl_.last(); }
 84
 85   void clear()
 86   {  slist_impl_.clear(); }
 87
 88   iterator insert_after(iterator it, void_pointer m)
 89   {  return slist_impl_.insert_after(it, to_node(m));   }
 90
 91   void push_front(void_pointer m)
 92   {  return slist_impl_.push_front(to_node(m));   }
 93
 94   void push_back(void_pointer m)
 95   {  return slist_impl_.push_back(to_node(m));   }
 96
 97   void pop_front()
 98   {  return slist_impl_.pop_front();   }
 99
100   void *front()
101   {  return &*slist_impl_.begin();   }
102
103   void splice_after(iterator after_this, basic_multiallocation_chain &x, iterator before_begin, iterator before_end)
104   {  slist_impl_.splice_after(after_this, x.slist_impl_, before_begin, before_end);   }
105
106   void splice_after(iterator after_this, basic_multiallocation_chain &x, iterator before_begin, iterator before_end, std::size_t n)
107   {  slist_impl_.splice_after(after_this, x.slist_impl_, before_begin, before_end, n);   }
108
109   void splice_after(iterator after_this, basic_multiallocation_chain &x)
110   {  slist_impl_.splice_after(after_this, x.slist_impl_);   }
111
112   void incorporate_after(iterator after_this, void_pointer begin , iterator before_end)
113   {  slist_impl_.incorporate_after(after_this, &to_node(begin), &to_node(before_end));   }
114
115   void incorporate_after(iterator after_this, void_pointer begin, void_pointer before_end, std::size_t n)
116   {  slist_impl_.incorporate_after(after_this, &to_node(begin), &to_node(before_end), n);   }
117
118   void swap(basic_multiallocation_chain &x)
119   {  slist_impl_.swap(x.slist_impl_);   }
120
121   static iterator iterator_to(void_pointer p)
122   {  return slist_impl_t::s_iterator_to(to_node(p));   }
123
124   std::pair<void_pointer, void_pointer> extract_data()
125   {
126      std::pair<void_pointer, void_pointer> ret
127         (slist_impl_.begin().operator->()
128         ,slist_impl_.last().operator->());
129      slist_impl_.clear();
130      return ret;
131   }
132};
133
134template<class T>
135struct cast_functor
136{
137   typedef typename containers_detail::add_reference<T>::type result_type;
138   template<class U>
139   result_type operator()(U &ptr) const
140   {  return *static_cast<T*>(static_cast<void*>(&ptr));  }
141};
142
143template<class MultiallocationChain, class T>
144class transform_multiallocation_chain
145{
146   private:
147   BOOST_MOVE_MACRO_MOVABLE_BUT_NOT_COPYABLE(transform_multiallocation_chain)
148
149   MultiallocationChain   holder_;
150   typedef typename MultiallocationChain::void_pointer   void_pointer;
151   typedef typename boost::pointer_to_other
152      <void_pointer, T>::type                            pointer;
153
154   static pointer cast(void_pointer p)
155   {
156      return pointer(static_cast<T*>(containers_detail::get_pointer(p)));
157   }
158
159   public:
160   typedef transform_iterator
161      < typename MultiallocationChain::iterator
162      , containers_detail::cast_functor <T> >                 iterator;
163
164   transform_multiallocation_chain()
165      : holder_()
166   {}
167
168   transform_multiallocation_chain(BOOST_MOVE_MACRO_RV_REF(transform_multiallocation_chain) other)
169      : holder_()
170   {  this->swap(other); }
171
172   transform_multiallocation_chain(BOOST_MOVE_MACRO_RV_REF(MultiallocationChain) other)
173      : holder_(BOOST_CONTAINER_MOVE_NAMESPACE::move(other))
174   {}
175
176   transform_multiallocation_chain& operator=(BOOST_MOVE_MACRO_RV_REF(transform_multiallocation_chain) other)
177   {
178      transform_multiallocation_chain tmp(BOOST_CONTAINER_MOVE_NAMESPACE::move(other));
179      this->swap(tmp);
180      return *this;
181   }
182
183   void push_front(pointer mem)
184   {  holder_.push_front(mem);  }
185
186   void swap(transform_multiallocation_chain &other_chain)
187   {  holder_.swap(other_chain.holder_); }
188
189   void splice_after(iterator after_this, transform_multiallocation_chain &x, iterator before_begin, iterator before_end, std::size_t n)
190   {  holder_.splice_after(after_this.base(), x.holder_, before_begin.base(), before_end.base(), n);  }
191
192   void incorporate_after(iterator after_this, void_pointer begin, void_pointer before_end, std::size_t n)
193   {  holder_.incorporate_after(after_this.base(), begin, before_end, n);  }
194
195   void pop_front()
196   {  holder_.pop_front();  }
197
198   pointer front()
199   {  return cast(holder_.front());   }
200
201   bool empty() const
202   {  return holder_.empty(); }
203
204   iterator before_begin()
205   {  return iterator(holder_.before_begin());   }
206
207   iterator begin()
208   {  return iterator(holder_.begin());   }
209
210   iterator end()
211   {  return iterator(holder_.end());   }
212
213   iterator last()
214   {  return iterator(holder_.last());   }
215
216   std::size_t size() const
217   {  return holder_.size();  }
218
219   void clear()
220   {  holder_.clear(); }
221
222   iterator insert_after(iterator it, pointer m)
223   {  return iterator(holder_.insert_after(it.base(), m)); }
224
225   static iterator iterator_to(pointer p)
226   {  return iterator(MultiallocationChain::iterator_to(p));  }
227
228   std::pair<void_pointer, void_pointer> extract_data()
229   {  return holder_.extract_data();  }
230
231   MultiallocationChain extract_multiallocation_chain()
232   {
233      return MultiallocationChain(BOOST_CONTAINER_MOVE_NAMESPACE::move(holder_));
234   }
235};
236
237}}}
238
239// namespace containers_detail {
240// namespace container {
241// namespace boost {
242
243#include INCLUDE_BOOST_CONTAINER_DETAIL_CONFIG_END_HPP
244
245#endif   //BOOST_CONTAINERS_DETAIL_MULTIALLOCATION_CHAIN_HPP