GME
13
|
00001 // MgaAttribute.h : Declaration of the CMgaAttribute 00002 00003 #ifndef __MGAATTRIBUTE_H_ 00004 #define __MGAATTRIBUTE_H_ 00005 00006 #include "resource.h" // main symbols 00007 00008 #include "MgaProject.h" 00009 #include "MgaFCO.h" 00010 00011 #include <unordered_map> 00012 00013 struct CComBSTR_Length { 00014 ::std::size_t operator ()(const CComBSTR& bstr) const { 00015 return bstr.Length(); 00016 } 00017 }; 00018 00019 void MgaRegNode_get_Value(CMgaProject* mgaproject, FCO * fco, CoreObj s, BSTR mypath, BSTR *pVal); 00020 00022 // CMgaAttribute 00023 class ATL_NO_VTABLE CMgaAttribute : 00024 public CComObjectRootEx<CComSingleThreadModel>, 00025 public CComCoClass<CMgaAttribute, &__uuidof(MgaAttribute)>, 00026 public IDispatchImpl<IMgaAttribute, &__uuidof(IMgaAttribute), &__uuidof(__MGALib)>, 00027 public ISupportErrorInfoImpl<&__uuidof(IMgaAttribute)> 00028 { 00029 public: 00030 CMgaAttribute() : prevptr(NULL), next(NULL), load_status(ATTSTATUS_INVALID) { } 00031 00032 DECLARE_PROTECT_FINAL_CONSTRUCT() 00033 00034 BEGIN_COM_MAP(CMgaAttribute) 00035 COM_INTERFACE_ENTRY(IMgaAttribute) 00036 COM_INTERFACE_ENTRY_IID(IID_ISupportErrorInfo, IMyErrorInfoBase) 00037 COM_INTERFACE_ENTRY(IDispatch) 00038 END_COM_MAP() 00039 00040 // IMgaAttribute 00041 public: 00042 STDMETHOD(get_Meta)( IMgaMetaAttribute **pVal) { 00043 COMTRY { 00044 CHECK_OUTPTRPAR(pVal); 00045 CComQIPtr<IMgaMetaAttribute> m(mgaproject->FindMetaRef(mref)); 00046 *pVal = m.Detach(); 00047 } COMCATCH(;) 00048 } 00049 STDMETHOD(get_Owner)( IMgaFCO **pVal); 00050 STDMETHOD(get_Status)( long *status); 00051 STDMETHOD(get_Value)( VARIANT *pVal); 00052 STDMETHOD(put_Value)( VARIANT newVal); 00053 00054 STDMETHOD(get_StringValue)(BSTR *pVal); 00055 STDMETHOD(put_StringValue)( BSTR newVal); 00056 STDMETHOD(get_OrigValue)( VARIANT *pVal); 00057 STDMETHOD(get_HasChanged)( VARIANT_BOOL *pVal); 00058 00059 STDMETHOD(get_IntValue)( long *pVal); 00060 STDMETHOD(put_IntValue)( long newVal); 00061 STDMETHOD(get_BoolValue)( VARIANT_BOOL *pVal); 00062 STDMETHOD(put_BoolValue)( VARIANT_BOOL newVal); 00063 STDMETHOD(get_FloatValue)( double *pVal); 00064 STDMETHOD(put_FloatValue)( double newVal); 00065 STDMETHOD(get_FCOValue)( IMgaFCO **pVal); 00066 STDMETHOD(put_FCOValue)( IMgaFCO * newVal); 00067 00068 STDMETHOD(get_RegistryNode)( BSTR path, IMgaRegNode **pVal); 00069 STDMETHOD(GetRegistryNodeDisp)( BSTR path, IMgaRegNode **pVal) { return get_RegistryNode( path, pVal); } 00070 STDMETHOD(get_Registry)(VARIANT_BOOL virtuals, IMgaRegNodes **pVal); 00071 STDMETHOD(GetRegistryDisp)(VARIANT_BOOL virtuals, IMgaRegNodes **pVal) { return get_Registry( virtuals, pVal); } 00072 STDMETHOD(get_RegistryValue)( BSTR path, BSTR *pVal); 00073 STDMETHOD(put_RegistryValue)( BSTR path, BSTR newval); 00074 STDMETHOD(GetRegistryValueDisp)( BSTR path, BSTR *pVal) { return get_RegistryValue( path, pVal); } 00075 STDMETHOD(SetRegistryValueDisp)( BSTR path, BSTR newval) { return put_RegistryValue( path, newval); } 00076 00077 STDMETHOD(Clear)(); 00078 00079 typedef CMgaAttribute *hashobp; 00080 hashobp *prevptr, next; 00081 ~CMgaAttribute() { // remove object from hash 00082 if (next) 00083 next->prevptr = prevptr; 00084 if (prevptr) 00085 *prevptr = next; 00086 } 00087 void Initialize(metaref_type mr, FCO *o, CMgaProject *p); // Throws!!! 00088 metaref_type mref; 00089 00090 long load_status; 00091 CoreObj valueobj; 00092 CComQIPtr<IMgaMetaAttribute> mvalueobj; 00093 FCOPtr fco; 00094 attval_enum attrtyp, inputtyp; 00095 CMgaProject *mgaproject; 00096 CComBSTR getregprefix() 00097 { 00098 CComQIPtr<IMgaMetaAttribute> meta = mgaproject->FindMetaRef(mref); 00099 CComBSTR _regprefix = L"AttrRegs/"; 00100 CComBSTR metaname; 00101 COMTHROW(meta->get_Name(&metaname)); 00102 COMTHROW(_regprefix.Append(metaname)); 00103 return _regprefix; 00104 } 00105 __declspec(property(get=getregprefix)) CComBSTR regprefix; 00106 }; 00107 00108 00109 #define APOOL_HASHSIZE 8 00110 #define apool_hash(x) ((x)%APOOL_HASHSIZE) 00111 00112 00113 class attrpool { 00114 CMgaAttribute::hashobp pool[APOOL_HASHSIZE]; 00115 public: 00116 attrpool() { 00117 int i; 00118 for(i = 0; i < APOOL_HASHSIZE;i++) pool[i] = NULL; 00119 } 00120 00121 ~attrpool() { 00122 int i; 00123 for(i = 0; i < APOOL_HASHSIZE;i++) ASSERT(pool[i] == NULL); 00124 } 00125 00126 // Throws (allocates)!!!! 00127 CComPtr<IMgaAttribute> getpoolobj(metaref_type mref, FCO *o, CMgaProject *pr) { 00128 CMgaAttribute::hashobp &k = pool[apool_hash(mref)], *kk; 00129 for(kk = &k; *kk != NULL; kk = &((*kk)->next)) { 00130 if((*kk)->mref == mref) { 00131 return (*kk); 00132 } 00133 } 00134 CComPtr<CMgaAttribute> s; 00135 CreateComObject(s); 00136 s->prevptr = &k; // Insert to the front 00137 s->next = k; 00138 if(k) k->prevptr = &(s->next); 00139 k = s; 00140 00141 s->Initialize(mref, o, pr); 00142 CComPtr<IMgaAttribute> retval = s; 00143 return retval; 00144 } 00145 00146 void clear() 00147 { 00148 for (size_t mref = 0; mref < sizeof(pool) / sizeof(pool[0]); mref++) 00149 { 00150 CMgaAttribute::hashobp *kk; 00151 for (kk = &pool[mref]; *kk != NULL; kk = &(*kk)->next) 00152 { 00153 if ((*(*kk)->prevptr)->next) 00154 (*(*kk)->prevptr)->next = NULL; 00155 (*kk)->load_status = ATTSTATUS_INVALID; 00156 (*kk)->prevptr = NULL; 00157 } 00158 pool[mref] = NULL; 00159 } 00160 } 00161 }; 00162 00163 void MergeAttrs(const CoreObj &src, CoreObj &dst); 00164 00165 00167 // CMgaRegNode 00168 class ATL_NO_VTABLE CMgaRegNode : 00169 public CComObjectRootEx<CComSingleThreadModel>, 00170 public CComCoClass<CMgaRegNode, &__uuidof(MgaRegNode)>, 00171 public IDispatchImpl<IMgaRegNode, &__uuidof(IMgaRegNode), &__uuidof(__MGALib)>, 00172 public ISupportErrorInfoImpl<&__uuidof(IMgaRegNode)> 00173 { 00174 public: 00175 00176 DECLARE_PROTECT_FINAL_CONSTRUCT() 00177 00178 BEGIN_COM_MAP(CMgaRegNode) 00179 COM_INTERFACE_ENTRY(IMgaRegNode) 00180 COM_INTERFACE_ENTRY_IID(IID_ISupportErrorInfo, IMyErrorInfoBase) 00181 COM_INTERFACE_ENTRY(IDispatch) 00182 END_COM_MAP() 00183 00184 // IMgaRegNode 00185 void markchg(); 00186 public: 00187 STDMETHOD(get_Name)(BSTR *pVal) { 00188 COMTRY { 00189 CHECK_OUTPAR(pVal); 00190 LPCOLESTR p = (mypath == NULL ? NULL : wcsrchr(mypath, '/')); 00191 if (p) p += 1; // skip '/' 00192 else p = mypath; 00193 CComBSTR rval(p); 00194 *pVal = rval.Detach(); 00195 } COMCATCH(;); 00196 }; 00197 STDMETHOD(get_Path)( BSTR *pVal) { 00198 COMTRY { 00199 CHECK_OUTPAR(pVal); 00200 *pVal = mypath.Copy(); 00201 } COMCATCH(;); 00202 }; 00203 STDMETHOD(get_Object)( IMgaObject **pVal); 00204 STDMETHOD(get_Value)( BSTR *pVal); 00205 STDMETHOD(put_Value)( BSTR newVal); 00206 STDMETHOD(get_FCOValue)( IMgaFCO **pVal); 00207 STDMETHOD(put_FCOValue)( IMgaFCO *newVal); 00208 STDMETHOD(get_SubNodes)( VARIANT_BOOL virtuals, IMgaRegNodes **pVal); 00209 STDMETHOD(GetSubNodesDisp)( VARIANT_BOOL virtuals, IMgaRegNodes **pVal) { return get_SubNodes( virtuals, pVal); } 00210 STDMETHOD(get_SubNodeByName)(BSTR name, IMgaRegNode **pVal); 00211 STDMETHOD(GetSubNodeByNameDisp)(BSTR name, IMgaRegNode **pVal) { return get_SubNodeByName( name, pVal); } 00212 STDMETHOD(get_ParentNode)( IMgaRegNode **pVal); 00213 00214 STDMETHOD(get_Status)( long *status); 00215 STDMETHOD(get_Opacity)( VARIANT_BOOL *pVal); 00216 STDMETHOD(put_Opacity)( VARIANT_BOOL newVal); 00217 STDMETHOD(Clear)(); 00218 STDMETHOD(RemoveTree)(); 00219 00220 CMgaRegNode() { } 00221 ~CMgaRegNode() { } 00222 00223 void Initialize(BSTR path, FCO *o, CMgaProject* mgaproject) { 00224 mypath = path; 00225 fco = o; 00226 this->mgaproject = mgaproject; 00227 } 00228 00229 template<class F> 00230 void WalkKeyValues(CoreObj& obj, F& f, long status, bool& continue_); 00231 00232 template<class F> 00233 void WalkKeyValuesInher(F& f); 00234 00235 void SetValue(const wchar_t* path, const wchar_t* value); 00236 const static wchar_t* NULL_SENTINEL; 00237 00238 FCOPtr fco; 00239 CComBSTR mypath; 00240 CMgaProject* mgaproject; 00241 00242 typedef std::unordered_map<CComBSTR, CComBSTR, CComBSTR_Length> map_type; 00243 }; 00244 00245 00246 void MergeRegs(const CoreObj &src, CoreObj &dst); 00247 00248 00249 00251 // CMgaPart 00253 00254 class ATL_NO_VTABLE CMgaPart : 00255 public CComObjectRootEx<CComSingleThreadModel>, 00256 public CComCoClass<CMgaPart, &__uuidof(MgaPart)>, 00257 public IDispatchImpl<IMgaPart, &__uuidof(IMgaPart), &__uuidof(__MGALib)>, 00258 public ISupportErrorInfoImpl<&__uuidof(IMgaPart)> 00259 { 00260 public: 00261 00262 DECLARE_PROTECT_FINAL_CONSTRUCT() 00263 00264 BEGIN_COM_MAP(CMgaPart) 00265 COM_INTERFACE_ENTRY(IMgaPart) 00266 COM_INTERFACE_ENTRY(IDispatch) 00267 COM_INTERFACE_ENTRY_IID(IID_ISupportErrorInfo, IMyErrorInfoBase) 00268 END_COM_MAP() 00269 00270 // IMgaPart 00271 public: 00272 STDMETHOD(get_Model)(struct IMgaModel **pVal ); 00273 STDMETHOD(get_Meta)(struct IMgaMetaPart **pVal ); 00274 STDMETHOD(get_MetaAspect)(struct IMgaMetaAspect **pVal ); 00275 STDMETHOD(get_MetaRole)(struct IMgaMetaRole **pVal ); 00276 STDMETHOD(get_FCO)(struct IMgaFCO **pVal); 00277 STDMETHOD(get_AccessMask)(long *); 00278 00279 STDMETHOD(GetGmeAttrs)(BSTR *icon,long *x,long *y); 00280 STDMETHOD(SetGmeAttrs)(BSTR icon,long x,long y); 00281 00282 STDMETHOD(get_RegistryMode)( VARIANT_BOOL *own); 00283 STDMETHOD(put_RegistryMode)( VARIANT_BOOL own); 00284 00285 STDMETHOD(get_RegistryNode)( BSTR path, IMgaRegNode **pVal); 00286 STDMETHOD(GetRegistryNodeDisp)( BSTR path, IMgaRegNode **pVal) { return get_RegistryNode( path, pVal); } 00287 STDMETHOD(get_Registry)( VARIANT_BOOL virtuals, IMgaRegNodes **pVal); 00288 STDMETHOD(GetRegistryDisp)( VARIANT_BOOL virtuals, IMgaRegNodes **pVal) { return get_Registry( virtuals, pVal); } 00289 STDMETHOD(get_RegistryValue)( BSTR path, BSTR *pVal); 00290 STDMETHOD(put_RegistryValue)( BSTR path, BSTR newval); 00291 STDMETHOD(GetRegistryValueDisp)( BSTR path, BSTR *pVal) { return get_RegistryValue( path, pVal); } 00292 STDMETHOD(SetRegistryValueDisp)( BSTR path, BSTR newval) { return put_RegistryValue( path, newval); } 00293 CMgaPart(); 00294 ~CMgaPart(); 00295 void Initialize(metaref_type mr, ::FCO *o, CMgaProject *p); 00296 typedef CMgaPart *hashobp; 00297 hashobp *prevptr, next; 00298 metaref_type mref; 00299 00300 long load_status; 00301 FCOPtr fco; 00302 CMgaProject *mgaproject; // Holds no reference 00303 CComBSTR getregprefix() 00304 { 00305 CComPtr<IMgaMetaAspect> meta; 00306 COMTHROW(get_MetaAspect(&meta)); 00307 CComBSTR aspname; 00308 COMTHROW(meta->get_Name(&aspname)); 00309 CComBSTR _regprefix = L"PartRegs/"; 00310 COMTHROW(_regprefix.Append(aspname)); 00311 return _regprefix; 00312 } 00313 __declspec(property(get=getregprefix)) CComBSTR regprefix; 00314 }; 00315 00316 00317 00318 #define PPOOL_HASHSIZE 4 00319 #define ppool_hash(x) ((x)%PPOOL_HASHSIZE) 00320 00321 00322 class partpool { 00323 CMgaPart::hashobp pool[PPOOL_HASHSIZE]; 00324 public: 00325 partpool() { 00326 int i; 00327 for(i = 0; i < PPOOL_HASHSIZE;i++) pool[i] = NULL; 00328 } 00329 00330 ~partpool() { 00331 int i; 00332 for(i = 0; i < PPOOL_HASHSIZE;i++) ASSERT(pool[i] == NULL); 00333 } 00334 00335 // Throws (allocates)!!!! 00336 CComPtr<IMgaPart> getpoolobj(metaref_type mref, FCO *o, CMgaProject *pr) { 00337 CMgaPart::hashobp &k = pool[ppool_hash(mref)], *kk; 00338 for(kk = &k; *kk != NULL; kk = &((*kk)->next)) { 00339 if((*kk)->mref == mref) { 00340 return (*kk); 00341 } 00342 } 00343 CComPtr<CMgaPart > s; 00344 CreateComObject(s); 00345 s->prevptr = &k; // Insert to the front 00346 s->next = k; 00347 if(k) k->prevptr = &(s->next); 00348 k = s; 00349 00350 s->Initialize(mref, o, pr); 00351 CComPtr<IMgaPart> retval = s; 00352 return retval; 00353 } 00354 }; 00355 00356 #endif //__MGAATTRIBUTE_H_