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.

152 lines
3.3 KiB

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