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.

166 lines
4.0 KiB

  1. #ifndef _NAMELLST_H_
  2. #define _NAMELLST_H_
  3. #include <objbase.h>
  4. #include "mischlpr.h"
  5. ///////////////////////////////////////////////////////////////////////////////
  6. //
  7. class CNamedElem : public CRefCounted
  8. {
  9. public:
  10. HRESULT GetName(LPTSTR psz, DWORD cch, DWORD* pcchRequired);
  11. virtual HRESULT Init(LPCTSTR pszElemName) PURE;
  12. #ifdef DEBUG
  13. LPCTSTR DbgGetName();
  14. #endif
  15. protected:
  16. CNamedElem();
  17. virtual ~CNamedElem();
  18. HRESULT _SetName(LPCTSTR pszElemName);
  19. HRESULT _FreeName();
  20. protected:
  21. LPTSTR _pszElemName;
  22. // for access to _pelemNext
  23. friend class CNamedElemList;
  24. };
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. class CFillEnum : public CRefCounted
  28. {
  29. public:
  30. virtual HRESULT Next(LPTSTR pszElemName, DWORD cchElemName,
  31. DWORD* pcchRequired) = 0;
  32. };
  33. ///////////////////////////////////////////////////////////////////////////////
  34. //
  35. typedef HRESULT (*NAMEDELEMCREATEFCT)(CNamedElem** ppelem);
  36. // return values:
  37. // S_OK when everything's all right
  38. // S_FALSE when no more items
  39. // E_BUFFERTOOSMALL if buffer too small
  40. typedef HRESULT (*NAMEDELEMGETFILLENUMFCT)(CFillEnum** ppfillenum);
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //
  43. class CElemSlot : public CRefCounted
  44. {
  45. public:
  46. HRESULT Init(CNamedElem* pelem, CElemSlot* pesPrev, CElemSlot* pesNext);
  47. HRESULT Remove();
  48. HRESULT GetNamedElem(CNamedElem** ppelem);
  49. void SetPrev(CElemSlot* pes);
  50. CElemSlot* GetNext();
  51. CElemSlot* GetNextValid();
  52. CElemSlot* GetPrevValid();
  53. BOOL IsValid();
  54. void SetCallbackPointer(CNamedElemList* pnel);
  55. public:
  56. CElemSlot();
  57. virtual ~CElemSlot();
  58. private:
  59. // Payload
  60. CNamedElem* _pelem;
  61. // Impl details
  62. BOOL _fValid;
  63. CElemSlot* _pesPrev;
  64. CElemSlot* _pesNext;
  65. // for callback
  66. class CNamedElemList* _pnel;
  67. };
  68. ///////////////////////////////////////////////////////////////////////////////
  69. //
  70. class CNamedElemEnum : public CRefCounted
  71. {
  72. public:
  73. HRESULT Next(CNamedElem** ppelem);
  74. public:
  75. CNamedElemEnum();
  76. virtual ~CNamedElemEnum();
  77. private:
  78. HRESULT _Init(CElemSlot* pesHead, CRefCountedCritSect* pcsList);
  79. private:
  80. CElemSlot* _pesCurrent;
  81. BOOL _fFirst;
  82. CRefCountedCritSect* _pcsList;
  83. // for access to _Init
  84. friend class CNamedElemList;
  85. };
  86. ///////////////////////////////////////////////////////////////////////////////
  87. //
  88. class CNamedElemList : public CRefCounted
  89. {
  90. public:
  91. HRESULT Init(NAMEDELEMCREATEFCT createfct,
  92. NAMEDELEMGETFILLENUMFCT enumfct);
  93. // Returns S_FALSE if cannot find it
  94. HRESULT Get(LPCTSTR pszElemName, CNamedElem** ppelem);
  95. // Returns S_OK if was already existing
  96. // S_FALSE if was just added
  97. HRESULT GetOrAdd(LPCTSTR pszElemName, CNamedElem** ppelem);
  98. HRESULT Add(LPCTSTR pszElemName, CNamedElem** ppelem);
  99. HRESULT Remove(LPCTSTR pszElemName);
  100. HRESULT ReEnum();
  101. HRESULT EmptyList();
  102. HRESULT GetEnum(CNamedElemEnum** ppenum);
  103. #ifdef DEBUG
  104. HRESULT InitDebug(LPWSTR pszDebugName);
  105. void AssertAllElemsRefCount1();
  106. void AssertNoDuplicate();
  107. #endif
  108. void RealRemoveElemSlotCallback(CElemSlot* pes);
  109. public:
  110. CNamedElemList();
  111. virtual ~CNamedElemList();
  112. private:
  113. HRESULT _Add(LPCTSTR pszElemName, CNamedElem** ppelem);
  114. HRESULT _GetTail(CElemSlot** ppes);
  115. HRESULT _GetElemSlot(LPCTSTR pszElemName, CElemSlot** ppes);
  116. HRESULT _Remove(LPCTSTR pszElemName);
  117. HRESULT _EmptyList();
  118. CElemSlot* _GetValidHead();
  119. private:
  120. CElemSlot* _pesHead;
  121. NAMEDELEMCREATEFCT _createfct;
  122. NAMEDELEMGETFILLENUMFCT _enumfct;
  123. CRefCountedCritSect* _pcs;
  124. #ifdef DEBUG
  125. WCHAR _szDebugName[100];
  126. #endif
  127. };
  128. #endif //_NAMELLST_H_