array_allocator.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014 Glen Joseph Fernandes
3  * glenfe at live dot com
4  *
5  * Distributed under the Boost Software License,
6  * Version 1.0. (See accompanying file LICENSE_1_0.txt
7  * or copy at http://boost.org/LICENSE_1_0.txt)
8  */
9 #ifndef BOOST_SMART_PTR_DETAIL_ARRAY_ALLOCATOR_HPP
10 #define BOOST_SMART_PTR_DETAIL_ARRAY_ALLOCATOR_HPP
11 
12 #include <boost/align/align.hpp>
16 
17 namespace boost {
18  namespace detail {
19  struct ms_init_tag { };
20  struct ms_noinit_tag { };
21 
22  template<class T>
24 
25  template<class T>
26  struct ms_allocator_state<T[]> {
27  typedef typename array_base<T>::type type;
28 
29  ms_allocator_state(std::size_t size_,
30  type** result_)
31  : size(size_ * array_total<T>::size),
32  result(result_) {
33  }
34 
35  std::size_t size;
36 
37  union {
40  };
41  };
42 
43  template<class T, std::size_t N>
44  struct ms_allocator_state<T[N]> {
45  typedef typename array_base<T>::type type;
46 
48  : result(result_) {
49  }
50 
51  enum {
53  };
54 
55  union {
58  };
59  };
60 
61  template<class A, class T, class R>
63  : public A {
64  template<class A_, class T_, class R_>
65  friend class as_allocator;
66 
67 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
68  typedef std::allocator_traits<A> AT;
69  typedef typename AT::template rebind_alloc<char> CA;
70  typedef typename AT::template rebind_traits<char> CT;
71 #else
72  typedef typename A::template rebind<char>::other CA;
73 #endif
74 
75  public:
76  typedef A allocator_type;
77 
78 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
79  typedef typename AT::value_type value_type;
80  typedef typename AT::pointer pointer;
81  typedef typename AT::const_pointer const_pointer;
82  typedef typename AT::void_pointer void_pointer;
83  typedef typename AT::const_void_pointer const_void_pointer;
84  typedef typename AT::size_type size_type;
85  typedef typename AT::difference_type difference_type;
86 #else
87  typedef typename A::value_type value_type;
88  typedef typename A::pointer pointer;
89  typedef typename A::const_pointer const_pointer;
90  typedef typename A::size_type size_type;
91  typedef typename A::difference_type difference_type;
92  typedef typename A::reference reference;
93  typedef typename A::const_reference const_reference;
94  typedef void* void_pointer;
95  typedef const void* const_void_pointer;
96 #endif
97 
98  template<class U>
99  struct rebind {
100 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
101  typedef as_allocator<typename AT::
102  template rebind_alloc<U>, T, R> other;
103 #else
104  typedef as_allocator<typename A::
105  template rebind<U>::other, T, R> other;
106 #endif
107  };
108 
109  typedef typename array_base<T>::type type;
110 
111  as_allocator(const A& allocator_, type** result)
112  : A(allocator_),
113  data(result) {
114  }
115 
116  as_allocator(const A& allocator_, std::size_t size,
117  type** result)
118  : A(allocator_),
119  data(size, result) {
120  }
121 
122  template<class U>
124  : A(other.allocator()),
125  data(other.data) {
126  }
127 
129  enum {
131  };
132  std::size_t n1 = count * sizeof(value_type);
133  std::size_t n2 = data.size * sizeof(type);
134  std::size_t n3 = n2 + M;
135  CA ca(allocator());
136  void* p1 = ca.allocate(n1 + n3);
137  void* p2 = static_cast<char*>(p1) + n1;
138  (void)boost::alignment::align(M, n2, p2, n3);
139  *data.result = static_cast<type*>(p2);
140  return static_cast<value_type*>(p1);
141  }
142 
143  void deallocate(pointer memory, size_type count) {
144  enum {
146  };
147  std::size_t n1 = count * sizeof(value_type);
148  std::size_t n2 = data.size * sizeof(type) + M;
149  char* p1 = reinterpret_cast<char*>(memory);
150  CA ca(allocator());
151  ca.deallocate(p1, n1 + n2);
152  }
153 
154  const A& allocator() const {
155  return static_cast<const A&>(*this);
156  }
157 
158  A& allocator() {
159  return static_cast<A&>(*this);
160  }
161 
162  void set(type* memory) {
163  data.object = memory;
164  }
165 
166  void operator()() {
167  if (data.object) {
168  R tag;
169  release(tag);
170  }
171  }
172 
173  private:
175 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
176  as_destroy(allocator(), data.object, data.size);
177 #else
178  ms_destroy(data.object, data.size);
179 #endif
180  }
181 
183  ms_destroy(data.object, data.size);
184  }
185 
187  };
188 
189  template<class A1, class A2, class T, class R>
191  const as_allocator<A2, T, R>& a2) {
192  return a1.allocator() == a2.allocator();
193  }
194 
195  template<class A1, class A2, class T, class R>
197  const as_allocator<A2, T, R>& a2) {
198  return a1.allocator() != a2.allocator();
199  }
200 
201  template<class T, class Y = char>
203 
204  template<class T, class Y>
205  class ms_allocator {
206  template<class T_, class Y_>
207  friend class ms_allocator;
208 
209  public:
210  typedef typename array_base<T>::type type;
211 
212  typedef Y value_type;
213  typedef Y* pointer;
214  typedef const Y* const_pointer;
215  typedef std::size_t size_type;
216  typedef std::ptrdiff_t difference_type;
217  typedef Y& reference;
218  typedef const Y& const_reference;
219 
220  template<class U>
221  struct rebind {
223  };
224 
225  ms_allocator(type** result)
226  : data(result) {
227  }
228 
229  ms_allocator(std::size_t size, type** result)
230  : data(size, result) {
231  }
232 
233  template<class U>
235  : data(other.data) {
236  }
237 
238  pointer allocate(size_type count, const void* = 0) {
239  enum {
241  };
242  std::size_t n1 = count * sizeof(Y);
243  std::size_t n2 = data.size * sizeof(type);
244  std::size_t n3 = n2 + M;
245  void* p1 = ::operator new(n1 + n3);
246  void* p2 = static_cast<char*>(p1) + n1;
247  (void)boost::alignment::align(M, n2, p2, n3);
248  *data.result = static_cast<type*>(p2);
249  return static_cast<Y*>(p1);
250  }
251 
252  void deallocate(pointer memory, size_type) {
253  void* p1 = memory;
254  ::operator delete(p1);
255  }
256 
257 #if defined(BOOST_NO_CXX11_ALLOCATOR)
258  pointer address(reference value) const {
259  return &value;
260  }
261 
262  const_pointer address(const_reference value) const {
263  return &value;
264  }
265 
266  size_type max_size() const {
267  enum {
268  N = static_cast<std::size_t>(-1) / sizeof(Y)
269  };
270  return N;
271  }
272 
273  void construct(pointer memory, const_reference value) {
274  void* p1 = memory;
275  ::new(p1) Y(value);
276  }
277 
278  void destroy(pointer memory) {
279  (void)memory;
280  memory->~Y();
281  }
282 #endif
283 
284  void set(type* memory) {
285  data.object = memory;
286  }
287 
288  void operator()() {
289  if (data.object) {
290  ms_destroy(data.object, data.size);
291  }
292  }
293 
294  private:
296  };
297 
298  template<class T, class Y1, class Y2>
300  const ms_allocator<T, Y2>&) {
301  return true;
302  }
303 
304  template<class T, class Y1, class Y2>
306  const ms_allocator<T, Y2>&) {
307  return false;
308  }
309 
311  public:
312  void operator()(const void*) {
313  }
314  };
315  }
316 }
317 
318 #endif
boost::detail::as_allocator::void_pointer
AT::void_pointer void_pointer
Definition: array_allocator.hpp:82
boost::detail::as_allocator::AT
std::allocator_traits< A > AT
Definition: array_allocator.hpp:68
boost::detail::as_allocator::as_allocator
as_allocator(const as_allocator< U, T, R > &other)
Definition: array_allocator.hpp:123
boost::detail::as_allocator::as_allocator
as_allocator(const A &allocator_, std::size_t size, type **result)
Definition: array_allocator.hpp:116
boost::detail::as_allocator::set
void set(type *memory)
Definition: array_allocator.hpp:162
R
#define R(x, n)
Definition: SHA256.cpp:50
boost::detail::operator==
bool operator==(const as_allocator< A1, T, R > &a1, const as_allocator< A2, T, R > &a2)
Definition: array_allocator.hpp:190
boost::detail::ms_in_allocator_tag::operator()
void operator()(const void *)
Definition: array_allocator.hpp:312
T
T
Definition: mem_fn_cc.hpp:25
boost::detail::as_allocator
Definition: array_allocator.hpp:62
boost::detail::ms_allocator::ms_allocator
ms_allocator(type **result)
Definition: array_allocator.hpp:225
boost::detail::as_allocator::allocator
A & allocator()
Definition: array_allocator.hpp:158
boost::detail::ms_allocator::set
void set(type *memory)
Definition: array_allocator.hpp:284
boost::detail::ms_allocator::operator()
void operator()()
Definition: array_allocator.hpp:288
boost::detail::ms_allocator_state< T[N]>::result
type ** result
Definition: array_allocator.hpp:56
boost::detail::ms_noinit_tag
Definition: array_allocator.hpp:20
boost::detail::operator!=
bool operator!=(const as_allocator< A1, T, R > &a1, const as_allocator< A2, T, R > &a2)
Definition: array_allocator.hpp:196
boost::detail::as_allocator::rebind::other
as_allocator< typename AT::template rebind_alloc< U >, T, R > other
Definition: array_allocator.hpp:102
alignment_of.hpp
boost::detail::ms_allocator::rebind
Definition: array_allocator.hpp:221
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::detail::as_allocator::type
array_base< T >::type type
Definition: array_allocator.hpp:109
boost::detail::ms_allocator::data
ms_allocator_state< T > data
Definition: array_allocator.hpp:295
boost::detail::as_allocator::allocator
const A & allocator() const
Definition: array_allocator.hpp:154
boost::alignment::align
void * align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space)
Definition: detail/align.hpp:18
boost::detail::ms_allocator_state< T[]>::size
std::size_t size
Definition: array_allocator.hpp:35
boost::detail::ms_allocator_state< T[]>::object
type * object
Definition: array_allocator.hpp:39
boost::detail::ms_allocator_state< T[]>::result
type ** result
Definition: array_allocator.hpp:38
boost::detail::ms_allocator_state< T[N]>::type
array_base< T >::type type
Definition: array_allocator.hpp:45
boost::detail::as_allocator::const_pointer
AT::const_pointer const_pointer
Definition: array_allocator.hpp:81
boost::detail::ms_allocator_state
Definition: array_allocator.hpp:23
boost::detail::as_allocator::value_type
AT::value_type value_type
Definition: array_allocator.hpp:79
boost::detail::ms_allocator::ms_allocator
ms_allocator(const ms_allocator< T, U > &other)
Definition: array_allocator.hpp:234
boost::detail::ms_allocator::pointer
Y * pointer
Definition: array_allocator.hpp:213
boost::detail::as_allocator::rebind
Definition: array_allocator.hpp:99
boost::detail::as_allocator::release
void release(ms_noinit_tag)
Definition: array_allocator.hpp:182
boost::detail::ms_allocator::const_pointer
const typedef Y * const_pointer
Definition: array_allocator.hpp:214
boost::detail::ms_allocator_state< T[N]>::ms_allocator_state
ms_allocator_state(type **result_)
Definition: array_allocator.hpp:47
boost::detail::ms_allocator_state< T[]>::ms_allocator_state
ms_allocator_state(std::size_t size_, type **result_)
Definition: array_allocator.hpp:29
boost::foreach::tag
boost_foreach_argument_dependent_lookup_hack tag
Definition: foreach_fwd.hpp:31
boost::detail::ms_init_tag
Definition: array_allocator.hpp:19
boost::detail::as_allocator::allocator_type
A allocator_type
Definition: array_allocator.hpp:76
boost::detail::ms_destroy
void ms_destroy(T *, std::size_t, ms_is_trivial)
Definition: array_utility.hpp:25
boost::detail::ms_allocator_state< T[N]>::object
type * object
Definition: array_allocator.hpp:57
boost::detail::array_base::type
boost::remove_cv< T >::type type
Definition: array_traits.hpp:18
boost::detail::as_allocator::CA
AT::template rebind_alloc< char > CA
Definition: array_allocator.hpp:69
boost::detail::as_allocator::difference_type
AT::difference_type difference_type
Definition: array_allocator.hpp:85
boost::detail::as_allocator::data
ms_allocator_state< T > data
Definition: array_allocator.hpp:186
boost::detail::as_allocator::CT
AT::template rebind_traits< char > CT
Definition: array_allocator.hpp:70
boost::alignment_of
Definition: alignment_of.hpp:28
boost::detail::allocator::construct
void construct(void *p, const Type &t)
Definition: allocator_utilities.hpp:151
boost::detail::as_allocator::release
void release(ms_init_tag)
Definition: array_allocator.hpp:174
boost::detail::ms_allocator::difference_type
std::ptrdiff_t difference_type
Definition: array_allocator.hpp:216
array_traits.hpp
boost::detail::array_total
Definition: array_traits.hpp:32
boost::detail::as_allocator::deallocate
void deallocate(pointer memory, size_type count)
Definition: array_allocator.hpp:143
boost::detail::ms_allocator::size_type
std::size_t size_type
Definition: array_allocator.hpp:215
boost::detail::as_destroy
void as_destroy(const A &allocator, T *memory, std::size_t size)
Definition: array_utility.hpp:99
boost::detail::as_allocator::const_void_pointer
AT::const_void_pointer const_void_pointer
Definition: array_allocator.hpp:83
boost::detail::ms_allocator::value_type
Y value_type
Definition: array_allocator.hpp:212
boost::detail::ms_allocator::allocate
pointer allocate(size_type count, const void *=0)
Definition: array_allocator.hpp:238
boost::detail::as_allocator::pointer
AT::pointer pointer
Definition: array_allocator.hpp:80
boost::detail::ms_allocator::deallocate
void deallocate(pointer memory, size_type)
Definition: array_allocator.hpp:252
boost::detail::ms_in_allocator_tag
Definition: array_allocator.hpp:310
boost::detail::as_allocator::operator()
void operator()()
Definition: array_allocator.hpp:166
boost::detail::as_allocator::as_allocator
as_allocator(const A &allocator_, type **result)
Definition: array_allocator.hpp:111
boost::detail::as_allocator::size_type
AT::size_type size_type
Definition: array_allocator.hpp:84
array_utility.hpp
boost::detail::ms_allocator::reference
Y & reference
Definition: array_allocator.hpp:217
boost::detail::ms_allocator::type
array_base< T >::type type
Definition: array_allocator.hpp:210
boost::detail::as_allocator::allocate
pointer allocate(size_type count, const_void_pointer=0)
Definition: array_allocator.hpp:128
boost::detail::ms_allocator::ms_allocator
ms_allocator(std::size_t size, type **result)
Definition: array_allocator.hpp:229
boost::detail::ms_allocator
Definition: array_allocator.hpp:202
align.hpp
boost::detail::allocator::destroy
void destroy(const Type *p)
Definition: allocator_utilities.hpp:166
boost::detail::ms_allocator::rebind::other
ms_allocator< T, U > other
Definition: array_allocator.hpp:222
boost::detail::ms_allocator_state< T[]>::type
array_base< T >::type type
Definition: array_allocator.hpp:27
boost::detail::ms_allocator::const_reference
const typedef Y & const_reference
Definition: array_allocator.hpp:218


sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 03:36:32