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.

184 lines
5.0 KiB

  1. // ScopeMap.h - Create a map of Scope items.
  2. //
  3. // History: a-jsari 10/7/97 Initial version
  4. //
  5. // Copyright (c) 1998-1999 Microsoft Corporation
  6. #pragma once
  7. #include <afxtempl.h>
  8. #include "DataSrc.h"
  9. #include "ViewObj.h"
  10. #include "Consts.h"
  11. // This hack is required because we may be building in an environment
  12. // which doesn't have a late enough version of rpcndr.h
  13. #if __RPCNDR_H_VERSION__ < 440
  14. #define __RPCNDR_H_VERSION__ 440
  15. #define MIDL_INTERFACE(x) interface
  16. #endif
  17. #ifndef __mmc_h__
  18. #include <mmc.h>
  19. #endif // __mmc_h__
  20. /*
  21. * CScopeItem - an object which can be inserted in a CMapStringToOb which contains
  22. * an HSCOPEITEM
  23. *
  24. * History: a-jsari 12/16/97 Initial version.
  25. */
  26. class CScopeItem : public CObject {
  27. public:
  28. CScopeItem() {}
  29. CScopeItem(HSCOPEITEM hsiNew) :m_hsiValue(hsiNew) { }
  30. CScopeItem(const CScopeItem &siCopy) :m_hsiValue(siCopy.m_hsiValue) { }
  31. ~CScopeItem() {}
  32. const CScopeItem &operator=(const CScopeItem &siCopy)
  33. {
  34. if (&siCopy != this)
  35. SetValue(siCopy.GetValue());
  36. return *this;
  37. }
  38. void SetValue(HSCOPEITEM hsiSet) { m_hsiValue = hsiSet; }
  39. HSCOPEITEM GetValue() const { return m_hsiValue; }
  40. private:
  41. HSCOPEITEM m_hsiValue;
  42. };
  43. /*
  44. * CScopeItemMap - Wrapper function for two cross-mappings of HSCOPEITEM and
  45. * CViewObject pairs.
  46. *
  47. * History: a-jsari 10/7/97 Initial version.
  48. */
  49. class CScopeItemMap {
  50. public:
  51. CScopeItemMap() :m_mapScopeToView(MapIncrement), m_mapViewToScope(MapIncrement)
  52. { m_mapScopeToView.InitHashTable(HashSize); m_mapViewToScope.InitHashTable(HashSize); }
  53. ~CScopeItemMap() { Clear(); }
  54. CFolder *CategoryFromScope(HSCOPEITEM hsiNode) const;
  55. void InsertRoot(CViewObject *pvoRootData, HSCOPEITEM hsiNode);
  56. void Insert(CViewObject *pvoData, HSCOPEITEM hsiNode);
  57. BOOL ScopeFromView(CViewObject *pvoNode, HSCOPEITEM &hsiNode) const;
  58. BOOL ScopeFromName(const CString &strName, HSCOPEITEM &hsiNode) const;
  59. void Clear();
  60. private:
  61. static const int MapIncrement;
  62. static const int HashSize;
  63. CMap<HSCOPEITEM, HSCOPEITEM &, CViewObject *, CViewObject * &> m_mapScopeToView;
  64. CMap<CViewObject *, CViewObject * &, HSCOPEITEM, HSCOPEITEM &> m_mapViewToScope;
  65. CMapStringToOb m_mapNameToScope;
  66. };
  67. /*
  68. * CategoryFromScope - Return the CDataCategory pointer, given the hsiNode.
  69. * Note: Do not free the resultant pointer.
  70. *
  71. * History: a-jsari 10/7/97
  72. */
  73. inline CFolder *CScopeItemMap::CategoryFromScope(HSCOPEITEM hsiNode) const
  74. {
  75. CViewObject *pvoData;
  76. if (m_mapScopeToView.Lookup(hsiNode, pvoData) == 0) return NULL;
  77. // Root category.
  78. return pvoData->Category();
  79. }
  80. /*
  81. * Insert - Inserts the pvoData <-> hsiNode pairing into the maps.
  82. *
  83. * History: a-jsari 10/8/97
  84. */
  85. inline void CScopeItemMap::Insert(CViewObject *pvoData, HSCOPEITEM hsiNode)
  86. {
  87. CString strName;
  88. m_mapScopeToView.SetAt(hsiNode, pvoData);
  89. m_mapViewToScope.SetAt(pvoData, hsiNode);
  90. pvoData->Category()->InternalName(strName);
  91. m_mapNameToScope.SetAt(strName, new CScopeItem(hsiNode));
  92. }
  93. /*
  94. * InsertRoot - Special case insertion for the ROOT node (which always has
  95. * a Cookie of Zero), but which we want to have a legitamate object for
  96. * the Node.
  97. *
  98. * History: a-jsari 10/10/97
  99. */
  100. inline void CScopeItemMap::InsertRoot(CViewObject *pvoData, HSCOPEITEM hsiNode)
  101. {
  102. CString strValue = cszRootName;
  103. CViewObject *pvoNullCookie = NULL;
  104. m_mapScopeToView.SetAt(hsiNode, pvoData);
  105. // Insert the NULL cookie as the index for the HSCOPEITEM
  106. m_mapViewToScope.SetAt(pvoNullCookie, hsiNode);
  107. m_mapNameToScope.SetAt(strValue, new CScopeItem(hsiNode));
  108. }
  109. /*
  110. * ScopeFromView - Return the HSCOPEITEM pvoNode maps to, in hsiNode.
  111. *
  112. * Return Codes:
  113. * TRUE - Successful completion
  114. * FALSE - pvoNode could not be found in the map.
  115. *
  116. * History: a-jsari 10/8/97
  117. */
  118. inline BOOL CScopeItemMap::ScopeFromView(CViewObject *pvoNode, HSCOPEITEM &hsiNode) const
  119. {
  120. return m_mapViewToScope.Lookup(pvoNode, hsiNode);
  121. }
  122. /*
  123. * ScopeFromName - Return the scope item
  124. *
  125. * History: a-jsari 12/11/97
  126. */
  127. inline BOOL CScopeItemMap::ScopeFromName(const CString &strName, HSCOPEITEM &hsiNode) const
  128. {
  129. BOOL fReturn;
  130. CScopeItem *psiNode;
  131. fReturn = m_mapNameToScope.Lookup(strName, (CObject * &)psiNode);
  132. if (fReturn) hsiNode = psiNode->GetValue();
  133. return fReturn;
  134. }
  135. /*
  136. * clear - Remove all map items and free the CViewObject pointers
  137. *
  138. * History: a-jsari 10/7/97
  139. */
  140. inline void CScopeItemMap::Clear()
  141. {
  142. if (m_mapScopeToView.IsEmpty()) {
  143. ASSERT(m_mapViewToScope.IsEmpty());
  144. return;
  145. }
  146. CViewObject *pvoIterator;
  147. CString strIterator;
  148. CScopeItem *psiIterator;
  149. HSCOPEITEM hsiIterator;
  150. POSITION posCurrent;
  151. posCurrent = m_mapScopeToView.GetStartPosition();
  152. while (posCurrent != NULL) {
  153. m_mapScopeToView.GetNextAssoc(posCurrent, hsiIterator, pvoIterator);
  154. VERIFY(m_mapScopeToView.RemoveKey(hsiIterator));
  155. delete pvoIterator;
  156. }
  157. posCurrent = m_mapNameToScope.GetStartPosition();
  158. while (posCurrent != NULL) {
  159. m_mapNameToScope.GetNextAssoc(posCurrent, strIterator, (CObject * &)psiIterator);
  160. VERIFY(m_mapNameToScope.RemoveKey(strIterator));
  161. delete psiIterator;
  162. }
  163. ASSERT(m_mapScopeToView.IsEmpty());
  164. m_mapViewToScope.RemoveAll();
  165. }