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.

251 lines
6.2 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. #ifdef _CRTBLD_NATIVE_WCHAR_T
  53. template<> inline
  54. void _Destroy(unsigned short _FARQ *)
  55. { // destroy a unsigned short (do nothing)
  56. }
  57. #endif
  58. // TEMPLATE CLASS allocator
  59. template<class _Ty>
  60. class allocator
  61. { // generic allocator for objects of class _Ty
  62. public:
  63. typedef _SIZT size_type;
  64. typedef _PDFT difference_type;
  65. typedef _Ty _FARQ *pointer;
  66. typedef const _Ty _FARQ *const_pointer;
  67. typedef _Ty _FARQ& reference;
  68. typedef const _Ty _FARQ& const_reference;
  69. typedef _Ty value_type;
  70. template<class _Other>
  71. struct rebind
  72. { // convert an allocator<_Ty> to an allocator <_Other>
  73. typedef allocator<_Other> other;
  74. };
  75. pointer address(reference _Val) const
  76. { // return address of mutable _Val
  77. return (&_Val);
  78. }
  79. const_pointer address(const_reference _Val) const
  80. { // return address of nonmutable _Val
  81. return (&_Val);
  82. }
  83. allocator()
  84. { // construct default allocator (do nothing)
  85. }
  86. allocator(const allocator<_Ty>&)
  87. { // construct by copying (do nothing)
  88. }
  89. template<class _Other>
  90. allocator(const allocator<_Other>&)
  91. { // construct from a related allocator (do nothing)
  92. }
  93. template<class _Other>
  94. allocator<_Ty>& operator=(const allocator<_Other>&)
  95. { // assign from a related allocator (do nothing)
  96. return (*this);
  97. }
  98. template<class _Other>
  99. pointer allocate(size_type _Count, const _Other *)
  100. { // allocate array of _Count elements, ignore hint
  101. // don't call _Allocate directly, in case class is dllimport
  102. return (allocate(_Count));
  103. }
  104. pointer allocate(size_type _Count)
  105. { // allocate array of _Count elements
  106. return (_Allocate(_Count, (pointer)0));
  107. }
  108. void deallocate(pointer _Ptr, size_type)
  109. { // deallocate object at _Ptr, ignore size
  110. operator delete(_Ptr);
  111. }
  112. void construct(pointer _Ptr, const _Ty& _Val)
  113. { // construct object at _Ptr with value _Val
  114. _Construct(_Ptr, _Val);
  115. }
  116. void destroy(pointer _Ptr)
  117. { // destroy object at _Ptr
  118. _Destroy(_Ptr);
  119. }
  120. _SIZT max_size() const
  121. { // estimate maximum array size
  122. _SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
  123. return (0 < _Count ? _Count : 1);
  124. }
  125. };
  126. // allocator TEMPLATE OPERATORS
  127. template<class _Ty,
  128. class _Other> inline
  129. bool operator==(const allocator<_Ty>&, const allocator<_Other>&)
  130. { // test for allocator equality (always true)
  131. return (true);
  132. }
  133. template<class _Ty,
  134. class _Other> inline
  135. bool operator!=(const allocator<_Ty>&, const allocator<_Other>&)
  136. { // test for allocator inequality (always false)
  137. return (false);
  138. }
  139. // CLASS allocator<void>
  140. template<> class _CRTIMP2 allocator<void>
  141. { // generic allocator for type void
  142. public:
  143. typedef void _Ty;
  144. typedef _Ty _FARQ *pointer;
  145. typedef const _Ty _FARQ *const_pointer;
  146. typedef _Ty value_type;
  147. template<class _Other>
  148. struct rebind
  149. { // convert an allocator<void> to an allocator <_Other>
  150. typedef allocator<_Other> other;
  151. };
  152. allocator()
  153. { // construct default allocator (do nothing)
  154. }
  155. allocator(const allocator<_Ty>&)
  156. { // construct by copying (do nothing)
  157. }
  158. template<class _Other>
  159. allocator(const allocator<_Other>&)
  160. { // construct from related allocator (do nothing)
  161. }
  162. template<class _Other>
  163. allocator<_Ty>& operator=(const allocator<_Other>&)
  164. { // assign from a related allocator (do nothing)
  165. return (*this);
  166. }
  167. };
  168. // TEMPLATE FUNCTION _Destroy_range
  169. template<class _Ty,
  170. class _Alloc> inline
  171. void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al)
  172. { // destroy [_First, _Last)
  173. _Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));
  174. }
  175. template<class _Ty,
  176. class _Alloc> inline
  177. void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
  178. _Nonscalar_ptr_iterator_tag)
  179. { // destroy [_First, _Last), arbitrary type
  180. for (; _First != _Last; ++_First)
  181. _Al.destroy(_First);
  182. }
  183. template<class _Ty,
  184. class _Alloc> inline
  185. void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
  186. _Scalar_ptr_iterator_tag)
  187. { // destroy [_First, _Last), scalar type (do nothing)
  188. }
  189. _STD_END
  190. #pragma warning(default: 4100)
  191. #pragma warning(pop)
  192. #pragma pack(pop)
  193. #endif /* _XMEMORY_ */
  194. /*
  195. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  196. * Consult your license regarding permissions and restrictions.
  197. */
  198. /*
  199. * This file is derived from software bearing the following
  200. * restrictions:
  201. *
  202. * Copyright (c) 1994
  203. * Hewlett-Packard Company
  204. *
  205. * Permission to use, copy, modify, distribute and sell this
  206. * software and its documentation for any purpose is hereby
  207. * granted without fee, provided that the above copyright notice
  208. * appear in all copies and that both that copyright notice and
  209. * this permission notice appear in supporting documentation.
  210. * Hewlett-Packard Company makes no representations about the
  211. * suitability of this software for any purpose. It is provided
  212. * "as is" without express or implied warranty.
  213. V3.10:0009 */