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.

146 lines
4.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////
  2. // TuningSpaceCollectionImpl.h : Declaration of the TuningSpaceCollectionImpl.h
  3. // Copyright (c) Microsoft Corporation 1999-2000
  4. #include <tuner.h>
  5. namespace BDATuningModel {
  6. typedef CComQIPtr<ITuningSpace> PQTuningSpace;
  7. typedef std::map<ULONG, CComVariant> TuningSpaceContainer_t; // id->object mapping, id's not contiguous
  8. // utilities for element management semantics for TuningSpaceContainerEnum_t
  9. class stlmapClone
  10. {
  11. public:
  12. static HRESULT copy(VARIANT* p1, std::pair<const ULONG, CComVariant> *p2) {
  13. if (p2->second.vt != VT_DISPATCH && p2->second.vt != VT_UNKNOWN) {
  14. return DISP_E_TYPEMISMATCH;
  15. }
  16. PQTuningSpace pts(p2->second.punkVal);
  17. if (!pts) {
  18. return E_UNEXPECTED;
  19. }
  20. p1->vt = p2->second.vt;
  21. PQTuningSpace pnewts;
  22. HRESULT hr = pts->Clone(&pnewts);
  23. if (FAILED(hr)) {
  24. return hr;
  25. }
  26. p1->punkVal = pnewts.Detach();
  27. return NOERROR;
  28. }
  29. static void init(VARIANT* p) {VariantInit(p);}
  30. static void destroy(VARIANT* p) {VariantClear(p);}
  31. };
  32. typedef CComEnumOnSTL<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT, stlmapClone, TuningSpaceContainer_t, CComMultiThreadModel> TuningSpaceContainerEnum_t;
  33. class stlmapClone2
  34. {
  35. public:
  36. static HRESULT copy(ITuningSpace** p1, std::pair<const ULONG, CComVariant> *p2) {
  37. if (p2->second.vt != VT_DISPATCH && p2->second.vt != VT_UNKNOWN) {
  38. return DISP_E_TYPEMISMATCH;
  39. }
  40. PQTuningSpace p(p2->second.punkVal);
  41. if (!p) {
  42. return E_UNEXPECTED;
  43. }
  44. // don't ASSERT(p1 && !*p1); if !p1 then clone will return E_POINTER and p1 itself
  45. // can point to unitialized memory if the caller passed down a new'd array of pointers
  46. // to enum::Next(). therefore if this clone causes a leak then its the callers bug
  47. return p->Clone(p1);
  48. }
  49. static void init(ITuningSpace** p) {*p = NULL;}
  50. static void destroy(ITuningSpace** p) {(*p)->Release(); *p = NULL;}
  51. };
  52. typedef CComEnumOnSTL<IEnumTuningSpaces, &__uuidof(IEnumTuningSpaces), ITuningSpace*, stlmapClone2, TuningSpaceContainer_t, CComMultiThreadModel> TuningSpaceEnum_t;
  53. template<class T, class TSInterface, LPCGUID TSInterfaceID, LPCGUID TypeLibID> class TuningSpaceCollectionImpl :
  54. public IDispatchImpl<TSInterface, TSInterfaceID, TypeLibID> {
  55. public:
  56. TuningSpaceContainer_t m_mapTuningSpaces;
  57. virtual ~TuningSpaceCollectionImpl() {
  58. m_mapTuningSpaces.clear();
  59. }
  60. STDMETHOD(get__NewEnum)(/*[out, retval]*/ IEnumVARIANT** ppVal) {
  61. try {
  62. if (ppVal == NULL) {
  63. return E_POINTER;
  64. }
  65. CComObject<TuningSpaceContainerEnum_t>* p;
  66. *ppVal = NULL;
  67. HRESULT hr = CComObject<TuningSpaceContainerEnum_t>::CreateInstance(&p);
  68. if (FAILED(hr) || !p) {
  69. return E_OUTOFMEMORY;
  70. }
  71. ATL_LOCKT();
  72. hr = p->Init(pT->GetUnknown(), m_mapTuningSpaces);
  73. if (FAILED(hr)) {
  74. delete p;
  75. return hr;
  76. }
  77. hr = p->QueryInterface(__uuidof(IEnumVARIANT), reinterpret_cast<LPVOID *>(ppVal));
  78. if (FAILED(hr)) {
  79. delete p;
  80. return hr;
  81. }
  82. return NOERROR;
  83. } catch(...) {
  84. return E_POINTER;
  85. }
  86. }
  87. STDMETHOD(get_EnumTuningSpaces)(/*[out, retval]*/ IEnumTuningSpaces** ppNewEnum) {
  88. if (!ppNewEnum) {
  89. return E_POINTER;
  90. }
  91. try {
  92. CComObject<TuningSpaceEnum_t>* p;
  93. *ppNewEnum = NULL;
  94. HRESULT hr = CComObject<TuningSpaceEnum_t>::CreateInstance(&p);
  95. if (FAILED(hr) || !p) {
  96. return E_OUTOFMEMORY;
  97. }
  98. ATL_LOCKT();
  99. hr = p->Init(pT->GetUnknown(), m_mapTuningSpaces);
  100. if (FAILED(hr)) {
  101. delete p;
  102. return hr;
  103. }
  104. hr = p->QueryInterface(__uuidof(IEnumTuningSpaces), (void**)ppNewEnum);
  105. if (FAILED(hr)) {
  106. delete p;
  107. return hr;
  108. }
  109. return NOERROR;
  110. } catch(...) {
  111. return E_UNEXPECTED;
  112. }
  113. }
  114. STDMETHOD(get_Count)(/*[out, retval]*/ long *plVal) {
  115. if (!plVal) {
  116. return E_POINTER;
  117. }
  118. try {
  119. ATL_LOCKT();
  120. *plVal = static_cast<long>(m_mapTuningSpaces.size());
  121. return NOERROR;
  122. } catch(...) {
  123. return E_POINTER;
  124. }
  125. }
  126. };
  127. }; // namespace
  128. // end of file - tuningspacecollectionimpl.h