1 // xmemory internal header (from <memory>)
2 #pragma once
3 #ifndef _XMEMORY_
4 #define _XMEMORY_
5 #ifndef RC_INVOKED
6 #include <cstdlib>
7 #include <exception>
8 #include <new>
9 #include <xutility>
10
11 #ifdef  _MSC_VER
12  #pragma pack(push,_CRT_PACKING)
13  #pragma warning(push,3)
14  #pragma warning(disable: 4100)
15 #endif  /* _MSC_VER */
16
17 #ifndef _FARQ    /* specify standard memory model */
18  #define _FARQ
19  #define _PDFT    ptrdiff_t
20  #define _SIZT    size_t
21 #endif /* _FARQ */
22
23  #define _CPOINTER_X(T, A)        \
24     typename A::template rebind<T>::other::const_pointer
25  #define _CREFERENCE_X(T, A)    \
26     typename A::template rebind<T>::other::const_reference
27  #define _POINTER_X(T, A)    \
28     typename A::template rebind<T>::other::pointer
29  #define _REFERENCE_X(T, A)    \
30     typename A::template rebind<T>::other::reference
31
32 _STD_BEGIN
33         // TEMPLATE FUNCTION _Allocate
34 template<class _Ty> inline
35     _Ty _FARQ *_Allocate(_SIZT _Count, _Ty _FARQ *)
36     {    // check for integer overflow
37     if (_Count <= 0)
38         _Count = 0;
39     else if (((_SIZT)(-1) / _Count) < sizeof (_Ty))
40         _THROW_NCEE(std::bad_alloc, NULL);
41
42         // allocate storage for _Count elements of type _Ty
43     return ((_Ty _FARQ *)::operator new(_Count * sizeof (_Ty)));
44     }
45
46         // TEMPLATE FUNCTION _Construct
47 template<class _T1,
48     class _T2> inline
49     void _Construct(_T1 _FARQ *_Ptr, const _T2& _Val)
50     {    // construct object at _Ptr with value _Val
51     void _FARQ *_Vptr = _Ptr;
52     ::new (_Vptr) _T1(_Val);
53     }
54
55         // TEMPLATE FUNCTION _Destroy
56 template<class _Ty> inline
57     void _Destroy(_Ty _FARQ *_Ptr)
58     {    // destroy object at _Ptr
59     _DESTRUCTOR(_Ty, _Ptr);
60     }
61
62 template<> inline
63     void _Destroy(char _FARQ *)
64     {    // destroy a char (do nothing)
65     }
66
67 template<> inline
68     void _Destroy(wchar_t _FARQ *)
69     {    // destroy a wchar_t (do nothing)
70     }
71
72
73         // TEMPLATE CLASS _Allocator_base
74 template<class _Ty>
75     struct _Allocator_base
76     {    // base class for generic allocators
77     typedef _Ty value_type;
78     };
79
80         // TEMPLATE CLASS _Allocator_base<const _Ty>
81 template<class _Ty>
82     struct _Allocator_base<const _Ty>
83     {    // base class for generic allocators for const _Ty
84     typedef _Ty value_type;
85     };
86
87         // TEMPLATE CLASS allocator
88 template<class _Ty>
89     class allocator
90         : public _Allocator_base<_Ty>
91     {    // generic allocator for objects of class _Ty
92 public:
93     typedef _Allocator_base<_Ty> _Mybase;
94     typedef typename _Mybase::value_type value_type;
95     typedef value_type _FARQ *pointer;
96     typedef value_type _FARQ& reference;
97     typedef const value_type _FARQ *const_pointer;
98     typedef const value_type _FARQ& const_reference;
99
100     typedef _SIZT size_type;
101     typedef _PDFT difference_type;
102
103     template<class _Other>
104         struct rebind
105         {    // convert an allocator<_Ty> to an allocator <_Other>
106         typedef allocator<_Other> other;
107         };
108
109     pointer address(reference _Val) const
110         {    // return address of mutable _Val
111         return (&_Val);
112         }
113
114     const_pointer address(const_reference _Val) const
115         {    // return address of nonmutable _Val
116         return (&_Val);
117         }
118
119     allocator() _THROW0()
120         {    // construct default allocator (do nothing)
121         }
122
123     allocator(const allocator<_Ty>&) _THROW0()
124         {    // construct by copying (do nothing)
125         }
126
Lines 127 ... 136 are skipped.
137
138     void deallocate(pointer _Ptr, size_type)
139         {    // deallocate object at _Ptr, ignore size
140         ::operator delete(_Ptr);
141         }
142
143     pointer allocate(size_type _Count)
144         {    // allocate array of _Count elements
145         return (_Allocate(_Count, (pointer)0));
146         }
147
148     pointer allocate(size_type _Count, const void _FARQ *)
149         {    // allocate array of _Count elements, ignore hint
150         return (allocate(_Count));
151         }
152
153     void construct(pointer _Ptr, const _Ty& _Val)
154         {    // construct object at _Ptr with value _Val
155         _Construct(_Ptr, _Val);
156         }
157
158     void destroy(pointer _Ptr)
159         {    // destroy object at _Ptr
160         _Destroy(_Ptr);
161         }
162
163     _SIZT max_size() const _THROW0()
164         {    // estimate maximum array size
165         _SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
166         return (0 < _Count ? _Count : 1);
167         }
168     };
169
170         // allocator TEMPLATE OPERATORS
171 template<class _Ty,
172     class _Other> inline
173     bool operator==(const allocator<_Ty>&, const allocator<_Other>&) _THROW0()
174     {    // test for allocator equality (always true)
175     return (true);
176     }
177
178 template<class _Ty,
179     class _Other> inline
180     bool operator!=(const allocator<_Ty>&, const allocator<_Other>&) _THROW0()
181     {    // test for allocator inequality (always false)
182     return (false);
183     }
184
185         // CLASS allocator<void>
186 template<> class _CRTIMP2_PURE allocator<void>
187     {    // generic allocator for type void
188 public:
189     typedef void _Ty;
190     typedef _Ty _FARQ *pointer;
191     typedef const _Ty _FARQ *const_pointer;
192     typedef _Ty value_type;
193
194     template<class _Other>
195         struct rebind
196         {    // convert an allocator<void> to an allocator <_Other>
197         typedef allocator<_Other> other;
198         };
199
200     allocator() _THROW0()
201         {    // construct default allocator (do nothing)
202         }
203
204     allocator(const allocator<_Ty>&) _THROW0()
205         {    // construct by copying (do nothing)
206         }
207
208     template<class _Other>
209         allocator(const allocator<_Other>&) _THROW0()
210         {    // construct from related allocator (do nothing)
211         }
212
213     template<class _Other>
214         allocator<_Ty>& operator=(const allocator<_Other>&)
215         {    // assign from a related allocator (do nothing)
216         return (*this);
217         }
218     };
219
220         // TEMPLATE FUNCTION _Destroy_range
221 template<class _Alloc> inline
222     void _Destroy_range(typename _Alloc::pointer _First,
223         typename _Alloc::pointer _Last, _Alloc& _Al)
224     {    // destroy [_First, _Last)
225     _Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));
226     }
227
228 template<class _Alloc> inline
229     void _Destroy_range(typename _Alloc::pointer _First,
230         typename _Alloc::pointer _Last, _Alloc& _Al,
231         _Nonscalar_ptr_iterator_tag)
232     {    // destroy [_First, _Last), arbitrary type
233     for (; _First != _Last; ++_First)
234         _Al.destroy(_First);
235     }
236
237 template<class _Alloc> inline
238     void _Destroy_range(typename _Alloc::pointer _First,
239         typename _Alloc::pointer _Last, _Alloc& _Al,
240         _Scalar_ptr_iterator_tag)
241     {    // destroy [_First, _Last), scalar type (do nothing)
242     }
243 _STD_END
244
245 #ifdef _MSC_VER
246  #pragma warning(default: 4100)
247  #pragma warning(pop)
248  #pragma pack(pop)
249 #endif  /* _MSC_VER */
250
251 #endif /* RC_INVOKED */
252 #endif /* _XMEMORY_ */
253
254 /*
255  * Copyright (c) 1992-2007 by P.J. Plauger.  ALL RIGHTS RESERVED.
256  * Consult your license regarding permissions and restrictions.
257  */
258
259 /*
260  * This file is derived from software bearing the following
261  * restrictions:
262  *
263  * Copyright (c) 1994
264  * Hewlett-Packard Company
265  *
266  * Permission to use, copy, modify, distribute and sell this
267  * software and its documentation for any purpose is hereby
268  * granted without fee, provided that the above copyright notice
269  * appear in all copies and that both that copyright notice and
270  * this permission notice appear in supporting documentation.
271  * Hewlett-Packard Company makes no representations about the
272  * suitability of this software for any purpose. It is provided
273  * "as is" without express or implied warranty.
274  V5.03:0009 */
275