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.

115 lines
2.1 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. CScopeTreeIterator::CScopeTreeIterator() : m_pMTNodeCurr(NULL)
  25. {
  26. DEBUG_INCREMENT_INSTANCE_COUNTER(CScopeTreeIterator);
  27. }
  28. CScopeTreeIterator::~CScopeTreeIterator()
  29. {
  30. DEBUG_DECREMENT_INSTANCE_COUNTER(CScopeTreeIterator);
  31. }
  32. STDMETHODIMP CScopeTreeIterator::SetCurrent(HMTNODE hMTNode)
  33. {
  34. MMC_TRY
  35. if (hMTNode == 0)
  36. return E_INVALIDARG;
  37. m_pMTNodeCurr = CMTNode::FromHandle(hMTNode);
  38. return S_OK;
  39. MMC_CATCH
  40. }
  41. STDMETHODIMP CScopeTreeIterator::Next(UINT nRequested, HMTNODE* rghScopeItems,
  42. UINT* pnFetched)
  43. {
  44. MMC_TRY
  45. if (rghScopeItems == NULL || pnFetched == NULL)
  46. return E_POINTER;
  47. *pnFetched = 0; // init
  48. if (nRequested == 0)
  49. return S_OK;
  50. int i = 0;
  51. CMTNode** rgpMTNodes = reinterpret_cast<CMTNode**>(rghScopeItems);
  52. while (m_pMTNodeCurr != NULL && nRequested--)
  53. {
  54. rgpMTNodes[i++] = m_pMTNodeCurr;
  55. m_pMTNodeCurr = m_pMTNodeCurr->Next();
  56. }
  57. *pnFetched = i;
  58. return S_OK;
  59. MMC_CATCH
  60. }
  61. STDMETHODIMP CScopeTreeIterator::Child(HMTNODE* phsiChild)
  62. {
  63. MMC_TRY
  64. if (phsiChild == NULL)
  65. return E_POINTER;
  66. *phsiChild = 0; // init
  67. if (m_pMTNodeCurr != NULL)
  68. *phsiChild = CMTNode::ToHandle(m_pMTNodeCurr->Child());
  69. return S_OK;
  70. MMC_CATCH
  71. }
  72. STDMETHODIMP CScopeTreeIterator::Parent(HMTNODE* phsiParent)
  73. {
  74. MMC_TRY
  75. if (phsiParent == NULL)
  76. return E_POINTER;
  77. *phsiParent = 0; // init
  78. if (m_pMTNodeCurr != NULL)
  79. *phsiParent = CMTNode::ToHandle(m_pMTNodeCurr->Child());
  80. return S_OK;
  81. MMC_CATCH
  82. }