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.

89 lines
3.7 KiB

  1. //=--------------------------------------------------------------------------=
  2. // StandardEnum.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // object definition for a generic enumerator object.
  13. //
  14. #ifndef _STANDARDENUM_H_
  15. // A specific implementation of the Clone function
  16. void WINAPI CopyAndAddRefObject(void *pDest, const void *pSource, DWORD dwSize);
  17. // An IEnumConnectionPoints creation function
  18. HRESULT CreateInstance_IEnumConnectionPoints(LPENUMCONNECTIONPOINTS * ppEnum, DWORD count, ...);
  19. // to support a generic Enumerator object, we'll just define this
  20. // interface. it can be safely cast to any other enumerator, since all
  21. // they differ in is their pointer type in Next().
  22. //
  23. class IEnumGeneric: public IUnknown {
  24. public:
  25. virtual HRESULT __stdcall Next(ULONG celt, LPVOID rgelt, ULONG *pceltFetched) = 0;
  26. virtual HRESULT __stdcall Skip(ULONG celt) = 0;
  27. virtual HRESULT __stdcall Reset(void) = 0;
  28. virtual HRESULT __stdcall Clone(IEnumGeneric **ppenum) = 0;
  29. };
  30. //=--------------------------------------------------------------------------=
  31. // StandardEnum
  32. //=--------------------------------------------------------------------------=
  33. // a generic enumerator object. given a pointer to generic data, some
  34. // information about the elements, and a function to copy the elements,
  35. // we can implement a generic enumerator.
  36. //
  37. // NOTE: this class assumes that rgElements is HeapAlloc'd, and will free it
  38. // in it's destructor [although it IS valid for this to be NULL if there
  39. // are no elements to enumerate over.]
  40. //
  41. class CStandardEnum: public IEnumGeneric {
  42. public:
  43. // IUnknown methods
  44. //
  45. STDMETHOD(QueryInterface)(REFIID riid, LPVOID * ppvObj);
  46. STDMETHOD_(ULONG,AddRef)(void);
  47. STDMETHOD_(ULONG,Release)(void);
  48. // IEnumVariant methods
  49. //
  50. STDMETHOD(Next)(unsigned long celt, void * rgvar, unsigned long * pceltFetched);
  51. STDMETHOD(Skip)(unsigned long celt);
  52. STDMETHOD(Reset)();
  53. STDMETHOD(Clone)(IEnumGeneric **ppEnumOut);
  54. CStandardEnum(REFIID riid, BOOL fMembersAreInterfaces, int cElement, int cbElement, void *rgElements,
  55. void (WINAPI * pfnCopyElement)(void *, const void *, DWORD));
  56. virtual ~CStandardEnum();
  57. private:
  58. int m_cRef;
  59. IID m_iid; // type of enumerator that we are
  60. int m_cElements; // Total number of elements
  61. int m_cbElementSize; // Size of each element
  62. int m_iCurrent; // Current position: 0 = front, m_cElt = end
  63. BOOL m_fMembersAreInterfaces; // Indicates that members of the enumerated array are
  64. // Interfaces and that we need to hold refs on them
  65. VOID * m_rgElements; // Array of elements
  66. CStandardEnum *m_pEnumClonedFrom; // If we were cloned, from whom?
  67. void (WINAPI * m_pfnCopyElement)(void *, const void *, DWORD);
  68. const void *GetNthElement(int n)
  69. { return (const BYTE *)m_rgElements + (m_cbElementSize * n); }
  70. };
  71. STDAPI_(void*) CStandardEnum_CreateInstance(REFIID riid, BOOL fMembersAreInterfaces, int cElement, int cbElement, void *rgElements,
  72. void (WINAPI * pfnCopyElement)(void *, const void *, DWORD));
  73. #define _STANDARDENUM_H_
  74. #endif // _STANDARDENUM_H_