~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/boost/container/detail/multiallocation_chain.hpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// (C) Copyright Ion Gaztanaga 2005-2012. 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_CONTAINER_DETAIL_MULTIALLOCATION_CHAIN_HPP
12
 
#define BOOST_CONTAINER_DETAIL_MULTIALLOCATION_CHAIN_HPP
13
 
 
14
 
#include "config_begin.hpp"
15
 
#include <boost/container/container_fwd.hpp>
16
 
#include <boost/container/detail/utilities.hpp>
17
 
#include <boost/container/detail/type_traits.hpp>
18
 
#include <boost/container/detail/transform_iterator.hpp>
19
 
#include <boost/intrusive/slist.hpp>
20
 
#include <boost/intrusive/pointer_traits.hpp>
21
 
#include <boost/type_traits/make_unsigned.hpp>
22
 
#include <boost/move/utility.hpp>
23
 
 
24
 
namespace boost {
25
 
namespace container {
26
 
namespace container_detail {
27
 
 
28
 
template<class VoidPointer>
29
 
class basic_multiallocation_chain
30
 
{
31
 
   private:
32
 
   typedef bi::slist_base_hook<bi::void_pointer<VoidPointer>
33
 
                        ,bi::link_mode<bi::normal_link>
34
 
                        > node;
35
 
 
36
 
   typedef typename boost::intrusive::pointer_traits
37
 
      <VoidPointer>::template rebind_pointer<char>::type    char_ptr;
38
 
   typedef typename boost::intrusive::
39
 
      pointer_traits<char_ptr>::difference_type             difference_type;
40
 
 
41
 
   typedef bi::slist< node
42
 
                    , bi::linear<true>
43
 
                    , bi::cache_last<true>
44
 
                    , bi::size_type<typename boost::make_unsigned<difference_type>::type>
45
 
                    > slist_impl_t;
46
 
   slist_impl_t slist_impl_;
47
 
 
48
 
   typedef typename boost::intrusive::pointer_traits
49
 
      <VoidPointer>::template rebind_pointer<node>::type    node_ptr;
50
 
   typedef typename boost::intrusive::
51
 
      pointer_traits<node_ptr>                              node_ptr_traits;
52
 
 
53
 
   static node & to_node(const VoidPointer &p)
54
 
   {  return *static_cast<node*>(static_cast<void*>(container_detail::to_raw_pointer(p)));  }
55
 
 
56
 
   static VoidPointer from_node(node &n)
57
 
   {  return node_ptr_traits::pointer_to(n);  }
58
 
 
59
 
   static node_ptr to_node_ptr(const VoidPointer &p)
60
 
   {  return node_ptr_traits::static_cast_from(p);   }
61
 
 
62
 
   BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_multiallocation_chain)
63
 
 
64
 
   public:
65
 
 
66
 
   typedef VoidPointer                       void_pointer;
67
 
   typedef typename slist_impl_t::iterator   iterator;
68
 
   typedef typename slist_impl_t::size_type  size_type;
69
 
 
70
 
   basic_multiallocation_chain()
71
 
      :  slist_impl_()
72
 
   {}
73
 
 
74
 
   basic_multiallocation_chain(const void_pointer &b, const void_pointer &before_e, size_type n)
75
 
      :  slist_impl_(to_node_ptr(b), to_node_ptr(before_e), n)
76
 
   {}
77
 
 
78
 
   basic_multiallocation_chain(BOOST_RV_REF(basic_multiallocation_chain) other)
79
 
      :  slist_impl_(::boost::move(other.slist_impl_))
80
 
   {}
81
 
 
82
 
   basic_multiallocation_chain& operator=(BOOST_RV_REF(basic_multiallocation_chain) other)
83
 
   {
84
 
      slist_impl_ = ::boost::move(other.slist_impl_);
85
 
      return *this;
86
 
   }
87
 
 
88
 
   bool empty() const
89
 
   {  return slist_impl_.empty(); }
90
 
 
91
 
   size_type size() const
92
 
   {  return slist_impl_.size();  }
93
 
 
94
 
   iterator before_begin()
95
 
   {  return slist_impl_.before_begin(); }
96
 
 
97
 
   iterator begin()
98
 
   {  return slist_impl_.begin(); }
99
 
 
100
 
   iterator end()
101
 
   {  return slist_impl_.end(); }
102
 
 
103
 
