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.

109 lines
3.2 KiB

  1. // xmemory internal header (from <memory>)
  2. #ifndef _XMEMORY_
  3. #define _XMEMORY_
  4. #include <cstdlib>
  5. #include <new>
  6. #ifdef _MSC_VER
  7. #pragma pack(push,8)
  8. #endif /* _MSC_VER */
  9. #include <utility>
  10. #ifndef _FARQ /* specify standard memory model */
  11. #define _FARQ
  12. #define _PDFT ptrdiff_t
  13. #define _SIZT size_t
  14. #endif
  15. #define _POINTER_X(T, A) T _FARQ *
  16. #define _REFERENCE_X(T, A) T _FARQ &
  17. _STD_BEGIN
  18. // TEMPLATE FUNCTION _Allocate
  19. template<class _Ty> inline
  20. _Ty _FARQ *_Allocate(_PDFT _N, _Ty _FARQ *)
  21. {if (_N < 0)
  22. _N = 0;
  23. return ((_Ty _FARQ *)operator new(
  24. (_SIZT)_N * sizeof (_Ty))); }
  25. // TEMPLATE FUNCTION _Construct
  26. template<class _T1, class _T2> inline
  27. void _Construct(_T1 _FARQ *_P, const _T2& _V)
  28. {new ((void _FARQ *)_P) _T1(_V); }
  29. // TEMPLATE FUNCTION _Destroy
  30. template<class _Ty> inline
  31. void _Destroy(_Ty _FARQ *_P)
  32. {_DESTRUCTOR(_Ty, _P); }
  33. inline void _Destroy(char _FARQ *_P)
  34. {}
  35. inline void _Destroy(wchar_t _FARQ *_P)
  36. {}
  37. // TEMPLATE CLASS allocator
  38. template<class _Ty>
  39. class allocator {
  40. public:
  41. typedef _SIZT size_type;
  42. typedef _PDFT difference_type;
  43. typedef _Ty _FARQ *pointer;
  44. typedef const _Ty _FARQ *const_pointer;
  45. typedef _Ty _FARQ& reference;
  46. typedef const _Ty _FARQ& const_reference;
  47. typedef _Ty value_type;
  48. pointer address(reference _X) const
  49. {return (&_X); }
  50. const_pointer address(const_reference _X) const
  51. {return (&_X); }
  52. pointer allocate(size_type _N, const void *)
  53. {return (_Allocate((difference_type)_N, (pointer)0)); }
  54. char _FARQ *_Charalloc(size_type _N)
  55. {return (_Allocate((difference_type)_N,
  56. (char _FARQ *)0)); }
  57. void deallocate(void _FARQ *_P, size_type)
  58. {operator delete(_P); }
  59. void construct(pointer _P, const _Ty& _V)
  60. {_Construct(_P, _V); }
  61. void destroy(pointer _P)
  62. {_Destroy(_P); }
  63. _SIZT max_size() const
  64. {_SIZT _N = (_SIZT)(-1) / sizeof (_Ty);
  65. return (0 < _N ? _N : 1); }
  66. };
  67. template<class _Ty, class _U> inline
  68. bool operator==(const allocator<_Ty>&, const allocator<_U>&)
  69. {return (true); }
  70. template<class _Ty, class _U> inline
  71. bool operator!=(const allocator<_Ty>&, const allocator<_U>&)
  72. {return (false); }
  73. // CLASS allocator<void>
  74. template<> class _CRTIMP2 allocator<void> {
  75. public:
  76. typedef void _Ty;
  77. typedef _Ty _FARQ *pointer;
  78. typedef const _Ty _FARQ *const_pointer;
  79. typedef _Ty value_type;
  80. };
  81. _STD_END
  82. #ifdef _MSC_VER
  83. #pragma pack(pop)
  84. #endif /* _MSC_VER */
  85. #endif /* _XMEMORY_ */
  86. /*
  87. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  88. * Consult your license regarding permissions and restrictions.
  89. */
  90. /*
  91. * This file is derived from software bearing the following
  92. * restrictions:
  93. *
  94. * Copyright (c) 1994
  95. * Hewlett-Packard Company
  96. *
  97. * Permission to use, copy, modify, distribute and sell this
  98. * software and its documentation for any purpose is hereby
  99. * granted without fee, provided that the above copyright notice
  100. * appear in all copies and that both that copyright notice and
  101. * this permission notice appear in supporting documentation.
  102. * Hewlett-Packard Company makes no representations about the
  103. * suitability of this software for any purpose. It is provided
  104. * "as is" without express or implied warranty.
  105. */