Leaked source code of windows server 2003
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.

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