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.

94 lines
2.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: ptrcache.cxx
  7. //
  8. // Contents: CPtrCache implementation
  9. //
  10. // History: 26-Jul-93 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "exphead.cxx"
  14. #pragma hdrstop
  15. #include <ptrcache.hxx>
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Member: CPtrCache::~CPtrCache, public
  19. //
  20. // Synopsis: Destructor
  21. //
  22. // History: 26-Jul-93 DrewB Created
  23. //
  24. //----------------------------------------------------------------------------
  25. CPtrCache::~CPtrCache(void)
  26. {
  27. CPtrBlock *pb;
  28. Win4Assert(_pbHead != NULL);
  29. while (_pbHead != &_pbFirst)
  30. {
  31. pb = _pbHead->Next();
  32. delete _pbHead;
  33. _pbHead = pb;
  34. }
  35. }
  36. //+---------------------------------------------------------------------------
  37. //
  38. // Member: CPtrCache::Add, public
  39. //
  40. // Synopsis: Adds a pointer to the cache
  41. //
  42. // Arguments: [pv] - Pointer
  43. //
  44. // Returns: Appropriate status code
  45. //
  46. // History: 26-Jul-93 DrewB Created
  47. //
  48. //----------------------------------------------------------------------------
  49. SCODE CPtrCache::Add(void *pv)
  50. {
  51. CPtrBlock *pb;
  52. Win4Assert(_pbHead != NULL);
  53. if (_pbHead->Full())
  54. {
  55. pb = new CPtrBlock(_pbHead);
  56. if (pb == NULL)
  57. return E_OUTOFMEMORY;
  58. _pbHead = pb;
  59. }
  60. _pbHead->Add(pv);
  61. return S_OK;
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Member: CPtrCache::Next, public
  66. //
  67. // Synopsis: Returns the next element in the enumeration
  68. //
  69. // Arguments: [ppv] - Pointer return
  70. //
  71. // Returns: TRUE/FALSE
  72. //
  73. // History: 26-Jul-93 DrewB Created
  74. //
  75. //----------------------------------------------------------------------------
  76. BOOL CPtrCache::Next(void **ppv)
  77. {
  78. if (_pbEnum && _iEnum >= _pbEnum->Count())
  79. _pbEnum = _pbEnum->Next();
  80. if (_pbEnum == NULL)
  81. return FALSE;
  82. *ppv = _pbEnum->Nth(_iEnum++);
  83. return TRUE;
  84. }