Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
6.0 KiB

  1. // xmemory internal header (from <memory>)
  2. #pragma once
  3. #ifndef _XMEMORY_
  4. #define _XMEMORY_
  5. #include <cstdlib>
  6. #include <new>
  7. #include <xutility>
  8. #pragma pack(push,8)
  9. #pragma warning(push,3)
  10. #pragma warning(disable: 4100)
  11. #ifndef _FARQ /* specify standard memory model */
  12. #define _FARQ
  13. #define _PDFT ptrdiff_t
  14. #define _SIZT size_t
  15. #endif
  16. #define _CPOINTER_X(T, A) \
  17. typename A::_TEMPLATE_MEMBER rebind<T>::other::const_pointer
  18. #define _CREFERENCE_X(T, A) \
  19. typename A::_TEMPLATE_MEMBER rebind<T>::other::const_reference
  20. #define _POINTER_X(T, A) \
  21. typename A::_TEMPLATE_MEMBER rebind<T>::other::pointer
  22. #define _REFERENCE_X(T, A) \
  23. typename A::_TEMPLATE_MEMBER rebind<T>::other::reference
  24. _STD_BEGIN
  25. // TEMPLATE FUNCTION _Allocate
  26. template<class _Ty> inline
  27. _Ty _FARQ *_Allocate(_SIZT _Count, _Ty _FARQ *)
  28. { // allocate storage for _Count elements of type _Ty
  29. return ((_Ty _FARQ *)operator new(_Count * sizeof (_Ty)));
  30. }
  31. // TEMPLATE FUNCTION _Construct
  32. template<class _T1,
  33. class _T2> inline
  34. void _Construct(_T1 _FARQ *_Ptr, const _T2& _Val)
  35. { // construct object at _Ptr with value _Val
  36. new ((void _FARQ *)_Ptr) _T1(_Val);
  37. }
  38. // TEMPLATE FUNCTION _Destroy
  39. template<class _Ty> inline
  40. void _Destroy(_Ty _FARQ *_Ptr)
  41. { // destroy object at _Ptr
  42. _DESTRUCTOR(_Ty, _Ptr);
  43. }
  44. template<> inline
  45. void _Destroy(char _FARQ *)
  46. { // destroy a char (do nothing)
  47. }
  48. template<> inline
  49. void _Destroy(wchar_t _FARQ *)
  50. { // destroy a wchar_t (do nothing)
  51. }
  52. // TEMPLATE CLASS allocator
  53. template<class _Ty>
  54. class allocator
  55. { // generic allocator for objects of class _Ty
  56. public:
  57. typedef _SIZT size_type;
  58. typedef _PDFT difference_type;
  59. typedef _Ty _FARQ *pointer;
  60. typedef const _Ty _FARQ *const_pointer;
  61. typedef _Ty _FARQ& reference;
  62. typedef const _Ty _FARQ& const_reference;
  63. typedef _Ty value_type;
  64. template<class _Other>
  65. struct rebind
  66. { // convert an allocator<_Ty> to an allocator <_Other>
  67. typedef allocator<_Other> other;
  68. };
  69. pointer address(reference _Val) const
  70. { // return address of mutable _Val
  71. return (&_Val);
  72. }
  73. const_pointer address(const_reference _Val) const
  74. { // return address of nonmutable _Val
  75. return (&_Val);
  76. }
  77. allocator()
  78. { // construct default allocator (do nothing)
  79. }
  80. allocator(const allocator<_Ty>&)
  81. { // construct by copying (do nothing)
  82. }
  83. template<class _Other>
  84. allocator(const allocator<_Other>&)
  85. { // construct from a related allocator (do nothing)
  86. }
  87. template<class _Other>
  88. allocator<_Ty>& operator=(const allocator<_Other>&)
  89. { // assign from a related allocator (do nothing)
  90. return (*this);
  91. }
  92. template<class _Other>
  93. pointer allocate(size_type _Count, const _Other *)
  94. { // allocate array of _Count elements, ignore hint
  95. // don't call _Allocate directly, in case class is dllimport
  96. return (allocate(_Count));
  97. }
  98. pointer allocate(size_type _Count)
  99. { // allocate array of _Count elements
  100. return (_Allocate(_Count, (pointer)0));
  101. }
  102. void deallocate(pointer _Ptr, size_type)
  103. { // deallocate object at _Ptr, ignore size
  104. operator delete(_Ptr);
  105. }
  106. void construct(pointer _Ptr, const _Ty& _Val)
  107. { // construct object at _Ptr with value _Val
  108. _Construct(_Ptr, _Val);
  109. }
  110. void destroy(pointer _Ptr)
  111. { // destroy object at _Ptr
  112. _Destroy(_Ptr);
  113. }
  114. _SIZT max_size() const
  115. { // estimate maximum array size
  116. _SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
  117. return (0 < _Count ? _Count : 1);
  118. }
  119. };
  120. // allocator TEMPLATE OPERATORS
  121. template<class _Ty,
  122. class _Other> inline
  123. bool operator==(const allocator<_Ty>&, const allocator<_Other>&)
  124. { // test for allocator equality (always true)
  125. return (true);
  126. }
  127. template<class _Ty,
  128. class _Other> inline
  129. bool operator!=(const allocator<_Ty>&, const allocator<_Other>&)
  130. { // test for allocator inequality (always false)
  131. return (false);
  132. }
  133. // CLASS allocator<void>
  134. template<> class _CRTIMP2 allocator<void>
  135. { // generic allocator for type void
  136. public:
  137. typedef void _Ty;
  138. typedef _Ty _FARQ *pointer;
  139. typedef const _Ty _FARQ *const_pointer;
  140. typedef _Ty value_type;
  141. template<class _Other>
  142. struct rebind
  143. { // convert an allocator<void> to an allocator <_Other>
  144. typedef allocator<_Other> other;
  145. };
  146. allocator()
  147. { // construct default allocator (do nothing)
  148. }
  149. allocator(const allocator<_Ty>&)
  150. { // construct by copying (do nothing)
  151. }
  152. template<class _Other>
  153. allocator(const allocator<_Other>&)
  154. { // construct from related allocator (do nothing)
  155. }
  156. template<class _Other>
  157. allocator<_Ty>& operator=(const allocator<_Other>&)
  158. { // assign from a related allocator (do nothing)
  159. return (*this);
  160. }
  161. };
  162. // TEMPLATE FUNCTION _Destroy_range
  163. template<class _Ty,
  164. class _Alloc> inline
  165. void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al)
  166. { // destroy [_First, _Last)
  167. _Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));
  168. }
  169. template<class _Ty,
  170. class _Alloc> inline
  171. void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
  172. _Nonscalar_ptr_iterator_tag)
  173. { // destroy [_First, _Last), arbitrary type
  174. for (; _First != _Last; ++_First)
  175. _Al.destroy(_First);
  176. }
  177. template<class _Ty,
  178. class _Alloc> inline
  179. void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
  180. _Scalar_ptr_iterator_tag)
  181. { // destroy [_First, _Last), scalar type (do nothing)
  182. }
  183. _STD_END
  184. #pragma warning(default: 4100)
  185. #pragma warning(pop)
  186. #pragma pack(pop)
  187. #endif /* _XMEMORY_ */
  188. /*
  189. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  190. * Consult your license regarding permissions and restrictions.
  191. */
  192. /*
  193. * This file is derived from software bearing the following
  194. * restrictions:
  195. *
  196. * Copyright (c) 1994
  197. * Hewlett-Packard Company
  198. *
  199. * Permission to use, copy, modify, distribute and sell this
  200. * software and its documentation for any purpose is hereby
  201. * granted without fee, provided that the above copyright notice
  202. * appear in all copies and that both that copyright notice and
  203. * this permission notice appear in supporting documentation.
  204. * Hewlett-Packard Company makes no representations about the
  205. * suitability of this software for any purpose. It is provided
  206. * "as is" without express or implied warranty.
  207. V3.10:0009 */