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.

138 lines
3.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////
  2. // RGSBag.h : Declaration of the CRGSBag
  3. // Copyright (c) Microsoft Corporation 2000.
  4. //
  5. // small internal class to provide readonly IPropertyBag access to a string containing
  6. // an atl .rgs fragment
  7. #ifndef __RGSBAG_H_
  8. #define __RGSBAG_H_
  9. #pragma once
  10. #include <objectwithsiteimplsec.h>
  11. #include <propertybag2impl.h>
  12. namespace BDATuningModel {
  13. using ::ATL::ATL::CRegObject;
  14. using ::ATL::ATL::CRegParser;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CRGSBag
  17. class ATL_NO_VTABLE DECLSPEC_UUID("7B3CAA7B-5E78-4797-95F7-BDA2FCD807A2") CRGSBagBase :
  18. public CComObjectRootEx<CComMultiThreadModel>,
  19. public CComCoClass<CRGSBagBase, &__uuidof(CRGSBagBase)>,
  20. public IObjectWithSiteImplSec<CRGSBagBase>,
  21. public IPropertyBag2Impl<CRGSBagBase>,
  22. public IPropertyBag
  23. {
  24. public:
  25. CRGSBagBase() {}
  26. virtual ~CRGSBagBase() {
  27. m_mapBag.clear();
  28. }
  29. DECLARE_NOT_AGGREGATABLE(CRGSBagBase)
  30. DECLARE_PROTECT_FINAL_CONSTRUCT()
  31. BEGIN_COM_MAP(CRGSBagBase)
  32. COM_INTERFACE_ENTRY(IPropertyBag2)
  33. COM_INTERFACE_ENTRY(IPropertyBag)
  34. COM_INTERFACE_ENTRY(IObjectWithSite)
  35. END_COM_MAP_WITH_FTM()
  36. // IPropertyBag2
  37. public:
  38. // IPropertyBag
  39. STDMETHOD(Read)(LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog *pErrorLog) {
  40. if (!pVar) {
  41. return E_POINTER;
  42. }
  43. try {
  44. CString csKey(pszPropName);
  45. ATL_LOCK();
  46. RGSBag_t::iterator i = m_mapBag.find(csKey);
  47. if (i == m_mapBag.end()) {
  48. return HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY);
  49. }
  50. return (*i).second.CopyTo(pVar);
  51. } CATCHALL();
  52. }
  53. STDMETHOD(Write)(LPCOLESTR pszPropName, VARIANT *pVar) {
  54. return E_NOTIMPL;
  55. }
  56. // IPropertyBag2
  57. STDMETHOD(CountProperties)(ULONG * pcProperties) {
  58. if (!pcProperties) {
  59. return E_POINTER;
  60. }
  61. try {
  62. ATL_LOCK();
  63. *pcProperties = m_mapBag.size();
  64. return NOERROR;
  65. } CATCHALL();
  66. }
  67. STDMETHOD(GetPropertyInfo)(ULONG iProperty, ULONG cProperties, PROPBAG2 * pPropBag, ULONG * pcProperties) {
  68. return E_NOTIMPL;
  69. }
  70. STDMETHOD(LoadObject)(LPCOLESTR pstrName, ULONG dwHint, IUnknown * pUnkObject, IErrorLog * pErrLog) {
  71. return E_NOTIMPL;
  72. }
  73. protected:
  74. typedef std::map<CString, CComVariant> RGSBag_t; // id->object mapping, id's not contiguous
  75. RGSBag_t m_mapBag;
  76. };
  77. class CRGSBag : public CComObject<CRGSBagBase>,
  78. public CRegParser
  79. {
  80. public:
  81. CRGSBag(LPCTSTR szRGS, CRegObject& croi, int& cchEaten); // parse string into map
  82. HRESULT BuildMapFromFragment(LPTSTR pszToken);
  83. HRESULT GetObject(CComVariant& val);
  84. HRESULT GetValue(CComVariant &val);
  85. };
  86. template<class BAGTYPE, class PERSISTTYPE> HRESULT LoadPersistedObject(PUnknown& pobj, CRegObject& cro, TCHAR** ppchCur) {
  87. HRESULT hr = NOERROR;
  88. try {
  89. PERSISTTYPE pPersistObj(pobj);
  90. if (!pPersistObj) {
  91. return E_NOINTERFACE;
  92. }
  93. hr = pPersistObj->InitNew();
  94. if (FAILED(hr) && hr != E_NOTIMPL) {
  95. return hr;
  96. }
  97. int cchEaten = 0;
  98. BAGTYPE pBag(new CRGSBag(*ppchCur, cro, cchEaten));
  99. if (!pBag) {
  100. return E_OUTOFMEMORY;
  101. }
  102. *ppchCur += cchEaten;
  103. hr = pPersistObj->Load(pBag, NULL);
  104. if (FAILED(hr)) {
  105. delete pBag;
  106. return hr;
  107. }
  108. return hr;
  109. } CATCHALL();
  110. };
  111. }; // namespace
  112. #endif //__RGSBAG_H_