DSMPropertyBag.h

00001 #pragma once
00002 #include <atlsimpcoll.h>
00003 
00004 // IDSMPropertyBag
00005 
00006 [uuid("232FD5D2-4954-41E7-BF9B-09E1257B1A95")]
00007 interface IDSMPropertyBag : public IPropertyBag2
00008 {
00009         STDMETHOD(SetProperty) (LPCWSTR key, LPCWSTR value) = 0;
00010         STDMETHOD(SetProperty) (LPCWSTR key, VARIANT* var) = 0;
00011         STDMETHOD(GetProperty) (LPCWSTR key, BSTR* value) = 0;
00012         STDMETHOD(DelAllProperties) () = 0;
00013         STDMETHOD(DelProperty) (LPCWSTR key) = 0;
00014 };
00015 
00016 class IDSMPropertyBagImpl : public ATL::CSimpleMap<CStringW, CStringW>, public IDSMPropertyBag, public IPropertyBag
00017 {
00018         BOOL Add(const CStringW& key, const CStringW& val) {return __super::Add(key, val);}
00019         BOOL SetAt(const CStringW& key, const CStringW& val) {return __super::SetAt(key, val);}
00020 
00021 public:
00022         IDSMPropertyBagImpl();
00023         virtual ~IDSMPropertyBagImpl();
00024 
00025         // IPropertyBag
00026 
00027     STDMETHODIMP Read(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog);
00028     STDMETHODIMP Write(LPCOLESTR pszPropName, VARIANT* pVar);
00029 
00030         // IPropertyBag2
00031 
00032         STDMETHODIMP Read(ULONG cProperties, PROPBAG2* pPropBag, IErrorLog* pErrLog, VARIANT* pvarValue, HRESULT* phrError);
00033         STDMETHODIMP Write(ULONG cProperties, PROPBAG2* pPropBag, VARIANT* pvarValue);
00034         STDMETHODIMP CountProperties(ULONG* pcProperties);
00035         STDMETHODIMP GetPropertyInfo(ULONG iProperty, ULONG cProperties, PROPBAG2* pPropBag, ULONG* pcProperties);
00036         STDMETHODIMP LoadObject(LPCOLESTR pstrName, DWORD dwHint, IUnknown* pUnkObject, IErrorLog* pErrLog);
00037 
00038         // IDSMPropertyBag
00039 
00040         STDMETHODIMP SetProperty(LPCWSTR key, LPCWSTR value);
00041         STDMETHODIMP SetProperty(LPCWSTR key, VARIANT* var);
00042         STDMETHODIMP GetProperty(LPCWSTR key, BSTR* value);
00043         STDMETHODIMP DelAllProperties();
00044         STDMETHODIMP DelProperty(LPCWSTR key);
00045 };
00046 
00047 // IDSMResourceBag
00048 
00049 [uuid("EBAFBCBE-BDE0-489A-9789-05D5692E3A93")]
00050 interface IDSMResourceBag : public IUnknown
00051 {
00052         STDMETHOD_(DWORD, ResGetCount) () = 0;
00053         STDMETHOD(ResGet) (DWORD iIndex, BSTR* ppName, BSTR* ppDesc, BSTR* ppMime, BYTE** ppData, DWORD* pDataLen, DWORD_PTR* pTag) = 0;
00054         STDMETHOD(ResSet) (DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE* pData, DWORD len, DWORD_PTR tag) = 0;
00055         STDMETHOD(ResAppend) (LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE* pData, DWORD len, DWORD_PTR tag) = 0;
00056         STDMETHOD(ResRemoveAt) (DWORD iIndex) = 0;
00057         STDMETHOD(ResRemoveAll) (DWORD_PTR tag) = 0;
00058 };
00059 
00060 class CDSMResource
00061 {
00062 public:
00063         DWORD_PTR tag;
00064         CStringW name, desc, mime;
00065         CArray<BYTE> data;
00066         CDSMResource();
00067         CDSMResource(LPCWSTR name, LPCWSTR desc, LPCWSTR mime, BYTE* pData, int len, DWORD_PTR tag = 0);
00068         virtual ~CDSMResource();
00069         void operator = (const CDSMResource& r);
00070 
00071         // global access to all resources
00072         static CCritSec m_csResources;
00073         static CAtlMap<DWORD, CDSMResource*> m_resources;
00074 };
00075 
00076 class IDSMResourceBagImpl : public IDSMResourceBag
00077 {
00078 protected:
00079         CArray<CDSMResource> m_resources;
00080 
00081 public:
00082         IDSMResourceBagImpl();
00083 
00084         void operator += (const CDSMResource& r) {m_resources.Add(r);}
00085 
00086         // IDSMResourceBag
00087 
00088         STDMETHODIMP_(DWORD) ResGetCount();
00089         STDMETHODIMP ResGet(DWORD iIndex, BSTR* ppName, BSTR* ppDesc, BSTR* ppMime, BYTE** ppData, DWORD* pDataLen, DWORD_PTR* pTag = NULL);
00090         STDMETHODIMP ResSet(DWORD iIndex, LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE* pData, DWORD len, DWORD_PTR tag = 0);
00091         STDMETHODIMP ResAppend(LPCWSTR pName, LPCWSTR pDesc, LPCWSTR pMime, BYTE* pData, DWORD len, DWORD_PTR tag = 0);
00092         STDMETHODIMP ResRemoveAt(DWORD iIndex);
00093         STDMETHODIMP ResRemoveAll(DWORD_PTR tag = 0);
00094 };
00095 
00096 // IDSMChapterBag
00097 
00098 [uuid("2D0EBE73-BA82-4E90-859B-C7C48ED3650F")]
00099 interface IDSMChapterBag : public IUnknown
00100 {
00101         STDMETHOD_(DWORD, ChapGetCount) () = 0;
00102         STDMETHOD(ChapGet) (DWORD iIndex, REFERENCE_TIME* prt, BSTR* ppName) = 0;
00103         STDMETHOD(ChapSet) (DWORD iIndex, REFERENCE_TIME rt, LPCWSTR pName) = 0;
00104         STDMETHOD(ChapAppend) (REFERENCE_TIME rt, LPCWSTR pName) = 0;
00105         STDMETHOD(ChapRemoveAt) (DWORD iIndex) = 0;
00106         STDMETHOD(ChapRemoveAll) () = 0;
00107         STDMETHOD_(long, ChapLookup) (REFERENCE_TIME* prt, BSTR* ppName) = 0;
00108         STDMETHOD(ChapSort) () = 0;
00109 };
00110 
00111 class CDSMChapter
00112 {
00113 public:
00114         REFERENCE_TIME rt;
00115         CStringW name;
00116         CDSMChapter() {rt = 0;}
00117         CDSMChapter(REFERENCE_TIME rt, LPCWSTR name);
00118         void operator = (const CDSMChapter& c);
00119 };
00120 
00121 class IDSMChapterBagImpl : public IDSMChapterBag
00122 {
00123 protected:
00124         CArray<CDSMChapter> m_chapters;
00125         bool m_fSorted;
00126 
00127 public:
00128         IDSMChapterBagImpl();
00129 
00130         void operator += (const CDSMChapter& c) {m_chapters.Add(c); m_fSorted = false;}
00131 
00132         // IDSMChapterBag
00133 
00134         STDMETHODIMP_(DWORD) ChapGetCount();
00135         STDMETHODIMP ChapGet(DWORD iIndex, REFERENCE_TIME* prt, BSTR* ppName = NULL);
00136         STDMETHODIMP ChapSet(DWORD iIndex, REFERENCE_TIME rt, LPCWSTR pName);
00137         STDMETHODIMP ChapAppend(REFERENCE_TIME rt, LPCWSTR pName);
00138         STDMETHODIMP ChapRemoveAt(DWORD iIndex);
00139         STDMETHODIMP ChapRemoveAll();
00140         STDMETHODIMP_(long) ChapLookup(REFERENCE_TIME* prt, BSTR* ppName = NULL);
00141         STDMETHODIMP ChapSort();
00142 };
00143 
00144 class CDSMChapterBag : public CUnknown, public IDSMChapterBagImpl
00145 {
00146 public:
00147         CDSMChapterBag(LPUNKNOWN pUnk, HRESULT* phr);
00148 
00149         DECLARE_IUNKNOWN;
00150         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00151 };
00152 
00153 template<class T>
00154 int range_bsearch(const CArray<T>& array, REFERENCE_TIME rt)
00155 {
00156         int i = 0, j = array.GetCount() - 1, ret = -1;
00157         if(j >= 0 && rt >= array[j].rt) return j;
00158         while(i < j)
00159         {
00160                 int mid = (i + j) >> 1;
00161                 REFERENCE_TIME midrt = array[mid].rt;
00162                 if(rt == midrt) {ret = mid; break;}
00163                 else if(rt < midrt) {ret = -1; if(j == mid) mid--; j = mid;}
00164                 else if(rt > midrt) {ret = mid; if(i == mid) mid++; i = mid;}
00165         }
00166         return ret;
00167 }

Generated on Tue Dec 13 14:47:06 2005 for guliverkli by  doxygen 1.4.5