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.

181 lines
3.4 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1999
  4. Module Name:
  5. EnumTask.h
  6. Abstract:
  7. This header file implements the IEnumTASKImpl template class.
  8. This base class implements an enumerator for tasks to populate a taskpad.
  9. This is an inline template class, there is no cpp class for implementation.
  10. Author:
  11. Michael A. Maguire 02/05/98
  12. Revision History:
  13. mmaguire 02/05/98 - created from MMC taskpad sample code
  14. --*/
  15. //////////////////////////////////////////////////////////////////////////////
  16. #if !defined(_IAS_ENUM_TASKS_H_)
  17. #define _IAS_ENUM_TASKS_H_
  18. //////////////////////////////////////////////////////////////////////////////
  19. // BEGIN INCLUDES
  20. //
  21. // where we can find what this class derives from:
  22. //
  23. //
  24. //
  25. // where we can find what this class has or uses:
  26. //
  27. //
  28. // END INCLUDES
  29. //////////////////////////////////////////////////////////////////////////////
  30. template < class T >
  31. class IEnumTASKImpl : public IEnumTASK
  32. {
  33. public:
  34. IEnumTASKImpl()
  35. {
  36. ATLTRACE(_T("# IEnumTASKImpl::IEnumTASKImpl\n"));
  37. m_refs = 0;
  38. m_index = 0;
  39. m_type = 0; // default group/category
  40. }
  41. ~IEnumTASKImpl()
  42. {
  43. ATLTRACE(_T("# IEnumTASKImpl::~IEnumTASKImpl\n"));
  44. }
  45. // IUnknown implementation
  46. public:
  47. STDMETHOD(QueryInterface) (REFIID riid, LPVOID FAR* ppvObj)
  48. {
  49. ATLTRACE(_T("# IEnumTASKImpl::QueryInterface\n"));
  50. if ( (riid == IID_IUnknown) || (riid == IID_IEnumTASK) )
  51. {
  52. *ppvObj = this;
  53. ((LPUNKNOWN)(*ppvObj))->AddRef();
  54. return NOERROR;
  55. }
  56. *ppvObj = NULL;
  57. return E_NOINTERFACE;
  58. }
  59. STDMETHOD_(ULONG, AddRef)()
  60. {
  61. ATLTRACE(_T("# IEnumTASKImpl::AddRef\n"));
  62. return ++m_refs;
  63. }
  64. STDMETHOD_(ULONG, Release) ()
  65. {
  66. ATLTRACE(_T("# IEnumTASKImpl::Release\n"));
  67. T * pT = static_cast<T*>(this);
  68. if (--m_refs == 0)
  69. {
  70. delete pT;
  71. return 0;
  72. }
  73. return m_refs;
  74. }
  75. private:
  76. ULONG m_refs;
  77. // IEnumTASKS implementation
  78. public:
  79. STDMETHOD(Next) (ULONG celt, MMC_TASK *rgelt, ULONG *pceltFetched)
  80. {
  81. ATLTRACE(_T("# IEnumTASKImpl::Next -- Override in your derived class\n"));
  82. if ( NULL != pceltFetched)
  83. {
  84. *pceltFetched = 0;
  85. }
  86. return S_FALSE; // Failed to enumerate any more tasks.
  87. }
  88. STDMETHOD(Skip) (ULONG celt)
  89. {
  90. ATLTRACE(_T("# IEnumTASKImpl::Skip\n"));
  91. m_index += celt;
  92. return S_OK;
  93. }
  94. STDMETHOD(Reset)()
  95. {
  96. ATLTRACE(_T("# IEnumTASKImpl::Reset\n"));
  97. m_index = 0;
  98. return S_OK;
  99. }
  100. STDMETHOD(Clone)(IEnumTASK **ppEnumTASK)
  101. {
  102. ATLTRACE(_T("# IEnumTASKImpl::Clone\n"));
  103. // Clone maintaining state info
  104. T * pEnumTasks = new T();
  105. if( pEnumTasks )
  106. {
  107. pEnumTasks->CopyState( (T *) this );
  108. return pEnumTasks->QueryInterface (IID_IEnumTASK, (void **)ppEnumTASK); // can't fail
  109. }
  110. return E_OUTOFMEMORY;
  111. }
  112. STDMETHOD(CopyState)( T * pSourceT)
  113. {
  114. ATLTRACE(_T("# IEnumTASKImpl::CopyState\n"));
  115. m_index = pSourceT->m_index;
  116. m_type = pSourceT->m_type;
  117. return S_OK;
  118. }
  119. protected:
  120. ULONG m_index;
  121. public:
  122. STDMETHOD(Init)(IDataObject * pdo, LPOLESTR szTaskGroup)
  123. {
  124. ATLTRACE(_T("# IEnumTASKImpl::Init -- Override in your derived class\n"));
  125. return S_OK;
  126. }
  127. protected:
  128. int m_type; // Task grouping mechanism.
  129. };
  130. #endif // _IAS_ENUM_TASKS_H_