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.

238 lines
5.5 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: MetaUtil object
  6. File: KeyCol.h
  7. Owner: t-BrianM
  8. This file contains the headers for the key collections.
  9. ===================================================================*/
  10. #ifndef __KEYCOL_H_
  11. #define __KEYCOL_H_
  12. #if _MSC_VER >= 1000
  13. #pragma once
  14. #endif // _MSC_VER >= 1000
  15. #include "resource.h" // main symbols
  16. /*
  17. * C F l a t K e y C o l l e c t i o n
  18. *
  19. * Implements non-recursive subkey collections.
  20. */
  21. class CFlatKeyCollection :
  22. public IDispatchImpl<IKeyCollection, &IID_IKeyCollection, &LIBID_MetaUtil>,
  23. public ISupportErrorInfo,
  24. public CComObjectRoot
  25. {
  26. public:
  27. BEGIN_COM_MAP(CFlatKeyCollection)
  28. COM_INTERFACE_ENTRY(IDispatch)
  29. COM_INTERFACE_ENTRY(IKeyCollection)
  30. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  31. END_COM_MAP()
  32. DECLARE_NOT_AGGREGATABLE(CFlatKeyCollection)
  33. CFlatKeyCollection();
  34. HRESULT Init(const CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszBaseKey);
  35. ~CFlatKeyCollection();
  36. // IKeyCollection
  37. STDMETHOD(get_Count)(/*[out, retval]*/ long *plReturn);
  38. STDMETHOD(get_Item)(/*[in]*/ long lIndex, /*[out, retval]*/ BSTR *pbstrRetKey);
  39. STDMETHOD(get__NewEnum)(/*[out, retval]*/ LPUNKNOWN *ppIReturn);
  40. STDMETHOD(Add)(/*[in]*/ BSTR bstrRelKey);
  41. STDMETHOD(Remove)(/*[in]*/ BSTR bstrRelKey);
  42. // ISupportsErrorInfo
  43. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  44. private:
  45. LPTSTR m_tszBaseKey;
  46. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  47. CComPtr<IMSAdminBase> m_pIMeta;
  48. };
  49. /*
  50. * C F l a t K e y E n u m
  51. *
  52. * Implements non-recursive subkey enumerations.
  53. */
  54. class CFlatKeyEnum :
  55. public IEnumVARIANT,
  56. public CComObjectRoot
  57. {
  58. public:
  59. CFlatKeyEnum();
  60. HRESULT Init(const CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszBaseKey, int iIndex);
  61. ~CFlatKeyEnum();
  62. BEGIN_COM_MAP(CFlatKeyEnum)
  63. COM_INTERFACE_ENTRY(IEnumVARIANT)
  64. END_COM_MAP()
  65. DECLARE_NOT_AGGREGATABLE(CFlatKeyEnum)
  66. //IEnumVARIANT
  67. STDMETHOD(Next)(unsigned long ulNumToGet,
  68. VARIANT FAR* rgvarDest,
  69. unsigned long FAR* pulNumGot);
  70. STDMETHOD(Skip)(unsigned long ulNumToSkip);
  71. STDMETHOD(Reset)();
  72. STDMETHOD(Clone)(IEnumVARIANT FAR* FAR* ppIReturn);
  73. private:
  74. int m_iIndex;
  75. LPTSTR m_tszBaseKey;
  76. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  77. CComPtr<IMSAdminBase> m_pIMeta;
  78. };
  79. /*
  80. * C K e y S t a c k
  81. *
  82. * C K e y S t a c k N o d e
  83. *
  84. * Internal classes used to maintain and clone the state for a
  85. * deep key enumberation.
  86. */
  87. class CKeyStack;
  88. class CKeyStackNode {
  89. friend CKeyStack;
  90. public:
  91. CKeyStackNode() { m_tszRelKey = NULL; m_iIndex = 0; m_pCNext = NULL; }
  92. HRESULT Init(LPCTSTR tszRelKey, int iIndex);
  93. ~CKeyStackNode();
  94. int GetIndex() { return m_iIndex; }
  95. void SetIndex(int iIndex) { ASSERT(iIndex >= 0); m_iIndex = iIndex; }
  96. LPTSTR GetBaseKey() { return m_tszRelKey; }
  97. CKeyStackNode *Clone();
  98. private:
  99. LPTSTR m_tszRelKey;
  100. int m_iIndex;
  101. CKeyStackNode *m_pCNext;
  102. };
  103. class CKeyStack {
  104. public:
  105. CKeyStack() { m_pCTop = NULL; }
  106. ~CKeyStack();
  107. void Push(CKeyStackNode *pCNew);
  108. CKeyStackNode *Pop();
  109. BOOL IsEmpty() { return (m_pCTop == NULL); }
  110. CKeyStack *Clone();
  111. private:
  112. CKeyStackNode *m_pCTop;
  113. };
  114. /*
  115. * C D e e p K e y C o l l e c t i o n
  116. *
  117. * Implements recursive (depth first) subkey collections.
  118. */
  119. class CDeepKeyCollection :
  120. public IDispatchImpl<IKeyCollection, &IID_IKeyCollection, &LIBID_MetaUtil>,
  121. public ISupportErrorInfo,
  122. public CComObjectRoot
  123. {
  124. public:
  125. BEGIN_COM_MAP(CDeepKeyCollection)
  126. COM_INTERFACE_ENTRY(IDispatch)
  127. COM_INTERFACE_ENTRY(IKeyCollection)
  128. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  129. END_COM_MAP()
  130. DECLARE_NOT_AGGREGATABLE(CDeepKeyCollection)
  131. CDeepKeyCollection();
  132. HRESULT Init(const CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszBaseKey);
  133. ~CDeepKeyCollection();
  134. // IKeyCollection
  135. STDMETHOD(get_Count)(/*[out, retval]*/ long *plReturn);
  136. STDMETHOD(get_Item)(/*[in]*/ long lIndex, /*[out, retval]*/ BSTR *pbstrRetKey);
  137. STDMETHOD(get__NewEnum)(/*[out, retval]*/ LPUNKNOWN *ppIReturn);
  138. STDMETHOD(Add)(/*[in]*/ BSTR bstrRelKey);
  139. STDMETHOD(Remove)(/*[in]*/ BSTR bstrRelKey);
  140. // ISupportsErrorInfo
  141. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  142. private:
  143. LPTSTR m_tszBaseKey;
  144. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  145. CComPtr<IMSAdminBase> m_pIMeta;
  146. HRESULT CountKeys(LPTSTR tszBaseKey, long *plNumKeys);
  147. HRESULT IndexItem(LPTSTR tszRelKey, long lDestIndex, long *plCurIndex, LPTSTR ptszRet);
  148. };
  149. /*
  150. * C D e e p K e y E n u m
  151. *
  152. * Implements recursive (depth first) subkey enumerations.
  153. */
  154. class CDeepKeyEnum :
  155. public IEnumVARIANT,
  156. public CComObjectRoot
  157. {
  158. public:
  159. CDeepKeyEnum();
  160. HRESULT Init(const CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszBaseKey, CKeyStack *pCKeyStack);
  161. ~CDeepKeyEnum();
  162. BEGIN_COM_MAP(CDeepKeyEnum)
  163. COM_INTERFACE_ENTRY(IEnumVARIANT)
  164. END_COM_MAP()
  165. DECLARE_NOT_AGGREGATABLE(CDeepKeyEnum)
  166. //IEnumVARIANT
  167. STDMETHOD(Next)(unsigned long ulNumToGet,
  168. VARIANT FAR* rgvarDest,
  169. unsigned long FAR* pulNumGot);
  170. STDMETHOD(Skip)(unsigned long ulNumToSkip);
  171. STDMETHOD(Reset)();
  172. STDMETHOD(Clone)(IEnumVARIANT FAR* FAR* ppenum);
  173. private:
  174. LPTSTR m_tszBaseKey;
  175. CKeyStack *m_pCKeyStack;
  176. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  177. CComPtr<IMSAdminBase> m_pIMeta;
  178. };
  179. #endif //__KEYCOL_H_