   iterator last()
104
 
   {  return slist_impl_.last(); }
105
 
 
106
 
   void clear()
107
 
   {  slist_impl_.clear(); }
108
 
 
109
 
   iterator insert_after(iterator it, void_pointer m)
110
 
   {  return slist_impl_.insert_after(it, to_node(m));   }
111
 
 
112
 
   void push_front(const void_pointer &m)
113
 
   {  return slist_impl_.push_front(to_node(m));  }
114
 
 
115
 
   void push_back(const void_pointer &m)
116
 
   {  return slist_impl_.push_back(to_node(m));   }
117
 
 
118
 
   void_pointer pop_front()
119
 
   {
120
 
      node & n = slist_impl_.front();
121
 
      void_pointer ret = from_node(n);
122
 
      slist_impl_.pop_front();
123
 
      return ret;
124
 
   }
125
 
 
126
 
   void splice_after(iterator after_this, basic_multiallocation_chain &x, iterator before_b, iterator before_e, size_type n)
127
 
   {  slist_impl_.splice_after(after_this, x.slist_impl_, before_b, before_e, n);   }
128
 
 
129
 
   void splice_after(iterator after_this, basic_multiallocation_chain &x)
130
 
   {  slist_impl_.splice_after(after_this, x.slist_impl_);   }
131
 
 
132
 
   void erase_after(iterator before_b, iterator e, size_type n)
133
 
   {  slist_impl_.erase_after(before_b, e, n);   }
134
 
 
135
 
   void_pointer incorporate_after(iterator after_this, const void_pointer &b, size_type unit_bytes, size_type num_units)
136
 
   {
137
 
      typedef typename boost::intrusive::pointer_traits<char_ptr> char_pointer_traits;
138
 
      char_ptr elem = char_pointer_traits::static_cast_from(b);
139
 
      if(num_units){
140
 
         char_ptr prev_elem = elem;
141
 
         elem += unit_bytes;
142
 
         for(size_type i = 0; i != num_units-1; ++i, elem += unit_bytes){
143
 
            ::new (container_detail::to_raw_pointer(prev_elem)) void_pointer(elem);
144
 
            prev_elem = elem;
145
 
         }
146
 
         slist_impl_.incorporate_after(after_this, to_node_ptr(b), to_node_ptr(prev_elem), num_units);
147
 
      }
148
 
      return elem;
149
 
   }
150
 
 
151
 
   void incorporate_after(iterator after_this, void_pointer b, void_pointer before_e, size_type n)
152
 
   {  slist_impl_.incorporate_after(after_this, to_node_ptr(b), to_node_ptr(before_e), n);   }
153
 
 
154
 
   void swap(basic_multiallocation_chain &x)
155
 
   {  slist_impl_.swap(x.slist_impl_);   }
156
 
 
157
 
   static iterator iterator_to(const void_pointer &p)
158
 
   {  return slist_impl_t::s_iterator_to(to_node(p));   }
159
 
 
160
 
   std::pair<void_pointer, void_pointer> extract_data()
161
 
   {
162
 
      std::pair<void_pointer, void_pointer> ret
163
 
         (slist_impl_.begin().operator->()
164
 
         ,slist_impl_.last().operator->());
165
 
      slist_impl_.clear();
166
 
      return ret;
167
 
   }
168
 
};
169
 
 
170
 
template<class T>
171
 
struct cast_functor
172
 
{
173
 
   typedef typename container_detail::add_reference<T>::type result_type;
174
 
   template<class U>
175
 
   result_type operator()(U &ptr) const
176
 
   {  return *static_cast<T*>(static_cast<void*>(&ptr));  }
177
 
};
178
 
 
179
 
template<class MultiallocationChain, class T>
180
 
class transform_multiallocation_chain
181
 
