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.

74 lines
1.4 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. WSTLALLC.H
  5. Abstract:
  6. WMI STL Allocator so we can throw exceptions
  7. History:
  8. sanjes 16-Aug-99 Created
  9. --*/
  10. #ifndef __WSTLALLC_H__
  11. #define __WSTLALLC_H__
  12. #include <memory>
  13. #include "corex.h"
  14. template<class _Ty>
  15. class wbem_allocator {
  16. public:
  17. typedef _SIZT size_type;
  18. typedef _PDFT difference_type;
  19. typedef _Ty _FARQ *pointer;
  20. typedef const _Ty _FARQ *const_pointer;
  21. typedef _Ty _FARQ& reference;
  22. typedef const _Ty _FARQ& const_reference;
  23. typedef _Ty value_type;
  24. pointer address(reference _X) const
  25. {return (&_X); }
  26. const_pointer address(const_reference _X) const
  27. {return (&_X); }
  28. pointer allocate(size_type _N, const void *)
  29. {
  30. _Ty _FARQ * pRet = ((_Ty _FARQ *)operator new(
  31. (_SIZT)_N * sizeof (_Ty)));
  32. if ( NULL == pRet )
  33. {
  34. throw CX_MemoryException();
  35. }
  36. return pRet; }
  37. char _FARQ *_Charalloc(size_type _N)
  38. {
  39. char _FARQ * pRet = ((char _FARQ *)operator new(
  40. (_SIZT)_N * sizeof (_Ty)));
  41. if ( NULL == pRet )
  42. {
  43. throw CX_MemoryException();
  44. }
  45. return pRet; }
  46. void deallocate(void _FARQ *_P, size_type)
  47. {operator delete(_P); }
  48. void construct(pointer _P, const _Ty& _V)
  49. {std::_Construct(_P, _V); }
  50. void destroy(pointer _P)
  51. {std::_Destroy(_P); }
  52. _SIZT max_size() const
  53. {_SIZT _N = (_SIZT)(-1) / sizeof (_Ty);
  54. return (0 < _N ? _N : 1); }
  55. };
  56. #endif