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.

81 lines
1.9 KiB

  1. /*
  2. *
  3. * Copyright (c) 1998,1999 Microsoft Corporation. All rights reserved.
  4. * EXEMPT: copyright change only, no build required
  5. *
  6. */
  7. #ifndef _RAWSTACK_HXX
  8. #define _RAWSTACK_HXX
  9. #pragma once
  10. //===========================================================================
  11. // This is a raw stack based on a contiguous block of memory that is divided
  12. // up into chunks.
  13. //
  14. // This is a Non-GC class because it is used in the tokenizer.
  15. //
  16. class RawStack
  17. {
  18. public:
  19. RawStack(long entrySize, long growth);
  20. ~RawStack();
  21. protected:
  22. inline char* _push() { if (_ncSize == _ncUsed) return __push(); return &_pStack[_lEntrySize * _ncUsed++]; }
  23. inline char* _pop() { if (_ncUsed > 0) _ncUsed--; return _peek(); }
  24. inline char* _peek() { if (_ncUsed == 0) return NULL; return &_pStack[_lEntrySize * (_ncUsed - 1)]; }
  25. inline char* _item(long index) { if (index >= _ncSize) return NULL; else return &_pStack[_lEntrySize * index]; }
  26. long _lEntrySize;
  27. char* _pStack;
  28. long _ncUsed;
  29. long _ncSize;
  30. long _lGrowth;
  31. private:
  32. char* __push();
  33. };
  34. //===========================================================================
  35. // This class implements a raw stack of C primitive types (or structs).
  36. template <class T> class _rawstack : public RawStack
  37. {
  38. public:
  39. _rawstack<T>(long growth) : RawStack(sizeof(T),growth)
  40. {
  41. }
  42. T* push()
  43. {
  44. return (T*)_push();
  45. }
  46. T* pop()
  47. {
  48. return (T*)_pop();
  49. }
  50. T* peek()
  51. {
  52. return (T*)_peek();
  53. }
  54. long size()
  55. {
  56. return _ncSize;
  57. }
  58. long used()
  59. {
  60. return _ncUsed;
  61. }
  62. T* operator[](long index)
  63. {
  64. return (T*)_item(index);
  65. }
  66. };
  67. #endif _RAWSTACK_HXX