Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_allocator.h
Go to the documentation of this file.
1// -*- C++ -*-
2
46#ifndef _RWSTD_RW_ALLOCATOR_H_INCLUDED
47#define _RWSTD_RW_ALLOCATOR_H_INCLUDED
48
49#ifndef _RWSTD_SPECIALIZED_H_INCLUDED
50# include <rw/_specialized.h>
51#endif // _RWSTD_SPECIALIZED_H_INCLUDED
52
53
55
56// [de]allocate storage (in bytes)
57_RWSTD_EXPORT void* __rw_allocate (_RWSTD_SIZE_T, int = 0);
58_RWSTD_EXPORT void __rw_deallocate (void*, _RWSTD_SIZE_T, int = 0);
59
60} // namespace __rw
61
62
64
65
66#ifndef _RWSTD_NO_EXT_CXX_0X
67
68struct allocator_arg_t { };
69
70const allocator_arg_t allocator_arg = allocator_arg_t ();
71
72#endif
73
74
75template <class _TypeT> class
76allocator;
77
78
80class allocator<void>
81{
82public:
83 typedef void value_type;
84 typedef value_type* pointer;
85 typedef const value_type* const_pointer;
86
87
88#ifdef _RWSTD_ALLOCATOR
89
90 template <class _TypeU>
91 struct rebind {
92 typedef allocator<_TypeU> other;
93 };
94
95#endif // _RWSTD_ALLOCATOR
96
97};
98
99
100template <class _TypeT>
101class allocator
102{
103public:
104 typedef _RWSTD_SIZE_T size_type;
105 typedef _RWSTD_PTRDIFF_T difference_type;
106 typedef _TypeT value_type;
107 typedef value_type* pointer;
108 typedef const value_type* const_pointer;
109 typedef value_type& reference;
110 typedef const value_type& const_reference;
111
112 allocator () _THROWS (()) { }
113
114 allocator (const allocator &__rhs) _THROWS (()) {
115 // working around an HP aCC warning 431
116 _RWSTD_UNUSED (__rhs);
117 }
118
119#ifdef _RWSTD_ALLOCATOR
120
121 template <class _TypeU>
122 struct rebind {
123 typedef allocator<_TypeU> other;
124 };
125
126 template <class _TypeU>
127 allocator (const allocator<_TypeU>&) _THROWS (()) { }
128
129 template <class _TypeU>
130 allocator&
131 operator= (const allocator<_TypeU>&) _THROWS (()) {
132 return *this;
133 }
134
135#endif // _RWSTD_ALLOCATOR
136
137
138 pointer address (reference __x) const {
139 // lwg issue 350
140 return _RWSTD_REINTERPRET_CAST (pointer,
141 &_RWSTD_REINTERPRET_CAST (char&, __x));
142 }
143
144 const_pointer address (const_reference __x) const {
145 // lwg issue 350
146 return _RWSTD_REINTERPRET_CAST (const_pointer,
147 &_RWSTD_REINTERPRET_CAST (const char&, __x));
148 }
149
150 pointer allocate (size_type __n, allocator<void>::const_pointer = 0) {
151
152#ifdef _RWSTD_ALLOCATOR
153 return _RWSTD_STATIC_CAST (pointer,
154 _RW::__rw_allocate (__n * sizeof (value_type)));
155#else
156 return _RWSTD_STATIC_CAST (pointer, _RW::__rw_allocate (__n));
157#endif // _RWSTD_ALLOCATOR
158 }
159
160#ifdef _RWSTD_ALLOCATOR
161 void deallocate (pointer __p, size_type __n)
162#else
163 void deallocate (void* __p, size_type __n)
164#endif // _RWSTD_ALLOCATOR
165 {
166 _RW::__rw_deallocate (__p, __n);
167 }
168
169 // 20.4.1.1, p11 - the largest N for which allocate (N) might succeed
170 size_type max_size () const _THROWS (()) {
171 return size_type (_RWSTD_SIZE_MAX) / sizeof (value_type)
172 ? size_type (size_type (_RWSTD_SIZE_MAX) / sizeof (value_type))
173 : size_type (1);
174 }
175
176 void construct (pointer __p, const_reference __val) {
177 _RW::__rw_construct (__p, __val);
178 }
179
180 void destroy (pointer __p) {
181 _RWSTD_ASSERT (0 != __p);
182 __p->~_TypeT ();
183 }
184};
185
186
187#if !defined (_RWSTD_NO_CLASS_PARTIAL_SPEC) \
188 && !defined (_RWSTD_NO_EXT_CONST_ALLOCATOR)
189
190// extension: allocates/constructs/destroys const elements
191
192template <class _TypeT>
193class allocator<const _TypeT>
194{
195public:
196 typedef _RWSTD_SIZE_T size_type;
197 typedef _RWSTD_PTRDIFF_T difference_type;
198 typedef const _TypeT value_type;
199 typedef const value_type* pointer;
200 typedef const value_type* const_pointer;
201 typedef const value_type& reference;
202 typedef const value_type& const_reference;
203
204 allocator () _THROWS (()) { }
205
206 allocator (const allocator &__rhs) _THROWS (()) {
207 // working around an HP aCC warning 431
208 _RWSTD_UNUSED (__rhs);
209 }
210
211#ifdef _RWSTD_ALLOCATOR
212
213 template <class _TypeU>
214 struct rebind {
215 typedef allocator<_TypeU> other;
216 };
217
218 template <class _TypeU>
219 allocator (const allocator<_TypeU>&) _THROWS (()) { }
220
221 template <class _TypeU>
222 allocator& operator= (const allocator<_TypeU>&) _THROWS (()) {
223 return *this;
224 }
225
226#endif // _RWSTD_ALLOCATOR
227
228 const_pointer address (const_reference __x) const {
229 // lwg issue 350
230 return _RWSTD_REINTERPRET_CAST (const_pointer,
231 &_RWSTD_REINTERPRET_CAST (const char&, __x));
232 }
233
234 // avoid the use of allocator<void>::const_pointer below
235 // to work around a SunPro 5.3 (and prior) bug
236 const_pointer allocate (size_type __n, const void* = 0) {
237
238#ifdef _RWSTD_ALLOCATOR
239 return _RWSTD_STATIC_CAST (const_pointer,
240 _RWSTD_CONST_CAST (const void*,
241 _RW::__rw_allocate (__n * sizeof (value_type))));
242#else
243 return _RWSTD_STATIC_CAST (const_pointer,
244 _RWSTD_CONST_CAST (const void*,
245 _RW::__rw_allocate (__n)));
246#endif // _RWSTD_ALLOCATOR
247
248 }
249
250#ifdef _RWSTD_ALLOCATOR
251 void deallocate (const_pointer __p, size_type __nelems) {
252 _RW::__rw_deallocate (_RWSTD_CONST_CAST (_TypeT*, __p), __nelems);
253 }
254#else
255 void deallocate (const void* __p, size_type __nbytes) {
256 _RW::__rw_deallocate (_RWSTD_CONST_CAST (void*, __p), __nbytes);
257 }
258#endif // _RWSTD_ALLOCATOR
259
260 // 20.4.1.1, p11 - the largest N for which allocate (N) might succeed
261 size_type max_size () const _THROWS (()) {
262 return size_type (_RWSTD_SIZE_MAX) / sizeof (value_type)
263 ? size_type (size_type (_RWSTD_SIZE_MAX) / sizeof (value_type))
264 : size_type (1);
265 }
266
267 void construct (const_pointer __p, const_reference __val) {
268 _RW::__rw_construct (_RWSTD_CONST_CAST (_TypeT*, __p), __val);
269 }
270
271 void destroy (const_pointer __p) {
272 _RWSTD_ASSERT (0 != __p);
273 __p->~_TypeT ();
274 }
275};
276
277#endif // !_RWSTD_NO_CLASS_PARTIAL_SPEC && !_RWSTD_NO_EXT_CONST_ALLOCATOR)
278
279
280// allocator_interface provides all types and typed functions. Memory
281// allocated as raw bytes using the class provided by the Allocator
282// template parameter. allocator_interface casts appropriately.
283//
284// Multiple allocator_interface objects can attach to a single
285// allocator, thus allowing one allocator to allocate all storage
286// for a container, regardless of how many types are involved.
287//
288// The only real restriction is that pointer and reference are
289// hard coded as _TypeT* and _TypeT&. Partial specialization would
290// get around this.
291//
292#ifndef _RWSTD_ALLOCATOR
293
294template <class _Allocator, class _TypeT>
295class allocator_interface
296{
297public:
298 typedef _Allocator allocator_type;
299 typedef _TypeT value_type;
300 typedef value_type* pointer;
301 typedef const value_type* const_pointer;
302 typedef value_type& reference;
303 typedef const value_type& const_reference;
304 typedef typename allocator_type::size_type size_type;
305 typedef typename allocator_type::difference_type difference_type;
306
307protected:
308 allocator_type _C_alloc;
309
310public:
311 allocator_interface() _THROWS (()) { }
312
313 allocator_interface (const allocator_type &__alloc) _THROWS (())
314 : _C_alloc (__alloc) { }
315
316 operator allocator_type& () {
317 return _C_alloc;
318 }
319
320 pointer address (reference __x) const {
321 // lwg issue 350
322 return _RWSTD_REINTERPRET_CAST (pointer,
323 &_RWSTD_REINTERPRET_CAST (char&, __x));
324 }
325
326 const_pointer address (const_reference __x) const {
327 // lwg issue 350
328 return _RWSTD_REINTERPRET_CAST (const_pointer,
329 &_RWSTD_REINTERPRET_CAST (const char&, __x));
330 }
331
332 size_type max_size () const {
333 return _C_alloc.max_size () / sizeof (value_type);
334 }
335
336 pointer allocate (size_type __n, const void* __p = 0) {
337 return (pointer)_C_alloc.allocate (__n * sizeof (value_type), __p);
338 }
339
340 void deallocate (pointer __p, size_type __n) {
341 _C_alloc.deallocate (__p, __n);
342 }
343
344 void construct (pointer __p, const_reference __val) {
345 _RW::__rw_construct(__p, __val);
346 }
347
348 void destroy (pointer __p) const {
349 _RWSTD_ASSERT (0 != __p);
350 __p->~_TypeT ();
351 }
352};
353
354
356class allocator_interface<allocator<void>, void>
357{
358public:
359 typedef allocator<void> allocator_type;
360 typedef void* pointer;
361 typedef const void* const_pointer;
362 typedef void value_type;
363
364protected:
365 allocator_type _C_alloc;
366
367public:
368 allocator_interface () _THROWS (()) { }
369
370 allocator_interface (const allocator<void>& __rhs) _THROWS (())
371 : _C_alloc (__rhs) { }
372
373};
374
375
376template <class _TypeT, class _TypeU, class _TypeV, class _TypeW>
377inline bool
378operator== (const allocator_interface<_TypeT, _TypeU>&,
379 const allocator_interface<_TypeV, _TypeW>&) _THROWS (())
380{
381 return true;
382}
383
384#endif // _RWSTD_ALLOCATOR
385
386
387template <class _TypeT, class _TypeU>
388inline bool
389operator== (const allocator<_TypeT>&, const allocator<_TypeU>&) _THROWS (())
390{
391 return true;
392}
393
394
395#ifndef _RWSTD_NO_NAMESPACE
396
397template <class _TypeT, class _TypeU>
398inline bool
399operator!= (const allocator<_TypeT>& __x,
400 const allocator<_TypeU>& __y) _THROWS (())
401{
402 return !(__x == __y);
403}
404
405#endif // _RWSTD_NO_NAMESPACE
406
407
408} // namespace std
409
410
411#endif // _RWSTD_RW_ALLOCATOR_H_INCLUDED
#define _RWSTD_SPECIALIZED_CLASS
#define _THROWS()
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_UNUSED(arg)
Definition _defs.h:972
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
#define _RWSTD_CONST_CAST(T, x)
Definition _defs.h:536
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
Definition json.h:5363