   : public MultiallocationChain
182
 
{
183
 
   private:
184
 
   BOOST_MOVABLE_BUT_NOT_COPYABLE(transform_multiallocation_chain)
185
 
   //transform_multiallocation_chain(const transform_multiallocation_chain &);
186
 
   //transform_multiallocation_chain & operator=(const transform_multiallocation_chain &);
187
 
 
188
 
   typedef typename MultiallocationChain::void_pointer   void_pointer;
189
 
   typedef typename boost::intrusive::pointer_traits
190
 
      <void_pointer>                                     void_pointer_traits;
191
 
   typedef typename void_pointer_traits::template
192
 
      rebind_pointer<T>::type                            pointer;
193
 
   typedef typename boost::intrusive::pointer_traits
194
 
      <pointer>                                          pointer_traits;
195
 
 
196
 
   static pointer cast(const void_pointer &p)
197
 
   {  return pointer_traits::static_cast_from(p);  }
198
 
 
199
 
   public:
200
 
   typedef transform_iterator
201
 
      < typename MultiallocationChain::iterator
202
 
      , container_detail::cast_functor <T> >             iterator;
203
 
   typedef typename MultiallocationChain::size_type      size_type;
204
 
 
205
 
   transform_multiallocation_chain()
206
 
      : MultiallocationChain()
207
 
   {}
208
 
 
209
 
   transform_multiallocation_chain(BOOST_RV_REF(transform_multiallocation_chain) other)
210
 
      : MultiallocationChain(::boost::move(static_cast<MultiallocationChain&>(other)))
211
 
   {}
212
 
 
213
 
   transform_multiallocation_chain(BOOST_RV_REF(MultiallocationChain) other)
214
 
      : MultiallocationChain(::boost::move(static_cast<MultiallocationChain&>(other)))
215
 
   {}
216
 
 
217
 
   transform_multiallocation_chain& operator=(BOOST_RV_REF(transform_multiallocation_chain) other)
218
 
   {
219
 
      return static_cast<MultiallocationChain&>
220
 
         (this->MultiallocationChain::operator=(::boost::move(static_cast<MultiallocationChain&>(other))));
221
 
   }
222
 
/*
223
 
   void push_front(const pointer &mem)
224
 
   {  holder_.push_front(mem);  }
225
 
 
226
 
   void push_back(const pointer &mem)
227
 
   {  return holder_.push_back(mem);   }
228
 
 
229
 
   void swap(transform_multiallocation_chain &other_chain)
230
 
   {  holder_.swap(other_chain.holder_); }
231
 
 
232
 
   void splice_after(iterator after_this, transform_multiallocation_chain &x, iterator before_b, iterator before_e, size_type n)
233
 
   {  holder_.splice_after(after_this.base(), x.holder_, before_b.base(), before_e.base(), n);  }
234
 
 
235
 
   void incorporate_after(iterator after_this, pointer b, pointer before_e, size_type n)
236
 
   {  holder_.incorporate_after(after_this.base(), b, before_e, n);  }
237
 
*/
238
 
   pointer pop_front()
239
 
   {  return cast(this->MultiallocationChain::pop_front());  }
240
 
/*
241
 
   bool empty() const
242
 
   {  return holder_.empty(); }
243
 
 
244
 
   iterator before_begin()
245
 
   {  return iterator(holder_.before_begin());   }
246
 
*/
247
 
   iterator begin()
248
 
   {  return iterator(this->MultiallocationChain::begin());   }
249
 
/*
250
 
   iterator end()
251
 
   {  return iterator(holder_.end());   }
252
 
 
253
 
   iterator last()
254
 
   {  return iterator(holder_.last());   }
255
 
 
256
 
   size_type size() const
257
 
   {  return holder_.size();  }
258
 
 
259
 
   void clear()
260
 
   {  holder_.clear(); }
261
 
*/
262
 
   iterator insert_after(iterator it, pointer m)
263
 
   {  return iterator(this->MultiallocationChain::insert_after(it.base(), m)); }
264
 
 
265
 
   static iterator iterator_to(const pointer &p)
266
 
   {  return iterator(MultiallocationChain::iterator_to(p));  }
267
 
 
268
 
   std::pair<pointer, pointer> extract_data()
269
 
   {
270
 
      std::pair<void_pointer, void_pointer> data(this->MultiallocationChain::extract_data());
271
 
      return std::pair<pointer, pointer>(cast(data.first), cast(data.second));
272
 
   }
273
 
/*
274
 
   MultiallocationChain &extract_multiallocation_chain()
275
 
   {  return holder_;  }*/
276
 
};
277
 
 
278
 
}}}
279
 
 
280
 
// namespace container_detail {
281
 
// namespace container {
282
 
// namespace boost {
283
 
 
284
 
#include <boost/container/detail/config_end.hpp>
285
 
 
286
 
#endif   //BOOST_CONTAINER_DETAIL_MULTIALLOCATION_CHAIN_HPP