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