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.

172 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Enum.hxx
  5. Abstract:
  6. Declaration of VSS_OBJECT_PROP_Array
  7. Adi Oltean [aoltean] 08/31/1999
  8. Revision History:
  9. Name Date Comments
  10. aoltean 08/31/1999 Created
  11. aoltean 09/09/1999 dss -> vss
  12. aoltean 09/13/1999 VSS_OBJECT_PROP_Copy moved into inc\Copy.hxx
  13. aoltean 09/20/1999 VSS_OBJECT_PROP_Copy renamed as VSS_OBJECT_PROP_Manager
  14. aoltean 09/21/1999 Renaming back VSS_OBJECT_PROP_Manager to VSS_OBJECT_PROP_Copy.
  15. Adding VSS_OBJECT_PROP_Ptr as a pointer to the properties structure.
  16. This pointer will serve as element in CSimpleArray constructs.
  17. Moving into basestor\vss\inc folder
  18. --*/
  19. #ifndef __VSS_ENUM_COORD_HXX__
  20. #define __VSS_ENUM_COORD_HXX__
  21. #if _MSC_VER > 1000
  22. #pragma once
  23. #endif
  24. ////////////////////////////////////////////////////////////////////////
  25. // Standard foo for file name aliasing. This code block must be after
  26. // all includes of VSS header files.
  27. //
  28. #ifdef VSS_FILE_ALIAS
  29. #undef VSS_FILE_ALIAS
  30. #endif
  31. #define VSS_FILE_ALIAS "INCENUMH"
  32. //
  33. ////////////////////////////////////////////////////////////////////////
  34. /////////////////////////////////////////////////////////////////////////////
  35. // VSS_OBJECT_PROP_Array
  36. class VSS_OBJECT_PROP_Array:
  37. public CSimpleArray <VSS_OBJECT_PROP_Ptr>,
  38. public IUnknown
  39. {
  40. // Typedefs
  41. public:
  42. class iterator
  43. {
  44. public:
  45. iterator(): m_nIndex(0), m_pArr(NULL) {};
  46. iterator(VSS_OBJECT_PROP_Array* pArr, int nIndex = 0)
  47. : m_nIndex(nIndex), m_pArr(pArr)
  48. {
  49. BS_ASSERT(m_pArr->GetSize() >= m_nIndex); // Equality only when pointing to the "end"
  50. BS_ASSERT(m_pArr);
  51. };
  52. iterator(const iterator& it): // To support postfix ++
  53. m_nIndex(it.m_nIndex), m_pArr(it.m_pArr)
  54. {
  55. BS_ASSERT(m_pArr->GetSize() >= m_nIndex); // Equality only when pointing to the "end"
  56. BS_ASSERT(m_pArr);
  57. };
  58. iterator& operator = (const iterator& rhs) {
  59. m_nIndex = rhs.m_nIndex;
  60. m_pArr = rhs.m_pArr;
  61. BS_ASSERT(m_pArr);
  62. BS_ASSERT(m_pArr->GetSize() >= m_nIndex); // Equality only when pointing to the "end"
  63. return (*this);
  64. };
  65. bool operator != (const iterator& rhs) {
  66. BS_ASSERT(m_pArr);
  67. BS_ASSERT(m_pArr == rhs.m_pArr); // Impossible to be reached by the ATL code
  68. return (m_nIndex != rhs.m_nIndex);
  69. };
  70. VSS_OBJECT_PROP& operator * () {
  71. BS_ASSERT(m_pArr);
  72. BS_ASSERT(m_nIndex <= m_pArr->GetSize());
  73. VSS_OBJECT_PROP_Ptr& ptr = (*m_pArr)[m_nIndex];
  74. VSS_OBJECT_PROP* pStruct = ptr.GetStruct();
  75. BS_ASSERT(pStruct);
  76. return *pStruct;
  77. };
  78. iterator operator ++ (int) { // Postfix ++
  79. BS_ASSERT(m_pArr);
  80. BS_ASSERT(m_nIndex < m_pArr->GetSize());
  81. m_nIndex++;
  82. return (*this);
  83. };
  84. private:
  85. int m_nIndex;
  86. VSS_OBJECT_PROP_Array* m_pArr;
  87. };
  88. // Constructors& destructors
  89. private:
  90. VSS_OBJECT_PROP_Array(const VSS_OBJECT_PROP_Array&);
  91. public:
  92. VSS_OBJECT_PROP_Array(): m_lRef(0) {};
  93. // Operations
  94. public:
  95. iterator begin() {
  96. return iterator(this, 0);
  97. }
  98. iterator end() {
  99. return iterator(this, GetSize());
  100. }
  101. // Ovverides
  102. public:
  103. STDMETHOD(QueryInterface)(REFIID iid, void** pp)
  104. {
  105. if (pp == NULL)
  106. return E_INVALIDARG;
  107. if (iid != IID_IUnknown)
  108. return E_NOINTERFACE;
  109. AddRef();
  110. IUnknown** pUnk = reinterpret_cast<IUnknown**>(pp);
  111. (*pUnk) = static_cast<IUnknown*>(this);
  112. return S_OK;
  113. };
  114. STDMETHOD_(ULONG, AddRef)()
  115. {
  116. return ::InterlockedIncrement(&m_lRef);
  117. };
  118. STDMETHOD_(ULONG, Release)()
  119. {
  120. LONG l = ::InterlockedDecrement(&m_lRef);
  121. if (l == 0)
  122. delete this; // We suppose that we always allocate this object on the heap!
  123. return l;
  124. };
  125. // Implementation
  126. public:
  127. LONG m_lRef;
  128. };
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CVssEnumFromArray
  131. typedef CComEnumOnSTL< IVssEnumObject, &IID_IVssEnumObject, VSS_OBJECT_PROP,
  132. VSS_OBJECT_PROP_Copy, VSS_OBJECT_PROP_Array >
  133. CVssEnumFromArray;
  134. #endif // __VSS_ENUM_COORD_HXX__