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.

158 lines
3.6 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* GetNextValid();
  51. CElemSlot* GetPrevValid();
  52. BOOL IsValid();
  53. public:
  54. CElemSlot();
  55. virtual ~CElemSlot();
  56. private:
  57. // Payload
  58. CNamedElem* _pelem;
  59. // Impl details
  60. BOOL _fValid;
  61. CElemSlot* _pesPrev;
  62. CElemSlot* _pesNext;
  63. };
  64. ///////////////////////////////////////////////////////////////////////////////
  65. //
  66. class CNamedElemEnum : public CRefCounted
  67. {
  68. public:
  69. HRESULT Next(CNamedElem** ppelem);
  70. public:
  71. CNamedElemEnum();
  72. virtual ~CNamedElemEnum();
  73. private:
  74. HRESULT _Init(CElemSlot* pesHead, CRefCountedCritSect* pcsList);
  75. private:
  76. CElemSlot* _pesCurrent;
  77. BOOL _fFirst;
  78. CRefCountedCritSect* _pcsList;
  79. // for access to _Init
  80. friend class CNamedElemList;
  81. };
  82. ///////////////////////////////////////////////////////////////////////////////
  83. //
  84. class CNamedElemList : public CRefCounted
  85. {
  86. public:
  87. HRESULT Init(NAMEDELEMCREATEFCT createfct,
  88. NAMEDELEMGETFILLENUMFCT enumfct);
  89. // Returns S_FALSE if cannot find it
  90. HRESULT Get(LPCTSTR pszElemName, CNamedElem** ppelem);
  91. // Returns S_OK if was already existing
  92. // S_FALSE if was just added
  93. HRESULT GetOrAdd(LPCTSTR pszElemName, CNamedElem** ppelem);
  94. HRESULT Add(LPCTSTR pszElemName, CNamedElem** ppelem);
  95. HRESULT Remove(LPCTSTR pszElemName);
  96. HRESULT ReEnum();
  97. HRESULT EmptyList();
  98. HRESULT GetEnum(CNamedElemEnum** ppenum);
  99. #ifdef DEBUG
  100. HRESULT InitDebug(LPWSTR pszDebugName);
  101. void AssertAllElemsRefCount1();
  102. void AssertNoDuplicate();
  103. #endif
  104. public:
  105. CNamedElemList();
  106. virtual ~CNamedElemList();
  107. private:
  108. HRESULT _Add(LPCTSTR pszElemName, CNamedElem** ppelem);
  109. HRESULT _GetTail(CElemSlot** ppes);
  110. HRESULT _GetElemSlot(LPCTSTR pszElemName, CElemSlot** ppes);
  111. HRESULT _Remove(LPCTSTR pszElemName);
  112. HRESULT _EmptyList();
  113. CElemSlot* _GetValidHead();
  114. private:
  115. CElemSlot* _pesHead;
  116. NAMEDELEMCREATEFCT _createfct;
  117. NAMEDELEMGETFILLENUMFCT _enumfct;
  118. CRefCountedCritSect* _pcs;
  119. #ifdef DEBUG
  120. WCHAR _szDebugName[100];
  121. #endif
  122. };
  123. #endif //_NAMELLST_H_