home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / xmemory < prev    next >
Text File  |  1998-06-16  |  3KB  |  115 lines

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