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.

130 lines
2.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: ptrcache.hxx
  7. //
  8. // Contents: CPtrCache header
  9. //
  10. // Classes: CPtrCache
  11. //
  12. // History: 26-Jul-93 DrewB Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #ifndef __PTRCACHE_HXX__
  16. #define __PTRCACHE_HXX__
  17. #include <debnot.h>
  18. #include <dfmem.hxx>
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Class: CPtrBlock (pb)
  22. //
  23. // Purpose: Holds an array of pointers
  24. //
  25. // Interface: See below
  26. //
  27. // History: 26-Jul-93 DrewB Created
  28. //
  29. //----------------------------------------------------------------------------
  30. #define CBLOCKPTRS 50
  31. class CPtrBlock
  32. {
  33. public:
  34. inline CPtrBlock(CPtrBlock *pbNext);
  35. inline void Add(void *pv);
  36. inline BOOL Full(void);
  37. inline int Count(void);
  38. inline void *Nth(int n);
  39. inline CPtrBlock *Next(void);
  40. private:
  41. int _cPtrs;
  42. CPtrBlock *_pbNext;
  43. void *_apv[CBLOCKPTRS];
  44. };
  45. inline CPtrBlock::CPtrBlock(CPtrBlock *pbNext)
  46. {
  47. _cPtrs = 0;
  48. _pbNext = pbNext;
  49. }
  50. inline void CPtrBlock::Add(void *pv)
  51. {
  52. Win4Assert(_cPtrs < CBLOCKPTRS);
  53. _apv[_cPtrs++] = pv;
  54. }
  55. inline BOOL CPtrBlock::Full(void)
  56. {
  57. return _cPtrs == CBLOCKPTRS;
  58. }
  59. inline int CPtrBlock::Count(void)
  60. {
  61. return _cPtrs;
  62. }
  63. inline void *CPtrBlock::Nth(int n)
  64. {
  65. Win4Assert(n >= 0 && n < _cPtrs);
  66. return _apv[n];
  67. }
  68. inline CPtrBlock *CPtrBlock::Next(void)
  69. {
  70. return _pbNext;
  71. }
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Class: CPtrCache (pc)
  75. //
  76. // Purpose: Holds an arbitrary number of pointers using an efficient
  77. // block allocation scheme
  78. //
  79. // Interface: See below
  80. //
  81. // History: 26-Jul-93 DrewB Created
  82. //
  83. //----------------------------------------------------------------------------
  84. class CPtrCache : public CLocalAlloc
  85. {
  86. public:
  87. inline CPtrCache(void);
  88. ~CPtrCache(void);
  89. SCODE Add(void *pv);
  90. inline void StartEnum(void);
  91. BOOL Next(void **ppv);
  92. private:
  93. CPtrBlock _pbFirst;
  94. CPtrBlock *_pbHead;
  95. CPtrBlock *_pbEnum;
  96. int _iEnum;
  97. };
  98. inline CPtrCache::CPtrCache(void)
  99. : _pbFirst(NULL)
  100. {
  101. _pbHead = &_pbFirst;
  102. StartEnum();
  103. }
  104. inline void CPtrCache::StartEnum(void)
  105. {
  106. _pbEnum = _pbHead;
  107. _iEnum = 0;
  108. }
  109. #endif // #ifndef __PTRCACHE_HXX__