1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
template<class _Tp, class _Alloc>
class __simple_alloc {
typedef _Alloc __alloc_type;
public:
typedef typename _Alloc::value_type __alloc_value_type;
typedef _Tp value_type;
static size_t _STLP_CALL __chunk(size_t __n) {
return (sizeof(__alloc_value_type)==sizeof(value_type)) ? __n :
((__n*sizeof(value_type)+sizeof(__alloc_value_type)-1)/sizeof(__alloc_value_type));
}
static _Tp* _STLP_CALL allocate(size_t __n) { return 0 == __n ? 0 : (_Tp*) __alloc_type::allocate(__chunk(__n)); }
static void _STLP_CALL deallocate(_Tp * __p, size_t __n) {
__alloc_type::deallocate((__alloc_value_type*)__p, __chunk(__n)); }
};
// Allocator adaptor to turn an SGI-style allocator (e.g. alloc, malloc_alloc)
// into a standard-conforming allocator. Note that this adaptor does
// *not* assume that all objects of the underlying alloc class are
// identical, nor does it assume that all of the underlying alloc's
// member functions are static member functions. Note, also, that
// __allocator<_Tp, alloc> is essentially the same thing as allocator<_Tp>.
template <class _Tp, class _Alloc>
struct __allocator : public _Alloc {
typedef _Alloc __underlying_alloc;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, _Alloc> other;
};
# endif
__allocator() _STLP_NOTHROW {}
__allocator(const _Alloc& ) _STLP_NOTHROW {}
__allocator(const __allocator<_Tp, _Alloc>& __a) _STLP_NOTHROW
: _Alloc(__a) {}
# if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
template <class _Tp1>
__allocator(const __allocator<_Tp1, _Alloc>& __a) _STLP_NOTHROW
: _Alloc(__a) {}
# endif
# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
~__allocator() _STLP_NOTHROW {}
# endif
pointer address(reference __x) const { return &__x; }
# if !defined (__WATCOM_CPLUSPLUS__)
const_pointer address(const_reference __x) const { return &__x; }
# endif
// __n is permitted to be 0.
_Tp* allocate(size_type __n, const void* = 0) {
if (__n > max_size())
__THROW_BAD_ALLOC;
return __n != 0
? __STATIC_CAST(_Tp*,__underlying_alloc::allocate(__n * sizeof(_Tp)))
: 0;
}
// __p is not permitted to be a null pointer.
void deallocate(pointer __p, size_type __n)
{ if (__p) __underlying_alloc::deallocate(__p, __n * sizeof(_Tp)); }
size_type max_size() const _STLP_NOTHROW
{ return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const_reference __val) { _STLP_STD::_Copy_Construct(__p, __val); }
void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
const __underlying_alloc& __get_underlying_alloc() const { return *this; }
};
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Alloc>
class __allocator<void, _Alloc> {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, _Alloc> other;
};
#endif
};
#endif
template <class _Tp, class _Alloc>
inline bool _STLP_CALL operator==(const __allocator<_Tp, _Alloc>& __a1,
const __allocator<_Tp, _Alloc>& __a2)
{
return __a1.__get_underlying_alloc() == __a2.__get_underlying_alloc();
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Tp, class _Alloc>
inline bool _STLP_CALL operator!=(const __allocator<_Tp, _Alloc>& __a1,
const __allocator<_Tp, _Alloc>& __a2)
{
return __a1.__get_underlying_alloc() != __a2.__get_underlying_alloc();
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
// Comparison operators for all of the predifined SGI-style allocators.
// This ensures that __allocator<malloc_alloc> (for example) will
// work correctly.
#ifndef _STLP_NON_TYPE_TMPL_PARAM_BUG
inline bool _STLP_CALL operator==(const __malloc_alloc&, const __malloc_alloc&)
{ return true; }
# ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
inline bool _STLP_CALL operator!=(const __malloc_alloc&, const __malloc_alloc&)
{ return false; }
# endif
inline bool _STLP_CALL operator==(const __new_alloc&, const __new_alloc&) { return true; }
# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
inline bool _STLP_CALL operator!=(const __new_alloc&, const __new_alloc&) { return false; }
# endif
# if !defined (_STLP_USE_NO_IOSTREAMS)
inline bool _STLP_CALL operator==(const __node_alloc&,
const __node_alloc&)
{ return true; }
# if defined( _STLP_FUNCTION_TMPL_PARTIAL_ORDER )
inline bool _STLP_CALL operator!=(const __node_alloc&,
const __node_alloc&)
{ return false; }
# endif
# endif
#endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
template <class _Alloc>
inline bool _STLP_CALL operator==(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) { return true; }
# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Alloc>
inline bool _STLP_CALL operator!=(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) { return false; }
# endif
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
// Versions for the predefined SGI-style allocators.
template <class _Tp>
struct _Alloc_traits<_Tp, __malloc_alloc> {
typedef __allocator<_Tp, __malloc_alloc> allocator_type;
};
# if !defined (_STLP_USE_NO_IOSTREAMS)
template <class _Tp>
struct _Alloc_traits<_Tp, __node_alloc> {
typedef __allocator<_Tp, __node_alloc> allocator_type;
};
# endif
template <class _Tp, class _Alloc>
struct _Alloc_traits<_Tp, __debug_alloc<_Alloc> > {
typedef __allocator<_Tp, __debug_alloc<_Alloc> > allocator_type;
};
// Versions for the __allocator adaptor used with the predefined
// SGI-style allocators.
template <class _Tp, class _Tp1, class _Alloc>
struct _Alloc_traits<_Tp, __allocator<_Tp1, _Alloc > > {
typedef __allocator<_Tp, _Alloc > allocator_type;
};
#endif
#if defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE)
// Versions for the predefined SGI-style allocators.
# if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
typedef __malloc_alloc __malloc_alloc_dfl;
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc_dfl >& _STLP_CALL
__stl_alloc_rebind(__malloc_alloc_dfl& __a, const _Tp*) {
return (__allocator<_Tp, __malloc_alloc_dfl >&)__a;
}
# if !defined (_STLP_USE_NO_IOSTREAMS)
template <class _Tp>
inline __allocator<_Tp, __node_alloc>& _STLP_CALL
__stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __node_alloc>&)__a;
}
# endif
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc_dfl > _STLP_CALL
__stl_alloc_create(const __malloc_alloc_dfl&, const _Tp*) {
return __allocator<_Tp, __malloc_alloc_dfl > ();
}
# if !defined (_STLP_USE_NO_IOSTREAMS)
template <class _Tp>
inline __allocator<_Tp, __node_alloc> _STLP_CALL
__stl_alloc_create(const __node_alloc&, const _Tp*) {
return __allocator<_Tp, __node_alloc>();
}
# endif
# else
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc>& _STLP_CALL
__stl_alloc_rebind(__malloc_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __malloc_alloc>&)__a;
}
# if !defined (_STLP_USE_NO_IOSTREAMS)
template <class _Tp>
inline __allocator<_Tp, __node_alloc>& _STLP_CALL
__stl_alloc_rebind(__node_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __node_alloc>&)__a;
}
# endif
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc> _STLP_CALL
__stl_alloc_create(const __malloc_alloc&, const _Tp*) {
return __allocator<_Tp, __malloc_alloc>();
}
# if !defined (_STLP_USE_NO_IOSTREAMS)
template <class _Tp>
inline __allocator<_Tp, __node_alloc> _STLP_CALL
__stl_alloc_create(const __node_alloc&, const _Tp*) {
return __allocator<_Tp, __node_alloc>();
}
# endif
# endif
template <class _Tp, class _Alloc>
inline __allocator<_Tp, __debug_alloc<_Alloc> > _STLP_CALL
__stl_alloc_create(const __debug_alloc<_Alloc>&, const _Tp*) {
return __allocator<_Tp, __debug_alloc<_Alloc> >();
}
template <class _Tp, class _Alloc>
inline __allocator<_Tp, __debug_alloc<_Alloc> >& _STLP_CALL
__stl_alloc_rebind(__debug_alloc<_Alloc>& __a, const _Tp*) {
return (__allocator<_Tp, __debug_alloc<_Alloc> >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __new_alloc > _STLP_CALL
__stl_alloc_create(const __new_alloc&, const _Tp*) {
return __allocator<_Tp, __new_alloc >();
}
template <class _Tp>
inline __allocator<_Tp, __new_alloc >& _STLP_CALL
__stl_alloc_rebind(__new_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __new_alloc >&)__a;
}
template <class _Tp1, class _Alloc, class _Tp2>
inline __allocator<_Tp2, _Alloc>& _STLP_CALL
__stl_alloc_rebind(__allocator<_Tp1, _Alloc>& __a, const _Tp2*) {
return (__allocator<_Tp2, _Alloc>&)__a;
}
template <class _Tp1, class _Alloc, class _Tp2>
inline __allocator<_Tp2, _Alloc> _STLP_CALL
__stl_alloc_create(const __allocator<_Tp1, _Alloc>&, const _Tp2*) {
return __allocator<_Tp2, _Alloc>();
}
#endif
|