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.

86 lines
2.0 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. #ifndef __GUIDENUM_H__
  3. #define __GUIDENUM_H__
  4. #include "mediaobj.h"
  5. template<typename T> class CArrayContainer {
  6. public:
  7. CArrayContainer(ULONG ulSize = 0) {
  8. if (ulSize) {
  9. m_ulMax = ulSize;
  10. m_ulUsed = 0;
  11. m_ar = (T*)malloc(ulSize * sizeof(T));
  12. }
  13. else
  14. m_ar = NULL;
  15. }
  16. ~CArrayContainer() {if (m_ar) free(m_ar);}
  17. HRESULT Add(const T& el) {
  18. if (!m_ar) {
  19. m_ulMax = 20;
  20. m_ulUsed = 0;
  21. m_ar = (T*)malloc(m_ulMax * sizeof(T));
  22. if (!m_ar)
  23. return E_OUTOFMEMORY;
  24. }
  25. else if (m_ulUsed == m_ulMax) {
  26. ULONG ulNew = m_ulMax + 20;
  27. T* pNew = (T*)realloc(m_ar, ulNew * sizeof(T));
  28. if (!pNew)
  29. return E_OUTOFMEMORY;
  30. m_ulMax = ulNew;
  31. m_ar = pNew;
  32. }
  33. m_ar[m_ulUsed++] = el;
  34. return NOERROR;
  35. }
  36. T* GetNth(ULONG ulPos) {
  37. if (ulPos >= m_ulUsed)
  38. return NULL;
  39. return &m_ar[ulPos];
  40. }
  41. ULONG GetSize(void) {
  42. return m_ulUsed;
  43. }
  44. private:
  45. T* m_ar;
  46. ULONG m_ulMax;
  47. ULONG m_ulUsed;
  48. };
  49. // implements IEnumDMO, which is returned by DMO enumeration API
  50. class CEnumDMOCLSID : public IEnumDMO {
  51. public:
  52. CEnumDMOCLSID();
  53. ~CEnumDMOCLSID();
  54. // IUnknown
  55. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  56. STDMETHODIMP_(ULONG) AddRef();
  57. STDMETHODIMP_(ULONG) Release();
  58. // enum
  59. STDMETHODIMP Next(ULONG celt, CLSID *pclsidItems, WCHAR **pszNames, ULONG *pceltFetched);
  60. STDMETHODIMP Skip(ULONG celt);
  61. STDMETHODIMP Reset(void);
  62. STDMETHODIMP Clone(IEnumDMO **ppenum);
  63. // private
  64. void Add(REFCLSID clsidDMO, WCHAR *szName);
  65. private:
  66. typedef struct {
  67. CLSID clsid;
  68. WCHAR *szName;
  69. } Entry;
  70. volatile long m_cRef;
  71. CArrayContainer<Entry> m_store;
  72. ULONG m_ulPos;
  73. };
  74. #endif //__GUIDENUM_H__