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.

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