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.

189 lines
5.3 KiB

  1. // memory standard header
  2. #ifndef _MEMORY_
  3. #define _MEMORY_
  4. #include <xmemory>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #endif /* _MSC_VER */
  8. // TEMPLATE OPERATOR new
  9. template<class _Ty>
  10. inline void *operator new(size_t _N, std::allocator<_Ty>& _Al)
  11. {return (_Al._Charalloc(_N)); }
  12. _STD_BEGIN
  13. // TEMPLATE FUNCTION get_temporary_buffer
  14. template<class _Ty> inline
  15. pair<_Ty _FARQ *, _PDFT>
  16. get_temporary_buffer(_PDFT _N, _Ty _FARQ *)
  17. {_Ty _FARQ *_P;
  18. for (_P = 0; 0 < _N; _N /= 2)
  19. if ((_P = (_Ty _FARQ *)operator new(
  20. (_SIZT)_N * sizeof (_Ty), nothrow)) != 0)
  21. break;
  22. return (pair<_Ty _FARQ *, _PDFT>(_P, _N)); }
  23. // TEMPLATE FUNCTION return_temporary_buffer
  24. template<class _Ty> inline
  25. void return_temporary_buffer(_Ty *_P)
  26. {operator delete(_P); }
  27. // TEMPLATE FUNCTION uninitialized_copy
  28. template<class _II, class _FI> inline
  29. _FI uninitialized_copy(_II _F, _II _L, _FI _X)
  30. {for (; _F != _L; ++_X, ++_F)
  31. _Construct(&*_X, *_F);
  32. return (_X); }
  33. // TEMPLATE FUNCTION uninitialized_fill
  34. template<class _FI, class _Ty> inline
  35. void uninitialized_fill(_FI _F, _FI _L, const _Ty& _X)
  36. {for (; _F != _L; ++_F)
  37. _Construct(&*_F, _X); }
  38. // TEMPLATE FUNCTION uninitialized_fill_n
  39. template<class _FI, class _S, class _Ty> inline
  40. void uninitialized_fill_n(_FI _F, _S _N, const _Ty& _X)
  41. {for (; 0 < _N; --_N, ++_F)
  42. _Construct(&*_F, _X); }
  43. // TEMPLATE CLASS raw_storage_iterator
  44. template<class _OI, class _Ty>
  45. class raw_storage_iterator
  46. : public iterator<output_iterator_tag, void, void> {
  47. public:
  48. typedef _OI iterator_type;
  49. typedef _Ty element_type;
  50. explicit raw_storage_iterator(_OI _X)
  51. : _Next(_X) {}
  52. raw_storage_iterator<_OI, _Ty>& operator*()
  53. {return (*this); }
  54. raw_storage_iterator<_OI, _Ty>& operator=(const _Ty& _X)
  55. {_Construct(&*_Next, _X);
  56. return (*this); }
  57. raw_storage_iterator<_OI, _Ty>& operator++()
  58. {++_Next;
  59. return (*this); }
  60. raw_storage_iterator<_OI, _Ty> operator++(int)
  61. {raw_storage_iterator<_OI, _Ty> _Ans = *this;
  62. ++_Next;
  63. return (_Ans); }
  64. private:
  65. _OI _Next;
  66. };
  67. // TEMPLATE CLASS _Temp_iterator
  68. template<class _Ty>
  69. class _Temp_iterator
  70. : public iterator<output_iterator_tag, void, void> {
  71. public:
  72. typedef _Ty _FARQ *_Pty;
  73. _Temp_iterator(_PDFT _N = 0)
  74. {pair<_Pty, _PDFT> _Pair =
  75. get_temporary_buffer(_N, (_Pty)0);
  76. _Buf._Begin = _Pair.first;
  77. _Buf._Cur = _Pair.first;
  78. _Buf._Hiwater = _Pair.first;
  79. _Buf._Len = _Pair.second;
  80. _Pb = &_Buf; }
  81. _Temp_iterator(const _Temp_iterator<_Ty>& _X)
  82. {_Buf._Begin = 0;
  83. _Buf._Cur = 0;
  84. _Buf._Hiwater = 0;
  85. _Buf._Len = 0;
  86. *this = _X; }
  87. ~_Temp_iterator()
  88. {if (_Buf._Begin != 0)
  89. {for (_Pty _F = _Buf._Begin;
  90. _F != _Buf._Hiwater; ++_F)
  91. _Destroy(&*_F);
  92. return_temporary_buffer(_Buf._Begin); }}
  93. _Temp_iterator<_Ty>& operator=(const _Temp_iterator<_Ty>& _X)
  94. {_Pb = _X._Pb;
  95. return (*this); }
  96. _Temp_iterator<_Ty>& operator=(const _Ty& _V)
  97. {if (_Pb->_Cur < _Pb->_Hiwater)
  98. *_Pb->_Cur++ = _V;
  99. else
  100. {_Construct(&*_Pb->_Cur, _V);
  101. _Pb->_Hiwater = ++_Pb->_Cur; }
  102. return (*this); }
  103. _Temp_iterator<_Ty>& operator*()
  104. {return (*this); }
  105. _Temp_iterator<_Ty>& operator++()
  106. {return (*this); }
  107. _Temp_iterator<_Ty>& operator++(int)
  108. {return (*this); }
  109. _Temp_iterator<_Ty>& _Init()
  110. {_Pb->_Cur = _Pb->_Begin;
  111. return (*this); }
  112. _Pty _First() const
  113. {return (_Pb->_Begin); }
  114. _Pty _Last() const
  115. {return (_Pb->_Cur); }
  116. _PDFT _Maxlen() const
  117. {return (_Pb->_Len); }
  118. private:
  119. struct _Bufpar {
  120. _Pty _Begin;
  121. _Pty _Cur;
  122. _Pty _Hiwater;
  123. _PDFT _Len;
  124. } _Buf, *_Pb;
  125. };
  126. // TEMPLATE CLASS auto_ptr
  127. template<class _Ty>
  128. class auto_ptr {
  129. public:
  130. typedef _Ty element_type;
  131. explicit auto_ptr(_Ty *_P = 0) _THROW0()
  132. : _Owns(_P != 0), _Ptr(_P) {}
  133. auto_ptr(const auto_ptr<_Ty>& _Y) _THROW0()
  134. : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
  135. auto_ptr<_Ty>& operator=(const auto_ptr<_Ty>& _Y) _THROW0()
  136. {if (this != &_Y)
  137. {if (_Ptr != _Y.get())
  138. {if (_Owns)
  139. delete _Ptr;
  140. _Owns = _Y._Owns; }
  141. else if (_Y._Owns)
  142. _Owns = true;
  143. _Ptr = _Y.release(); }
  144. return (*this); }
  145. ~auto_ptr()
  146. {if (_Owns)
  147. delete _Ptr; }
  148. _Ty& operator*() const _THROW0()
  149. {return (*get()); }
  150. _Ty *operator->() const _THROW0()
  151. {return (get()); }
  152. _Ty *get() const _THROW0()
  153. {return (_Ptr); }
  154. _Ty *release() const _THROW0()
  155. {((auto_ptr<_Ty> *)this)->_Owns = false;
  156. return (_Ptr); }
  157. private:
  158. bool _Owns;
  159. _Ty *_Ptr;
  160. };
  161. _STD_END
  162. #ifdef _MSC_VER
  163. #pragma pack(pop)
  164. #endif /* _MSC_VER */
  165. #endif /* _MEMORY_ */
  166. /*
  167. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  168. * Consult your license regarding permissions and restrictions.
  169. */
  170. /*
  171. * This file is derived from software bearing the following
  172. * restrictions:
  173. *
  174. * Copyright (c) 1994
  175. * Hewlett-Packard Company
  176. *
  177. * Permission to use, copy, modify, distribute and sell this
  178. * software and its documentation for any purpose is hereby
  179. * granted without fee, provided that the above copyright notice
  180. * appear in all copies and that both that copyright notice and
  181. * this permission notice appear in supporting documentation.
  182. * Hewlett-Packard Company makes no representations about the
  183. * suitability of this software for any purpose. It is provided
  184. * "as is" without express or implied warranty.
  185. */