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.

204 lines
5.4 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: ScopIter.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History:
  15. //____________________________________________________________________________
  16. //
  17. #include "stdafx.h"
  18. #include "scopiter.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. DEBUG_DECLARE_INSTANCE_COUNTER(CScopeTreeIterator);
  24. //+-------------------------------------------------------------------
  25. //
  26. // Member: CScopeTreeIterator::CScopeTreeIterator
  27. //
  28. // Synopsis: constructor for CScopeTreeIterator
  29. //
  30. // Arguments: -
  31. //
  32. // Returns: -
  33. //
  34. //--------------------------------------------------------------------
  35. CScopeTreeIterator::CScopeTreeIterator() : m_pMTNodeCurr(NULL)
  36. {
  37. DEBUG_INCREMENT_INSTANCE_COUNTER(CScopeTreeIterator);
  38. }
  39. //+-------------------------------------------------------------------
  40. //
  41. // Member: CScopeTreeIterator::~CScopeTreeIterator
  42. //
  43. // Synopsis: destructor for CScopeTreeIterator
  44. //
  45. // Arguments: -
  46. //
  47. // Returns: -
  48. //
  49. //--------------------------------------------------------------------
  50. CScopeTreeIterator::~CScopeTreeIterator()
  51. {
  52. DEBUG_DECREMENT_INSTANCE_COUNTER(CScopeTreeIterator);
  53. }
  54. //+-------------------------------------------------------------------
  55. //
  56. // Member: CScopeTreeIterator::SetCurrent
  57. //
  58. // Synopsis: Set's the iterator's current node
  59. //
  60. // Arguments: hMTNode: node to set as current
  61. //
  62. // Returns: HRESULT (E_INVALIDARG or S_OK)
  63. //
  64. //--------------------------------------------------------------------
  65. STDMETHODIMP CScopeTreeIterator::SetCurrent(HMTNODE hMTNode)
  66. {
  67. DECLARE_SC(sc, TEXT("CScopeTreeIterator::SetCurrent"));
  68. if (hMTNode == 0)
  69. {
  70. sc = E_INVALIDARG;
  71. return (sc.ToHr());
  72. }
  73. m_pMTNodeCurr = CMTNode::FromHandle(hMTNode);
  74. return sc.ToHr();
  75. }
  76. //+-------------------------------------------------------------------
  77. //
  78. // Member: CScopeTreeIterator::Next
  79. //
  80. // Synopsis: Sets the next node (if any) as current and returns a pointer to
  81. // the same. (May be NULL)
  82. //
  83. // Arguments: phScopeItem: [OUT] Non-null Pointer to location for the
  84. // node to be returned.
  85. //
  86. // Returns: HRESULT (E_INVALIDARG or S_OK)
  87. //
  88. //--------------------------------------------------------------------
  89. STDMETHODIMP CScopeTreeIterator::Next(HMTNODE* phScopeItem)
  90. {
  91. DECLARE_SC(sc, TEXT("CScopeTreeIterator::Next"));
  92. sc = ScCheckPointers(phScopeItem);
  93. if(sc)
  94. return sc.ToHr();
  95. if(m_pMTNodeCurr)
  96. m_pMTNodeCurr = m_pMTNodeCurr->Next();
  97. CMTNode** pMTNode = reinterpret_cast<CMTNode**>(phScopeItem);
  98. *pMTNode = m_pMTNodeCurr;
  99. return sc.ToHr();
  100. }
  101. //+-------------------------------------------------------------------
  102. //
  103. // Member: CScopeTreeIterator::Prev
  104. //
  105. // Synopsis: Sets the prev node (if any) as current and returns a pointer to
  106. // the same. (May be NULL)
  107. //
  108. // Arguments: phScopeItem: [OUT] Non-null Pointer to location for the
  109. // node to be returned.
  110. //
  111. // Returns: HRESULT (E_INVALIDARG or S_OK)
  112. //
  113. //--------------------------------------------------------------------
  114. STDMETHODIMP CScopeTreeIterator::Prev(HMTNODE* phScopeItem)
  115. {
  116. DECLARE_SC(sc, TEXT("CScopeTreeIterator::Prev"));
  117. sc = ScCheckPointers(phScopeItem);
  118. if(sc)
  119. return sc.ToHr();
  120. if(m_pMTNodeCurr)
  121. m_pMTNodeCurr = m_pMTNodeCurr->Prev();
  122. CMTNode** pMTNode = reinterpret_cast<CMTNode**>(phScopeItem);
  123. *pMTNode = m_pMTNodeCurr;
  124. return sc.ToHr();
  125. }
  126. //+-------------------------------------------------------------------
  127. //
  128. // Member: CScopeTreeIterator::Child
  129. //
  130. // Synopsis: Returns the child of the current node. NULL if either
  131. // current node or child is NULL.
  132. //
  133. // Arguments: phsiChild: [OUT] Non-null Pointer to location for the
  134. // node to be returned.
  135. //
  136. // Returns: HRESULT (E_INVALIDARG or S_OK)
  137. //
  138. //--------------------------------------------------------------------
  139. STDMETHODIMP CScopeTreeIterator::Child(HMTNODE* phsiChild)
  140. {
  141. DECLARE_SC(sc, TEXT("CScopeTreeIterator::Child"));
  142. sc = ScCheckPointers(phsiChild);
  143. if(sc)
  144. return sc.ToHr();
  145. *phsiChild = 0; // init
  146. if (m_pMTNodeCurr != NULL)
  147. *phsiChild = CMTNode::ToHandle(m_pMTNodeCurr->Child());
  148. return sc.ToHr();
  149. }
  150. //+-------------------------------------------------------------------
  151. //
  152. // Member: CScopeTreeIterator::LastChild
  153. //
  154. // Synopsis: Returns the last child of the current node. NULL if either
  155. // current node or last child is NULL.
  156. //
  157. // Arguments: phsiLastChild: [OUT] Non-null Pointer to location for the
  158. // node to be returned.
  159. //
  160. // Returns: HRESULT (E_INVALIDARG or S_OK)
  161. //
  162. //--------------------------------------------------------------------
  163. STDMETHODIMP CScopeTreeIterator::LastChild(HMTNODE* phsiLastChild)
  164. {
  165. DECLARE_SC(sc, TEXT("CScopeTreeIterator::LastChild"));
  166. sc = ScCheckPointers(phsiLastChild);
  167. if(sc)
  168. return sc.ToHr();
  169. *phsiLastChild = 0; // init
  170. if (m_pMTNodeCurr != NULL)
  171. *phsiLastChild = CMTNode::ToHandle(m_pMTNodeCurr->LastChild());
  172. return sc.ToHr();
  173. }