From 3f95d417d9e623ac0c74df8ef11d7a01846392dd Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 17 Sep 2003 19:07:23 +0000 Subject: Initial Import --- Common/ComponentData.h | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Common/ComponentData.h (limited to 'Common/ComponentData.h') diff --git a/Common/ComponentData.h b/Common/ComponentData.h new file mode 100644 index 0000000..75dcdbb --- /dev/null +++ b/Common/ComponentData.h @@ -0,0 +1,111 @@ +////////////////////////////////////////////////////////////////// +// CComponentData +// +// Exposes the IPropertyBag interface for the components to store +// their data in. +// +// Also supports other host specific settings. +// +// Current implementation saves the data in the registry and only +// saves when requested to by host. +// +// Component can pass a Variant NULL to delete the specified +// property +// +// Only the following types are supported for now: +// VT_UI1 +// VT_I2 +// VT_I4 +// VT_R4 +// VT_R8 +// VT_CY +// VT_BSTR +////////////////////////////////////////////////////////////////// + + +#if !defined(COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_) +#define COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_ + +#if _MSC_VER >= 1000 +#pragma once +#endif // _MSC_VER >= 1000 +// ComponentData.h : header file +// + +#define DATA_KEY _T("Data") + +#include "../common/interfaces.h" +#include +#include +using std::map; +using std::make_pair; + +#include + +typedef map string_variant_map; + +///////////////////////////////////////////////////////////////////////////// +// CComponentData command target +class ATL_NO_VTABLE CComponentData : + public CComObjectRootEx, + public IPropertyBag +{ + +// Attributes +public: + CComponentData(); + virtual ~CComponentData(); + + +public: + // Host specific functions + // Add String support later when needed. + bool WriteInt(const string& sKey, int nValue); + int GetInt(const string& sKey, int nDefault); + bool Delete(const string& sKey); + + // Can be used by Host and also called from the + // IPropertyBag Implementation below + HRESULT Write(const string& sValName, const VARIANT& varVal); + HRESULT Read(const string& sValName, VARIANT& varVal); + + // Initializes Key + HRESULT Initialize(const string& sKey); + + + // Saves All Setting to Registry Key + // If sKey = NULL then saves to key given in Initialize + HRESULT Save(string sKey = _T("")); + + + // Returns an IUnknown to IPropertyBag +// IUnknown* GetIUnknown(bool bAddRef = false); + + +protected: + + // Arrays of Settings to be written to Registry + // Supports Integers and Strings Only + string_variant_map m_mapValues; + + // Registry Key + string m_sKey; + +public: + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CComponentData) + COM_INTERFACE_ENTRY(IPropertyBag) +END_COM_MAP() + + // IPropertyBag Interface + STDMETHOD(Read)(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog); + STDMETHOD(Write)(LPCOLESTR pszPropName, VARIANT* pVar); + +}; + +///////////////////////////////////////////////////////////////////////////// + + +#endif // !defined(COMPONENTDATA_H__2AA70045_1988_11D2_B2D4_0020182B97FC__INCLUDED_) -- cgit v1.2.3