GME  13
MgaFCO.h
Go to the documentation of this file.
00001 // MgaFCO.h : Declaration of the CMgaFCO
00002 
00003 #ifndef __MGAFCO_H_
00004 #define __MGAFCO_H_
00005 
00006 #include "resource.h"       // main symbols
00007 #include "MgaAttribute.h"
00008 
00009 // IMgaFCOIMPL
00010 
00011 #define IMgaContainer IMgaObject
00012 
00013 #define RELIDSPACE (RELID_BASE_MAX+1L)
00014 #define RELIDSPACE_OVERFLOWED (RELID_VALUE_MAX+1UL)
00015 
00016 // ----------------------------------------
00017 // Generic template used in CMgaModel, CMgaAtom, CMgaFolder etc.
00018 // most methods just dispatch to the corresponding method in the inFCO object
00019 // ----------------------------------------
00020 template <class T1, class T2>
00021 class ATL_NO_VTABLE IMgaFCOImpl : public T1, public T2 {
00022 protected:
00023  friend class FCO;
00024 #ifdef _ATL_DEBUG_INTERFACES
00025  friend CComPtr<FCO> ObjFor(IMgaObject *s);
00026 #else
00027  friend FCO *ObjFor(IMgaObject *s);
00028 #endif
00029  DEFSIG;
00030 #ifdef DEBUG
00031 // in DEBUG, inFCO is transformed to a macro, which checks territory compatibility
00032  CComPtr<FCO> innFCO;
00033 #define inFCO  (tcheck() ,innFCO)
00034  void tcheck() { ASSERT(("You are working with an object from another territory, may ignore",\
00035                                                         territory == innFCO->mgaproject->activeterr)); }
00036 #else
00037  CComPtr<FCO> inFCO;
00038 #define innFCO inFCO
00039 #endif
00040  CComPtr<CMgaTerritory> territory;
00041  CComVariant userdata;
00042 public:
00043 
00044         IMgaFCOImpl()  {        
00045                 INITSIG('I'); 
00046 #ifdef DEBUG
00047                 MGA_TRACE("Constructed: %s - %08X\n", sig, this);
00048 #endif
00049         }
00050  void Initialize(CMgaTerritory *terr, FCO *fco) {
00051          MARKSIG('1');
00052          ASSERT(terr);
00053          ASSERT(fco);
00054          innFCO = fco;
00055          territory = terr;
00056          innFCO->pubfcos.insert(FCO::pubfcohash::value_type(terr, reinterpret_cast<CMgaAtom*>(this)));
00057  }
00058  
00059 
00060 
00061  ~IMgaFCOImpl () { 
00062 #ifdef DEBUG
00063          MGA_TRACE("Destructed: %s - %08X\n", sig, this);
00064 #endif
00065          MARKSIG('9');
00066 
00067          FCO::pubfcohash::iterator ii = innFCO->pubfcos.find(territory);
00068          ASSERT(ii != innFCO->pubfcos.end());
00069          innFCO->pubfcos.erase(ii);
00070 #ifdef DEBUG
00071          ii = innFCO->pubfcos.find(territory);
00072          ASSERT(ii == innFCO->pubfcos.end());
00073 #endif
00074  }
00075 
00076 // methods dispatched to FCO     
00077  STDMETHOD(get_ID)( ID_type *pVal)                                      { return inFCO->get_ID(pVal); }
00078  STDMETHOD(get_RelID)( long *pVal)                                      { return inFCO->get_RelID(pVal); }
00079  STDMETHOD(put_RelID)( long newVal)                                     { return inFCO->put_RelID(newVal); }
00080  STDMETHOD(get_Name)( BSTR *pVal)                                       { return inFCO->get_Name(pVal); }
00081  STDMETHOD(put_Name)( BSTR newVal)                                      { return inFCO->put_Name(newVal); }
00082  //by ZolMol
00083  STDMETHOD(get_AbsPath)( BSTR *pVal)                            { return inFCO->get_AbsPath(pVal); }
00084  STDMETHOD(get_Meta)( IMgaMetaFCO **pVal)                       { return inFCO->get_Meta(pVal); }
00085  //by ZolMol
00086  //STDMETHOD(get_FolderMeta)( IMgaMetaFolder **pVal)            { return inFCO->get_Meta(pVal); }
00087 
00088  STDMETHOD(get_ParentModel)( IMgaModel **pVal)          { return inFCO->get_ParentModel(pVal); }
00089  STDMETHOD(get_ParentFolder)( IMgaFolder **pVal)                { return inFCO->get_ParentFolder(pVal); }
00090  STDMETHOD(get_MetaBase)( IMgaMetaBase **pVal)          { return inFCO->get_MetaBase(pVal); }
00091  STDMETHOD(get_MetaRef)( metaref_type *pVal)            { return inFCO->get_MetaRef(pVal); }
00092  STDMETHOD(get_ObjType)( objtype_enum *pVal)            { return inFCO->get_ObjType(pVal); }
00093  STDMETHOD(GetAbsMetaPath)(BSTR *abspath)                       { return inFCO->GetAbsMetaPath(abspath); }
00094  STDMETHOD(GetRelMetaPath)(IMgaFCO *begfco, BSTR *relpath, IMgaFCOs *refs)
00095                                                                                                         { return inFCO->GetRelMetaPath(begfco, relpath, refs); }
00096  STDMETHOD(get_Project)(IMgaProject **pVal)         { return innFCO->get_Project(pVal); }
00097  STDMETHOD(CheckProject)( IMgaProject *project)     { return innFCO->CheckProject(project); }
00098  STDMETHOD(SendEvent)(long mask)                                        { return innFCO->SendEvent(mask); }
00099  STDMETHOD(get_IsLibObject)( VARIANT_BOOL *pVal)        { return inFCO->get_IsLibObject(pVal); }
00100 
00101  STDMETHOD(get_Territory)(IMgaTerritory **pVal)         {   COMTRY {
00102                                                                                                                         CHECK_OUTPTRPAR(pVal);
00103                                                                                                                         CMgaTerritory *p;
00104                                                                                                                         territory.CopyTo(&p);
00105                                                                                                                         *pVal = p;
00106                                                                                                                 } COMCATCH(;)
00107                                                                                                         }
00108  STDMETHOD(get_IsEqual)(IMgaObject *o, VARIANT_BOOL *pVal) { return inFCO->get_IsEqual(o, pVal); }
00109  STDMETHOD(GetIsEqualDisp)(IMgaObject *o, VARIANT_BOOL *pVal) { return inFCO->get_IsEqual(o, pVal); }
00110  
00111  STDMETHOD(DestroyObject)()                                                     { return inFCO->DeleteObject(); }
00112  STDMETHOD(get_Status) (long *p)                                        { return inFCO->get_Status(p); }
00113  STDMETHOD(get_IsWritable) (VARIANT_BOOL *p)            { return inFCO->get_IsWritable(p); }
00114                  
00115  STDMETHOD(Open)( openmode mode)                                        { return inFCO->Open(mode); }
00116  STDMETHOD(Close)()                                                                     { return inFCO->Close(); }
00117 
00118  STDMETHOD(Associate)( VARIANT ud)                      { userdata= ud; return S_OK; }
00119  STDMETHOD(get_CurrentAssociation)( VARIANT *udp)  { 
00120                                                                                                                 COMTRY {
00121                                                                                                                         CHECK_OUTPAR(udp);
00122                                                                                                                         COMTHROW(VariantCopy(udp, &userdata)); 
00123                                                                                                                 } COMCATCH(;)
00124                                                                                                         }
00125  STDMETHOD(GetParent)( IMgaContainer **pVal,  objtype_enum *l)  { return inFCO->GetParent(pVal,l); }
00126 
00127 
00128  STDMETHOD(Check)() { return inFCO->Check(); }
00129  STDMETHOD(CheckTree)() { return inFCO->CheckTree(); }
00130  STDMETHOD(put_Exempt)(VARIANT_BOOL newVal) { return inFCO->put_Exempt(newVal); }
00131  STDMETHOD(get_Exempt)(VARIANT_BOOL *pVal) { return inFCO->get_Exempt(pVal); }
00132 
00133  STDMETHOD(PutReadOnlyAccessWithPropagate)( VARIANT_BOOL pReadOnly)
00134                                                                 { return inFCO->PutReadOnlyAccessWithPropagate( pReadOnly); }
00135  STDMETHOD(PutReadOnlyAccess)( VARIANT_BOOL pReadOnly)
00136                                                                 { return inFCO->PutReadOnlyAccess( pReadOnly); }
00137  STDMETHOD(HasReadOnlyAccess)( VARIANT_BOOL *pReadOnly)
00138                                                                 { return inFCO->HasReadOnlyAccess( pReadOnly); }
00139 
00140  STDMETHOD(GetGuid)( long* l1, long* l2, long* l3, long* l4)
00141                                                                 { return inFCO->GetGuid( l1, l2, l3, l4); }
00142  STDMETHOD(PutGuid)( long l1, long l2, long l3, long l4)
00143                                                                 { return inFCO->PutGuid( l1, l2, l3, l4); }
00144  STDMETHOD(GetGuidDisp)( BSTR *guid_str)
00145                                                                 { return inFCO->GetGuidDisp( guid_str); }
00146  STDMETHOD(PutGuidDisp)( BSTR guid_str)
00147                                                                 { return inFCO->PutGuidDisp( guid_str); }
00148 
00149  STDMETHOD(get_ChildObjects)(IMgaObjects **pVal) 
00150                                                                 { return inFCO->get_ChildObjects(pVal); }
00151  STDMETHOD(get_ChildObjectByRelID)(long relid, IMgaObject **pVal) 
00152                                                                 { return inFCO->get_ChildObjectByRelID(relid ,pVal); }
00153  STDMETHOD(GetChildObjectByRelIDDisp)(long relid, IMgaObject **pVal) 
00154                                                                 { return inFCO->get_ChildObjectByRelID(relid ,pVal); }
00155  STDMETHOD(get_ObjectByPath)(BSTR path, IMgaObject **pVal) 
00156                                                                 { return inFCO->get_ObjectByPath(path, pVal); }
00157  STDMETHOD(get_NthObjectByPath)(long n_th, BSTR path, IMgaObject **pVal) 
00158                                                                 { return inFCO->get_NthObjectByPath(n_th, path, pVal); }
00159  STDMETHOD(GetObjectByPathDisp)(BSTR path, IMgaObject **pVal) 
00160                                                                 { return inFCO->get_ObjectByPath(path, pVal); }
00161  STDMETHOD(GetNthObjectByPathDisp)(long n_th, BSTR path, IMgaObject **pVal) 
00162                                                                 { return inFCO->get_NthObjectByPath(n_th, path, pVal); }
00163  
00164  STDMETHOD(get_MetaRole)( IMgaMetaRole **pVal)          { return inFCO->get_MetaRole(pVal); }
00165 
00166 
00167  STDMETHOD(get_Parts)( IMgaParts **pVal)                        { return inFCO->get_Parts(pVal); }
00168  STDMETHOD(get_Part)( IMgaMetaAspect * asp,  IMgaPart **pVal)  { return inFCO->get_Part(asp, pVal); }
00169  STDMETHOD(GetPartDisp) ( IMgaMetaAspect * asp,  IMgaPart **pVal)  { return inFCO->get_Part(asp, pVal); }
00170  STDMETHOD(get_PartByMetaPart)( IMgaMetaPart *p,  IMgaPart **pVal)  { return inFCO->get_PartByMP(p, pVal); }
00171  STDMETHOD(GetPartByMetaPartDisp)( IMgaMetaPart *p,  IMgaPart **pVal)  { return inFCO->get_PartByMP(p, pVal); }
00172  STDMETHOD(get_Attributes)( IMgaAttributes **pVal)  { return inFCO->get_Attributes(pVal); }
00173  STDMETHOD(get_Attribute)( IMgaMetaAttribute *meta,  IMgaAttribute **pVal)  
00174                                                                                                         { return inFCO->get_Attribute(meta,pVal); }
00175  STDMETHOD(GetAttributeDisp)( IMgaMetaAttribute *meta,  IMgaAttribute **pVal)  
00176                                                                                                         { return inFCO->get_Attribute(meta,pVal); }
00177  STDMETHOD(get_AttributeByName)( BSTR name,  VARIANT *pVal) { return inFCO->get_AttributeByName(name, pVal); }
00178  STDMETHOD(put_AttributeByName)( BSTR name,  VARIANT newval) { return inFCO->put_AttributeByName( name, newval); }
00179  STDMETHOD(GetAttributeByNameDisp)( BSTR name,  VARIANT *pVal) { return inFCO->get_AttributeByName(name, pVal); }
00180  STDMETHOD(SetAttributeByNameDisp)( BSTR name,  VARIANT newval) { return inFCO->put_AttributeByName( name, newval); }
00181  STDMETHOD(get_StrAttrByName)( BSTR name,  BSTR *pVal)  { return inFCO->get_StrAttrByName(name, pVal); }
00182  STDMETHOD(put_StrAttrByName)( BSTR name,  BSTR newval)  { return inFCO->put_StrAttrByName(name, newval); }
00183  STDMETHOD(GetStrAttrByNameDisp)( BSTR name,  BSTR *pVal)  { return inFCO->get_StrAttrByName(name, pVal); }
00184  STDMETHOD(SetStrAttrByNameDisp)( BSTR name,  BSTR newval)  { return inFCO->put_StrAttrByName(name, newval); }
00185  STDMETHOD(get_IntAttrByName)( BSTR name,  long *pVal)  { return inFCO->get_IntAttrByName(name, pVal); }
00186  STDMETHOD(put_IntAttrByName)( BSTR name,  long newval)  { return inFCO->put_IntAttrByName(name, newval); }
00187  STDMETHOD(GetIntAttrByNameDisp)( BSTR name,  long *pVal)  { return inFCO->get_IntAttrByName(name, pVal); }
00188  STDMETHOD(SetIntAttrByNameDisp)( BSTR name,  long newval)  { return inFCO->put_IntAttrByName(name, newval); }
00189  STDMETHOD(get_FloatAttrByName)( BSTR name,  double *pVal)  { return inFCO->get_FloatAttrByName(name, pVal); }
00190  STDMETHOD(put_FloatAttrByName)( BSTR name,  double newval)  { return inFCO->put_FloatAttrByName(name, newval); }
00191  STDMETHOD(GetFloatAttrByNameDisp)( BSTR name,  double *pVal)  { return inFCO->get_FloatAttrByName(name, pVal); }
00192  STDMETHOD(SetFloatAttrByNameDisp)( BSTR name,  double newval)  { return inFCO->put_FloatAttrByName(name, newval); }
00193  STDMETHOD(get_BoolAttrByName)( BSTR name,  VARIANT_BOOL *pVal)  { return inFCO->get_BoolAttrByName(name, pVal); }
00194  STDMETHOD(put_BoolAttrByName)( BSTR name,  VARIANT_BOOL newval)  { return inFCO->put_BoolAttrByName(name, newval); }
00195  STDMETHOD(GetBoolAttrByNameDisp)( BSTR name,  VARIANT_BOOL *pVal)  { return inFCO->get_BoolAttrByName(name, pVal); }
00196  STDMETHOD(SetBoolAttrByNameDisp)( BSTR name,  VARIANT_BOOL newval)  { return inFCO->put_BoolAttrByName(name, newval); }
00197  STDMETHOD(get_RefAttrByName)( BSTR name,  IMgaFCO **pVal)  { return inFCO->get_RefAttrByName(name, pVal); }
00198  STDMETHOD(put_RefAttrByName)( BSTR name,  IMgaFCO * newval)  { return inFCO->put_RefAttrByName(name, newval); }
00199  STDMETHOD(GetRefAttrByNameDisp)( BSTR name,  IMgaFCO **pVal)  { return inFCO->get_RefAttrByName(name, pVal); }
00200  STDMETHOD(SetRefAttrByNameDisp)( BSTR name,  IMgaFCO * newval)  { return inFCO->put_RefAttrByName(name, newval); }
00201  STDMETHOD(ClearAttrByName)( BSTR name)                 { return inFCO->ClearAttrByName(name); }
00202 
00203  STDMETHOD(get_RegistryNode)( BSTR path,  IMgaRegNode **pVal)  { return inFCO->get_RegistryNode(path, pVal); }
00204  STDMETHOD(GetRegistryNodeDisp)( BSTR path,  IMgaRegNode **pVal)  { return inFCO->get_RegistryNode(path, pVal); }
00205  STDMETHOD(get_Registry)(VARIANT_BOOL virtuals, IMgaRegNodes **pVal)            { return inFCO->get_Registry (virtuals, pVal); }
00206  STDMETHOD(GetRegistryDisp)(VARIANT_BOOL virtuals, IMgaRegNodes **pVal)         { return inFCO->get_Registry (virtuals, pVal); }
00207  STDMETHOD(get_RegistryValue)( BSTR path,  BSTR *pVal)  { return inFCO->get_RegistryValue(path, pVal); }
00208  STDMETHOD(put_RegistryValue)( BSTR path,  BSTR newval)  { return inFCO->put_RegistryValue(path, newval); }
00209  STDMETHOD(GetRegistryValueDisp)( BSTR path,  BSTR *pVal)  { return inFCO->get_RegistryValue(path, pVal); }
00210  STDMETHOD(SetRegistryValueDisp)( BSTR path,  BSTR newval)  { return inFCO->put_RegistryValue(path, newval); }
00211 
00212  STDMETHOD(get_Constraints)( VARIANT_BOOL includemeta, IMgaConstraints **pVal)  
00213                                                                                                         { return inFCO->get_Constraints (includemeta, pVal); }
00214  STDMETHOD(GetConstraintsDisp)( VARIANT_BOOL includemeta, IMgaConstraints **pVal)  
00215                                                                                                         { return inFCO->get_Constraints (includemeta, pVal); }
00216  STDMETHOD(AddConstraint)( IMgaConstraint *pVal)  { return inFCO->AddConstraint (pVal); }
00217  STDMETHOD(DefineConstraint)(BSTR name, long mask, BSTR expr, IMgaConstraint **nc)
00218                                                                                                         { return inFCO->DefineConstraint (name, mask, expr, nc); }
00219 
00220  STDMETHOD(CreateCollection)( IMgaFCOs **pVal) { return inFCO->CreateCollection(pVal); } 
00221  STDMETHOD(GetBaseType)(IMgaFCO ** basetype, IMgaFCO ** immbase, VARIANT_BOOL *isinst) {
00222                                                 return inFCO->GetBaseType(basetype, immbase, isinst); }
00223  STDMETHOD(get_DerivedFrom)( IMgaFCO **pVal)            { return inFCO->get_DerivedFrom( pVal); }
00224  STDMETHOD(get_Type)( IMgaFCO **pVal)                   { return inFCO->get_Type( pVal); }
00225  STDMETHOD(get_BaseType)( IMgaFCO **pVal)               { return inFCO->get_BaseType( pVal); }
00226  STDMETHOD(get_ArcheType)( IMgaFCO **pVal)              { return inFCO->get_ArcheType( pVal); }
00227  STDMETHOD(get_IsInstance)( VARIANT_BOOL *pVal) { return inFCO->get_IsInstance( pVal); }
00228  STDMETHOD(get_IsPrimaryDerived)( VARIANT_BOOL *pVal)   { return inFCO->get_IsPrimaryDerived( pVal); }
00229  STDMETHOD(get_DerivedObjects)( IMgaFCOs **pVal) { return inFCO->get_DerivedObjects( pVal); }
00230  STDMETHOD(AttachToArcheType)( IMgaFCO *newtype,  VARIANT_BOOL instance) { 
00231                                                                                                         return inFCO->AttachToArcheType(newtype,instance); }
00232  STDMETHOD(DetachFromArcheType)()                               { return inFCO->DetachFromArcheType (); }
00233  STDMETHOD(get_RootFCO)(IMgaFCO **pVal)                 { return inFCO->get_RootParent(pVal); }
00234 
00235  STDMETHOD(get_PartOfConns)(IMgaConnPoints **pVal)      { return inFCO->get_PartOfConns(pVal); }
00236  STDMETHOD(get_MemberOfSets)(IMgaFCOs **pVal)   { return inFCO->get_MemberOfSets(pVal); }
00237  STDMETHOD(get_ReferencedBy)(IMgaFCOs **pVal)   { return inFCO->get_ReferencedBy(pVal); }
00238 
00239 
00240 };
00241 
00242 // ----------------------------------------
00243 // MgaAtom is defined here (it is empty)
00244 // ----------------------------------------
00245 class ATL_NO_VTABLE CMgaAtom : 
00246         public CComCoClass<CMgaAtom, &__uuidof(MgaAtom)>,
00247         public IMgaFCOImpl< 
00248                 CComObjectRootEx<CComSingleThreadModel>,
00249                 IDispatchImpl<IMgaAtom, &__uuidof(IMgaAtom), &__uuidof(__MGALib)> >,
00250         public ISupportErrorInfoImpl<&__uuidof(IMgaAtom)>
00251 {
00252 public:
00253         CMgaAtom()      {}
00254 
00255 
00256 DECLARE_PROTECT_FINAL_CONSTRUCT()
00257 
00258 BEGIN_COM_MAP(CMgaAtom)
00259         COM_INTERFACE_ENTRY(IMgaAtom)
00260         COM_INTERFACE_ENTRY_IID(__uuidof(IMgaObject),IMgaAtom)
00261         COM_INTERFACE_ENTRY_IID(__uuidof(IMgaFCO),IMgaAtom)
00262         COM_INTERFACE_ENTRY(IDispatch)
00263         COM_INTERFACE_ENTRY_IID(IID_ISupportErrorInfo, IMyErrorInfoBase)
00264 END_COM_MAP()
00265 public:
00266 };
00267 
00268 
00269 
00270 
00271 // ----------------------------------------
00272 // FCO
00273 // ----------------------------------------
00274 struct terr_hashfunc : public stdext::hash_compare<IMgaTerritory *> 
00275 {
00276         size_t operator()(const IMgaTerritory *p_ob) const
00277         {
00278                 return reinterpret_cast<size_t>( p_ob) % 5;//return (((int)p_ob) % 5);// 64 bt
00279         }
00280         bool operator()(const IMgaTerritory *p_ob1, const IMgaTerritory *p_ob2) const 
00281         {
00282                 return p_ob1 < p_ob2;
00283         }
00284 };
00285 
00286 struct cp_hashfunc : public stdext::hash_compare<objid_type> 
00287 {
00288         size_t operator()(const objid_type p_ob) const
00289         {
00290                 return (((int)p_ob) % 5);
00291         }
00292         bool operator()(const objid_type p_ob1, const objid_type p_ob2) const 
00293         {
00294                 return p_ob1 < p_ob2;
00295         }
00296 };
00297 
00298 
00299 class CMgaConnPoint;
00300 class CMgaConstraint;
00301 
00302 class ATL_NO_VTABLE FCO : 
00303         public CComObjectRootEx<CComSingleThreadModel>,
00304         public CComCoClass<FCO, &__uuidof(MgaO)>,
00305         public IDispatchImpl<IMgaO, &__uuidof(IMgaO), &__uuidof(__MGALib)>
00306 {
00307 public:
00308         DEFSIG;
00309    
00310 DECLARE_REGISTRY_RESOURCEID(IDR_MGAO)
00311 
00312 DECLARE_PROTECT_FINAL_CONSTRUCT()
00313 
00314 BEGIN_COM_MAP(FCO)
00315         COM_INTERFACE_ENTRY(IMgaO)
00316         COM_INTERFACE_ENTRY(IDispatch)
00317 END_COM_MAP()
00318 
00319 
00320         STDMETHOD(FinalConstruct)();
00321 
00322 private:
00323 //Notification
00324         unsigned long changemask, notifymask, temporalmask;
00325 
00326 // PreDelete Notification by Tihamer for the PAMS SynchTool
00327         void PreDeleteNotify();
00328 
00329 public:
00330         class NoAddRefCoreObj : public CoreObj {        // CoreObj, but non-addref/release-ing
00331         public:
00332                 void operator=(CoreObj &p) { Attach(p); } 
00333            ~NoAddRefCoreObj() { Detach(); }
00334         }  self;
00335 
00336         typedef stdext::hash_map<CMgaTerritory*, CMgaAtom*, terr_hashfunc> pubfcohash;
00337         pubfcohash pubfcos;
00338         CComPtr<CMgaProject> mgaproject;
00339         bool simpleconn();
00340         partpool ppool;
00341         attrpool apool;
00342         typedef stdext::hash_map<objid_type, CMgaConnPoint *, cp_hashfunc> cphash;
00343         cphash connpointhash;
00344         typedef stdext::hash_map<objid_type, CMgaConstraint *, cp_hashfunc> cshash;
00345         cshash constrainthash;
00346 
00347         FCO();
00348         ~FCO();
00349 //      void AddRef(void);
00350 //      void Release(void);
00351 
00352         // these THROW
00353         long getstatus();
00354         void CheckRead();
00355         void CheckDeletedRead();
00356         void CheckWrite();
00357 
00358         HRESULT get_Project(IMgaProject **pVal);
00359         HRESULT CheckProject(IMgaProject *project);
00360         HRESULT get_IsEqual(IMgaObject *o, VARIANT_BOOL *pVal);
00361         HRESULT get_ID(ID_type *pVal);
00362         HRESULT get_RelID(long *pVal);
00363         HRESULT put_RelID(long newVal);
00364 
00365         HRESULT get_IsLibObject(VARIANT_BOOL *pVal);
00366 
00367         HRESULT get_Meta(IMgaMetaFCO **pVal);
00368         HRESULT get_ParentModel(IMgaModel **pVal);
00369         HRESULT get_ParentFolder(IMgaFolder **pVal);
00370         HRESULT get_MetaBase(IMgaMetaBase **pVal);
00371         HRESULT get_MetaRef(metaref_type *pVal);
00372         HRESULT get_Name(BSTR *pVal);
00373                 void initialname();  // add inital name to object
00374         HRESULT put_Name(BSTR newVal);
00375         HRESULT get_AbsPath(BSTR *pVal);
00376         HRESULT get_Status(long *p);
00377         HRESULT get_IsWritable(VARIANT_BOOL *p);
00378         HRESULT get_ObjType(objtype_enum *pVal);
00379         HRESULT GetParent(IMgaContainer **pVal, objtype_enum *l = NULL);
00380         HRESULT GetAbsMetaPath(BSTR *abspath);
00381         HRESULT GetRelMetaPath(IMgaFCO *begfco, BSTR *relpath, IMgaFCOs *refs);
00382 
00383         HRESULT get_MetaRole( IMgaMetaRole **pVal);
00384         HRESULT Check();
00385         HRESULT CheckTree();
00386 
00387         // check the relations in refs, conns and sets
00388                 void CheckRCS();
00389                 // Get a list of basetypes this object is derived from
00390                 HRESULT FCO::get_AllBaseTypes(IMgaFCOs **bases);
00391                 // Get root parent of object
00392                 HRESULT FCO::get_RootParent(IMgaFCO **parent, long *distance = NULL);
00393                 // Get all parents starting from root (does not contain the object itself) 
00394                 HRESULT FCO::get_ParentChain(IMgaFCOs **parents);
00395                 // check if object is a child or any grandchild of parentobject (also true if itself)
00396                 bool FCO::IsDescendantOf(IMgaFCO *rootobject, long *distance = NULL);
00397 
00398 
00399         HRESULT put_Exempt(VARIANT_BOOL newVal);
00400         HRESULT get_Exempt(VARIANT_BOOL *pVal);
00401         HRESULT PutReadOnlyAccessWithPropagate( VARIANT_BOOL pReadOnly);
00402         HRESULT PutReadOnlyAccess( VARIANT_BOOL pReadOnly);
00403         HRESULT HasReadOnlyAccess( VARIANT_BOOL *pReadOnly);
00404 
00405         HRESULT GetGuid( long* l1, long* l2, long* l3, long* l4);
00406         HRESULT PutGuid( long l1, long l2, long l3, long l4);
00407         HRESULT GetGuidDisp( BSTR *guid_str);
00408         HRESULT PutGuidDisp( BSTR guid_str);
00409 
00410         HRESULT get_ChildObjects(IMgaObjects **pVal);
00411         HRESULT get_ChildObjectByRelID(long relid, IMgaObject **pVal); 
00412         HRESULT get_ObjectByPath(BSTR path, IMgaObject **pVal);
00413         HRESULT get_NthObjectByPath(long n_th, BSTR path, IMgaObject **pVal);
00414 
00415 
00416         void assignnewchild(CoreObj &ss);
00417         void newrelidforchildren(CoreObj &ss);
00418 
00419         void inDeleteObject();
00420         HRESULT DeleteObject();
00421 
00422         HRESULT Open ( openmode mode = OPEN_READ);
00423         HRESULT Close ();
00424 
00425         HRESULT SendEvent(long mask);
00426 
00427 //      HRESULT Associate(VARIANT userdata);
00428 //      HRESULT get_CurrentAssociation(VARIANT *userdata);
00429         
00430         // FOLDER
00431     HRESULT get_ChildFolders(IMgaFolders **pVal);
00432         HRESULT CreateFolder(IMgaMetaFolder *meta, IMgaFolder **nf);
00433         HRESULT CreateRootObject(IMgaMetaFCO *meta, IMgaFCO **nobj);
00434         HRESULT get_MetaFolder(IMgaMetaFolder **pVal);
00435         // by ZolMol
00436         HRESULT CopyFolders(IMgaFolders *copylist, IMgaFolders **objs);
00437         HRESULT MoveFolders(IMgaFolders *copylist, IMgaFolders **objs);
00438         HRESULT CopyFolderDisp(IMgaFolder *copyfold, IMgaFolder **nobj);
00439         HRESULT MoveFolderDisp(IMgaFolder *movefold, IMgaFolder **nobj);
00440         HRESULT RefreshParent( IMgaFolder * f);
00441         
00442 
00443         // MODEL
00444         HRESULT CreateChildObject( IMgaMetaRole *role, IMgaFCO **newobj);
00445         HRESULT CreateReference( IMgaMetaRole *meta,  IMgaFCO *target,  IMgaFCO **newobj);
00446         HRESULT get_AspectParts( IMgaMetaAspect * asp, unsigned int filter, IMgaParts **pVal);
00447         HRESULT CreateSimpleConn( IMgaMetaRole *metar,  IMgaFCO *src,  IMgaFCO *dst, 
00448                                                                         IMgaFCOs *srcrefs, IMgaFCOs *dstrefs, IMgaFCO **newobj);
00449         HRESULT CreateSimpleConnDisp( IMgaMetaRole *metar,  IMgaFCO *src,  IMgaFCO *dst, 
00450                                                                         IMgaFCO *srcref, IMgaFCO *dstref, IMgaFCO **newobj);
00451 
00452 // FOLDER & MODEL
00453         HRESULT ContainerCreateFCO(IMgaMetaFCO *meta, CoreObj &FCO);
00454         HRESULT GetChildrenOfKind(BSTR kn, IMgaFCOs **pVal);
00455         HRESULT GetDescendantFCOs(IMgaFilter* filt, IMgaFCOs **pVal); 
00456         HRESULT get_ChildFCOs(IMgaFCOs ** pVal);
00457         HRESULT get_ChildFCO(BSTR n,IMgaFCO**pVal);
00458         HRESULT CopyFCOs(IMgaFCOs *copylist, IMgaMetaRoles *rlist, IMgaFCOs **objs);
00459         HRESULT MoveFCOs(IMgaFCOs *copylist, IMgaMetaRoles *rlist, IMgaFCOs **objs);
00460         HRESULT CopyFCODisp(IMgaFCO *obj, IMgaMetaRole *role, IMgaFCO **nobj);
00461         HRESULT MoveFCODisp(IMgaFCO *obj, IMgaMetaRole *role, IMgaFCO **nobj);
00462         HRESULT DeriveFCO(IMgaFCO *base, IMgaMetaRole *role, VARIANT_BOOL instance, IMgaFCO** newobj);
00463         HRESULT AddInternalConnections(IMgaFCOs *inobjs, IMgaFCOs **objs);
00464 
00465         // CONNECTION
00466         static const CComBSTR SrcName, DstName;
00467         HRESULT get_NamedRoleTarget(BSTR rolename, IMgaFCO **pVal);
00468         HRESULT get_NamedRoleReferences(BSTR rolename, IMgaFCOs **pVal);
00469         HRESULT put_NamedRole(BSTR rolename, IMgaFCOs *rs, IMgaFCO * newVal);
00470                 bool findroleobj(BSTR rolename, CoreObj &tt);
00471         HRESULT AddConnPoint(BSTR rolename, long maxinrole, IMgaFCO *target, IMgaFCOs *refs, IMgaConnPoint **pVal);
00472         HRESULT get_ConnPoints(IMgaConnPoints **pVal);
00473 
00474 
00475         // REFERENCE
00476         HRESULT get_Referred(IMgaFCO **pVal);
00477         HRESULT put_Referred(IMgaFCO * newVal);
00478         HRESULT get_RefAspect(IMgaMetaAspect **pVal);
00479         HRESULT put_RefAspect(IMgaMetaAspect * newVal);
00480         HRESULT get_UsedByConns(IMgaConnPoints **pVal);
00481 
00482         // SET
00483         HRESULT RemoveMember(IMgaFCO *member);
00484         HRESULT SetRemoveAll();
00485         HRESULT AddMember(IMgaFCO *member);
00486         HRESULT get_Members(IMgaFCOs * *pVal);
00487         HRESULT get_IsMember(IMgaFCO *obj, VARIANT_BOOL *pVal);
00488 
00489 
00490         // ALL
00491         HRESULT CreateCollection(IMgaFCOs **pVal);
00492         HRESULT get_Constraints(VARIANT_BOOL includemeta, IMgaConstraints **pVal);
00493         HRESULT CheckConstraints(long,int *,unsigned short ** );
00494         HRESULT AddConstraint(struct IMgaConstraint *p);
00495         HRESULT DefineConstraint(BSTR name, long eventmask, BSTR expression, IMgaConstraint **nconstraint);
00496 
00497         HRESULT GetBaseType(IMgaFCO **basetype, IMgaFCO ** immbase, VARIANT_BOOL *isinst);
00498         HRESULT get_DerivedFrom( IMgaFCO **pVal);
00499         HRESULT get_Type( IMgaFCO **pVal);
00500         HRESULT get_BaseType( IMgaFCO **pVal);
00501         HRESULT get_ArcheType( IMgaFCO **pVal);
00502         HRESULT get_IsInstance( VARIANT_BOOL *pVal);
00503         HRESULT get_IsPrimaryDerived( VARIANT_BOOL *pVal);
00504         HRESULT get_DerivedObjects( IMgaFCOs **pVal);
00505         HRESULT get_ChildDerivedFrom(IMgaFCO *baseobj, IMgaFCO **pVal);
00506         HRESULT DetachFromArcheType();
00507         HRESULT AttachToArcheType( IMgaFCO *newtype,  VARIANT_BOOL instance);
00508 
00509         HRESULT RefCompareToBase(short *status);                                
00510         HRESULT RefRevertToBase();                                                              
00511         HRESULT SetCompareToBase(IMgaFCO *p, short *status);                            
00512         HRESULT SetRevertToBase(IMgaFCO *p);                                                            
00513         HRESULT ConnCompareToBase(IMgaConnPoint *p, short *status);                             
00514         HRESULT ConnRevertToBase(IMgaConnPoint *p);                                                             
00515 
00516         HRESULT get_Parts(struct IMgaParts ** pVal);
00517         HRESULT get_Part(IMgaMetaAspect * asp, IMgaPart **pVal);
00518         HRESULT get_PartByMP(IMgaMetaPart *part, IMgaPart **pVal);
00519         HRESULT get_Attributes(IMgaAttributes **pVal);
00520         HRESULT get_Attribute(IMgaMetaAttribute *metaa,  IMgaAttribute **pVal);
00521 
00522         HRESULT get_PartOfConns(IMgaConnPoints **pVal);
00523         HRESULT get_MemberOfSets(IMgaFCOs **pVal);
00524         HRESULT get_ReferencedBy(IMgaFCOs **pVal);
00525         
00526         // THROWS!!
00527         CComPtr<IMgaAttribute> AbyN(BSTR name);
00528                         CComPtr<IMgaMetaAttribute> metaattr;
00529         HRESULT get_AttributeByName(BSTR name, VARIANT *pVal);
00530         HRESULT put_AttributeByName(BSTR name, VARIANT newVal);
00531         HRESULT get_StrAttrByName( BSTR name,  BSTR *pVal);
00532         HRESULT put_StrAttrByName( BSTR name,  BSTR newVal);
00533         HRESULT get_IntAttrByName( BSTR name,  long *pVal);
00534         HRESULT put_IntAttrByName( BSTR name,  long newVal);
00535         HRESULT get_FloatAttrByName( BSTR name,  double *pVal);
00536         HRESULT put_FloatAttrByName( BSTR name,  double newVal);
00537         HRESULT get_BoolAttrByName( BSTR name,  VARIANT_BOOL *pVal);
00538         HRESULT put_BoolAttrByName( BSTR name,  VARIANT_BOOL newVal);
00539         HRESULT get_RefAttrByName( BSTR name,  IMgaFCO **pVal);
00540         HRESULT put_RefAttrByName( BSTR name,  IMgaFCO * newVal);
00541         HRESULT ClearAttrByName( BSTR name);
00542         HRESULT get_RegistryNode( BSTR path,  IMgaRegNode **pVal);
00543         HRESULT get_Registry( VARIANT_BOOL virtuals, IMgaRegNodes **pVal);
00544         HRESULT get_RegistryValue( BSTR path,  BSTR *pVal);
00545         HRESULT put_RegistryValue( BSTR path,  BSTR newval);
00546 
00547         HRESULT ChangeObject(IMgaMetaRole *r, IMgaMetaFCO *kind);
00548 
00549         // Library
00550         HRESULT doAttach(  BSTR libname, VARIANT_BOOL ungroup, IMgaFolder **nf);
00551         HRESULT doRefresh( BSTR libname, VARIANT_BOOL ungroup, long *numOfErrors);
00552         HRESULT AttachLibraryV3(BSTR libname, VARIANT_BOOL ungrouped, IMgaFolder **nf);
00553         HRESULT RefreshLibraryV3(BSTR libname, VARIANT_BOOL ungrouped, long *numOfErrors);
00554 
00555         HRESULT AttachLibrary(BSTR libname, IMgaFolder **nf);
00556         HRESULT RefreshLibrary(BSTR libname);
00557         HRESULT get_LibraryName(BSTR *libname);
00558         HRESULT put_LibraryName(BSTR libname);
00559 
00560         HRESULT GetVirtuallyIncludedBy( IMgaFolders** pDep);
00561         HRESULT SetVirtuallyIncludedBy( IMgaFolders*  pDep);
00562         HRESULT GetVirtuallyIncludes  ( IMgaFolders** pDep);
00563         HRESULT SetVirtuallyIncludes  ( IMgaFolders*  pDep);
00564 
00565         // Source control
00566         HRESULT GetSourceControlInfo( long* scInfo);
00567 
00568         void prepareDepInfo2Coll( CComBSTR& pInfo, IMgaFolders** p_resultColl);
00569         void prepareColl2DepInfo( IMgaFolders* pDep, CComBSTR& pResInfo);
00570 
00571         HRESULT get_ChildRelIDCounter(long *pVal);
00572         HRESULT put_ChildRelIDCounter(long pVal);
00573 
00574         void objsetuserdata(CMgaTerritory *t, VARIANT udata);
00575 
00576         void ObjMark(IMgaObject *s, long mask) { mgaproject->ObjMark(s, mask); }
00577         HRESULT objrwnotify();
00578         void objforgetrwnotify() { changemask = 0; };
00579         HRESULT objnotify();
00580         void objforgetnotify() { notifymask = 0; };
00581         void SelfMark(long newmask);  // not unsigned long, to avoid warnings
00582         void objrecordchange();
00583         void objforgetchange();
00584         void removeterrfromlist(CMgaTerritory *t);
00585 
00586         // lph: notification service for precursory object events (used by PRE_DESTROYED and PRE_STATUS)
00587         HRESULT PreNotify(unsigned long changemask, CComVariant param);
00588 
00589         template <class Q>
00590         void getinterface(Q **p, CMgaTerritory *terr = NULL) {
00591                 CComPtr<IMgaObject> zz;
00592                 getinterface(&zz, terr);
00593 #if defined(DEBUG) || defined(_ATL_DEBUG_INTERFACES)
00594                 CComQIPtr<Q> pp = zz;
00595                 *p = pp.Detach();
00596 #else
00597                 * reinterpret_cast<IMgaObject **>(p) = zz.Detach();             
00598 #endif
00599         }
00600 
00601         template <> // specialization for the template method above
00602         void getinterface<IMgaObject>(IMgaObject **p, CMgaTerritory *terr);
00603 
00604         //template <> //gives internal compiler error
00605         void getinterface(IMgaObject **p) // shorthand for the method above
00606         { 
00607                 getinterface<IMgaObject>(p, (CMgaTerritory *) NULL);
00608         }
00609 };
00610 
00611 class DeriveTreeTask  {
00612 protected:
00613         int peercnt, internalpeercnt;
00614         int endreserve;   // the number of 'reserved' coreobjs at the end of the vector
00615         attrid_type masterattr;
00616 private:
00617         std::vector<int> peerdepths;
00618         int selfdepth;
00619         virtual bool Do(CoreObj self, std::vector<CoreObj> *peers = NULL) = 0;
00620         void _DoWithDeriveds(CoreObj self, std::vector<CoreObj> *peers = NULL);
00621 public:
00622         DeriveTreeTask() : endreserve(0), masterattr(0) { };
00623         void DoWithDeriveds(CoreObj self, std::vector<CoreObj> *peers = NULL);
00624 };
00625 
00626 class put_NameTask : public DeriveTreeTask {
00627         CComBSTR oldname, newname;
00628 
00629         bool Do(CoreObj self, std::vector<CoreObj> *peers = NULL);
00630 public:
00631         put_NameTask(BSTR oname, BSTR nname);
00632 };
00633 
00634 
00635 
00636 #ifdef _ATL_DEBUG_INTERFACES
00637 bool IsQIThunk(IUnknown *p);
00638 
00639 inline FCOPtr ObjForCore(ICoreObject *s) {
00640 #else
00641 inline FCO *ObjForCore(ICoreObject *s) {
00642 #endif
00643                 CComQIPtr<IMgaO> p = s;
00644                 if(!p) COMTHROW(E_MGA_MODULE_INCOMPATIBILITY);
00645 #ifdef _ATL_DEBUG_INTERFACES
00646                 IUnknown* pUnk = ((ATL::_QIThunk *)(p.p))->m_pUnk;
00647                 while (IsQIThunk(pUnk))
00648                         pUnk = ((ATL::_QIThunk *)(pUnk))->m_pUnk;
00649                 return (FCO*)((ATL::CComContainedObject<FCO>*)pUnk);
00650 #else
00651                 return (FCO *)(p.p);
00652 #endif
00653 }
00654 
00655 #ifdef _ATL_DEBUG_INTERFACES
00656 inline CComPtr<FCO> ObjFor(IMgaObject *s) {
00657         IUnknown* pUnk = ((ATL::_QIThunk *)(s))->m_pUnk;
00658         return ((CMgaAtom*)pUnk)->innFCO;
00659 }
00660 #else
00661 inline FCO *ObjFor(IMgaObject *s) {
00662                 return (static_cast<CMgaAtom *>(s)->innFCO);
00663 }
00664 #endif
00665 
00666 void CoreObjMark(CoreObj const &o, long mask);
00667 
00668 
00669 
00670 
00671 struct CComBSTR_hashfunc : public stdext::hash_compare<CComBSTR> 
00672 {
00673         size_t operator()(const CComBSTR &p_ob) const
00674         {
00675                 size_t c = 0;
00676                 for(unsigned int i = 0; i < p_ob.Length(); i+= 3) c += p_ob[i];
00677                 return c;
00678         }
00679         bool operator()(const CComBSTR &p_ob1, const CComBSTR &p_ob2) const
00680         {
00681                 return p_ob1 < p_ob2;
00682         }
00683 };
00684 
00685 struct metaref_hashfunc : public stdext::hash_compare<metaref_type>
00686 {
00687         size_t operator()(const metaref_type &p_ob) const
00688         {
00689                 return p_ob;
00690         }
00691         bool operator()(const metaref_type &p_ob1, const metaref_type &p_ob2) const
00692         {
00693                 return p_ob1 < p_ob2;
00694         }
00695 };
00696 
00697  
00698 /* *******************  setcheck / docheck ******************************* */
00699 
00700 #define CHK_NONE 0
00701 #define CHK_NEW  1
00702 #define CHK_CHANGED 3
00703 #define CHK_DELETED 4
00704 #define CHK_MOVED 7
00705 #define CHK_ILLEGAL 8
00706 
00707 #define CHK_REFEREES 4
00708 #define CHK_REFCONNS 2
00709 #define CHK_SELF 1
00710 
00711 
00712 void setcheck(CMgaProject *mgaproject, CoreObj &ob, int code);
00713 void docheck(CMgaProject *mgaproject);
00714 void ObjTreeNotify(CMgaProject *mgaproject, CoreObj &self);
00715 
00716 
00717 
00718 void ReDeriveNewObj(CMgaProject *mgaproject, CoreObj &orignobj, int targetlevel);
00719 void ObjTreeDerive(CMgaProject *mgaproject, const CoreObj &origobj, CoreObj &newobj, coreobjpairhash &crealist, long instance);
00720 bool ObjTreeReconnect(CoreObj self, coreobjpairhash &crealist, CoreObj const &derivtgt = NULLCOREOBJ);
00721 void ObjDetachAndMerge( CMgaProject *mgaproject, CoreObj orig, CoreObj &nobj, coreobjpairhash& crealist, unsigned long nextrelid, bool prim);
00722 void ObjAttach(CMgaProject *mgaproject, const CoreObj &origobj, CoreObj &newobj, coreobjpairhash &crealist, long instance, bool prim);
00723 
00724 
00725 /* ******************* CollectionEx *************************************** */
00726 
00727 typedef CCoreCollectionEx<IMgaFCOs, std::vector<IMgaFCO*>, IMgaFCO, IMgaFCO, &__uuidof(MgaFCOs), IDR_MGAFCOS> CMgaFCOs;
00728 typedef CCoreCollectionEx<IMgaFolders, std::vector<IMgaFolder*>, IMgaFolder, IMgaFolder, &__uuidof(MgaFolders), IDR_MGAFOLDERS> CMgaFolders;
00729 typedef CCoreCollectionEx<IMgaObjects, std::vector<IMgaObject*>, IMgaObject, IMgaObject, &__uuidof(MgaObjects), IDR_MGAOBJECTS> CMgaObjects;
00730 typedef CCoreCollectionEx<IMgaRegNodes, std::vector<IMgaRegNode*>, IMgaRegNode, IMgaRegNode, &__uuidof(MgaRegNodes), IDR_MGAREGNODES> CMgaRegNodes;
00731 #define CREATEEXCOLLECTION_FOR(x, q) CComPtr<C##x##s> q; CreateComObject(q);
00732 #define EXCOLLECTIONTYPE_FOR(x) C##x##s 
00733 #endif //__MGAFCO_H_
00734 
00735 void CheckColl(IMgaProject *p, IMgaFCOs *f);