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.

74 lines
1.5 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( (_SIZT)_N ));
  40. if ( NULL == pRet )
  41. {
  42. throw CX_MemoryException();
  43. }
  44. return pRet; }
  45. void deallocate(void _FARQ *_P, size_type)
  46. {operator delete(_P); }
  47. void construct(pointer _P, const _Ty& _V)
  48. {std::_Construct(_P, _V); }
  49. void destroy(pointer _P)
  50. {std::_Destroy(_P); }
  51. _SIZT max_size() const
  52. {_SIZT _N = (_SIZT)(-1) / sizeof (_Ty);
  53. return (0 < _N ? _N : 1); }
  54. friend bool operator==(const wbem_allocator<_Ty>&, const wbem_allocator<_Ty>&) { return true;}
  55. };
  56. #endif