GME
13
|
00001 #pragma once 00002 00003 #include <unordered_map> 00004 00005 struct CComBSTR_Length { 00006 ::std::size_t operator ()(const CComBSTR& bstr) const { 00007 return bstr.Length(); 00008 } 00009 }; 00010 00011 class ATL_NO_VTABLE CCoreDictionaryAttributeValue : 00012 public CComObjectRootEx<CComSingleThreadModel>, 00013 public IDispatchImpl<ICoreDictionaryAttributeValue, &IID_ICoreDictionaryAttributeValue, &LIBID_MGACoreLib> 00014 { 00015 public: 00016 CCoreDictionaryAttributeValue() {} 00017 ~CCoreDictionaryAttributeValue() {} 00018 00019 //DECLARE_REGISTRY_RESOURCEID(IDR_) 00020 //DECLARE_PROTECT_FINAL_CONSTRUCT() 00021 // DECLARE_INTERFACE 00022 00023 BEGIN_COM_MAP(CCoreDictionaryAttributeValue) 00024 COM_INTERFACE_ENTRY(ICoreDictionaryAttributeValue) 00025 COM_INTERFACE_ENTRY(IDispatch) 00026 END_COM_MAP() 00027 00028 public: 00029 STDMETHOD(put_Value)(BSTR Key, BSTR Value); 00030 STDMETHOD(get_Value)(BSTR Key, BSTR* Value); 00031 STDMETHOD(get_Keys)(VARIANT* Keys); 00032 STDMETHOD(get_Map)(VARIANT* Map) { 00033 Map->vt = VT_I8; 00034 Map->llVal = (size_t)(void*)&m_dict; 00035 return S_OK; 00036 } 00037 00038 STDMETHOD(put_Map)(VARIANT Map) { 00039 m_dict = std::move(*(map_type*)(void*)(size_t)Map.llVal); 00040 return S_OK; 00041 } 00042 00043 STDMETHOD(Clone)(ICoreDictionaryAttributeValue** Clone) 00044 { 00045 CCoreDictionaryAttributeValue* out; 00046 typedef CComObject< CCoreDictionaryAttributeValue > COMTYPE; 00047 HRESULT hr = COMTYPE::CreateInstance((COMTYPE **)&out); 00048 if (SUCCEEDED(hr)) 00049 { 00050 out->AddRef(); 00051 out->m_dict = this->m_dict; 00052 *Clone = out; 00053 } 00054 return hr; 00055 } 00056 00057 typedef std::unordered_map<CComBSTR, CComBSTR, CComBSTR_Length> map_type; 00058 map_type m_dict; 00059 }; 00060 00061 static void CopyTo(const VARIANT& from, CComPtr<CCoreDictionaryAttributeValue>& to) 00062 { 00063 if (from.vt == VT_DISPATCH) { 00064 to = 0; 00065 CComPtr<ICoreDictionaryAttributeValue> fro; 00066 COMTHROW(from.pdispVal->QueryInterface(&fro)); 00067 COMTHROW(fro->Clone((ICoreDictionaryAttributeValue**)&to)); 00068 } 00069 }