GME  13
CoreProject.h
Go to the documentation of this file.
00001 
00002 #ifndef MGA_COREPROJECT_H
00003 #define MGA_COREPROJECT_H
00004 
00005 #include <list>
00006 //#include <slist>
00007 #include <hash_map>
00008 #include "CommonVersionInfo.h"
00009 
00010 class CCoreProject;
00011 class CCoreObject;
00012 class CCoreTransactionItem;
00013 class CCoreFinalTrItem;
00014 class CCoreUndoItem;
00015 class CCoreTerritory;
00016 class CCoreMetaProject;
00017 
00018 
00019 #define MAX_UNDO_STEP                   10
00020 
00021 // --------------------------- typedefs
00022 
00023 typedef CCoreTransactionItem *transaction_item_type;
00024 typedef core::forward_list<transaction_item_type> transaction_items_type;
00025 typedef transaction_items_type::iterator transaction_items_iterator;
00026 
00027 typedef struct transaction_type
00028 {
00029         transaction_items_type items;
00030         bool readonly;
00031 } transaction_type;
00032 
00033 typedef core::list<transaction_type> transactions_type;
00034 typedef transactions_type::iterator transactions_iterator;
00035 
00036 typedef CCoreFinalTrItem *finaltr_item_type;
00037 typedef core::forward_list<finaltr_item_type> finaltr_items_type;
00038 typedef finaltr_items_type::iterator finaltr_items_iterator;
00039 
00040 typedef CCoreUndoItem *undo_item_type;
00041 typedef core::list<undo_item_type> undo_items_type;
00042 typedef undo_items_type::iterator undo_items_iterator;
00043 
00044 typedef undo_items_type undo_type;
00045 typedef core::list<undo_type> undos_type;
00046 typedef undos_type::iterator undos_iterator;
00047 
00048 typedef core::hash_map< metaobjidpair_type
00049                         , CCoreObject*
00050                         , metaobjid2pair_hashfunc
00051                         > object_lookup_type;
00052 typedef object_lookup_type::iterator object_lookup_iterator;
00053 
00054 typedef core::list< CComObjPtr<CCoreTerritory> > pushed_territorys_type;
00055 typedef core::list<CCoreTerritory*> created_territorys_type;
00056 
00057 // --------------------------- CCoreProject
00058 
00059 class ATL_NO_VTABLE CCoreProject : 
00060         public CComObjectRootEx<CComSingleThreadModel>,
00061         public CComCoClass<CCoreProject, &__uuidof(CoreProject)>,
00062         public IDispatchImpl<ICoreProject, &__uuidof(ICoreProject), &__uuidof(__MGACoreLib)>,
00063         public ISupportErrorInfoImpl<&__uuidof(ICoreProject)>,
00064         public IGMEVersionInfoImpl
00065 {
00066 public:
00067         CCoreProject();
00068         ~CCoreProject();
00069 
00070 DECLARE_REGISTRY_RESOURCEID(IDR_COREPROJECT)
00071 DECLARE_PROTECT_FINAL_CONSTRUCT()
00072 
00073 BEGIN_COM_MAP(CCoreProject)
00074         COM_INTERFACE_ENTRY(ICoreProject)
00075         COM_INTERFACE_ENTRY(IDispatch)
00076         COM_INTERFACE_ENTRY(ISupportErrorInfo)
00077         COM_INTERFACE_ENTRY_IID(__uuidof(IGMEVersionInfo), IGMEVersionInfoImpl)
00078 END_COM_MAP()
00079 
00080 // ------- COM methods
00081 
00082 public:
00083         STDMETHOD(put_Storage)(ICoreStorage *p);
00084         STDMETHOD(get_Storage)(ICoreStorage **p);
00085         STDMETHOD(get_MetaProject)(ICoreMetaProject **p);
00086 
00087         STDMETHOD(OpenProject)(BSTR connection, ICoreMetaProject *p, VARIANT_BOOL *ro_mode = NULL);
00088         STDMETHOD(CloseProject)(VARIANT_BOOL abort = VARIANT_FALSE);
00089         STDMETHOD(SaveProject)(BSTR connection = NULL, VARIANT_BOOL keepoldname = VARIANT_FALSE);
00090         STDMETHOD(CreateProject)(BSTR connection, ICoreMetaProject *p);
00091         STDMETHOD(DeleteProject)(BSTR connection);
00092         // undosize
00093         STDMETHOD(OpenProject2)(BSTR connection, long pUndoSize, ICoreMetaProject *p, VARIANT_BOOL *ro_mode = NULL);
00094         STDMETHOD(CreateProject2)(BSTR connection, long pUndoSize, ICoreMetaProject *p);
00095 
00096         STDMETHOD(get_Object)(metaid_type metaid, objid_type objid, ICoreObject **p);
00097         STDMETHOD(GetObjectDisp)(metaid_type metaid, objid_type objid, ICoreObject **p) { return get_Object( metaid, objid, p); }
00098         STDMETHOD(CreateObject)(metaid_type metaid, ICoreObject **p);
00099         STDMETHOD(get_RootObject)(ICoreObject **p);
00100 
00101         STDMETHOD(BeginTransaction)(transtype_enum transtype);
00102         STDMETHOD(CommitTransaction)(transtype_enum transtype);
00103         STDMETHOD(AbortTransaction)(transtype_enum transtype);
00104 
00105         STDMETHOD(get_NestedTransactionCount)(short *p);
00106 
00107         STDMETHOD(UndoTransaction)();
00108         STDMETHOD(RedoTransaction)();
00109         STDMETHOD(FlushUndoQueue)();
00110         STDMETHOD(FlushRedoQueue)();
00111         STDMETHOD(get_UndoQueueSize)(short *p);
00112         STDMETHOD(get_RedoQueueSize)(short *p);
00113 
00114         STDMETHOD(CreateTerritory)(ICoreTerritory **p);
00115         STDMETHOD(PushTerritory)(ICoreTerritory *p);
00116         STDMETHOD(PopTerritory)();
00117 
00118         std::string GetFirstToken(BSTR connection);
00119 
00120 // ------- Attributes
00121 
00122 protected:
00123         CComObjPtr<ICoreStorage> storage;
00124         CComObjPtr<CCoreMetaProject> metaproject;
00125 
00126         typedef unsigned int status_type;
00127         status_type status;
00128 
00129         transactions_type transactions;
00130         finaltr_items_type finaltr_items;
00131         undos_type undos;
00132         short redo_count;
00133 
00134         object_lookup_type object_lookup;
00135         pushed_territorys_type pushed_territorys;
00136         created_territorys_type created_territorys;
00137 
00138         unsigned long    m_maxUndoStep;
00139         inline void      setMaxUndoStep( long p_undoSize);
00140 // ------- Status
00141 
00142 public:
00143         void SetStatusFlag(status_type flags) { status |= flags; }
00144         void ResetStatusFlag(status_type flags) { status &= ~flags; }
00145         bool GetStatusFlag(status_type flag) const { return (status & flag) != 0; }
00146 
00147 public:
00148         bool InTransaction() const NOTHROW { return !transactions.empty(); }
00149         bool InReadTransaction() const NOTHROW
00150         { return !transactions.empty() && transactions.front().readonly; }
00151         bool InWriteTransaction() const NOTHROW
00152         { return !transactions.empty() && !transactions.front().readonly; }
00153 
00154 // ------- Transaction
00155 
00156 public:
00157         int GetNestedTrCount() const;
00158 
00159         void RegisterTransactionItem(CCoreTransactionItem *modified) NOTHROW;
00160         void RegisterFinalTrItem(CCoreFinalTrItem *modified) NOTHROW;
00161         void RegisterUndoItem(CCoreUndoItem *modified) NOTHROW;
00162         
00163         void BeginFinalTr();
00164         void CommitFinalTr(bool undo);
00165         void AbortFinalTr();
00166 
00167         void BeginNestedTr() NOTHROW;
00168         void CommitNestedTr() NOTHROW;
00169         void AbortNestedTr() NOTHROW;
00170 
00171         void TryUndoTransaction();
00172         void TryRedoTransaction();
00173         void TryDiscardLastItem();
00174 
00175 // ------- Methods
00176 
00177 public:
00178         ICoreStorage *GetStorage() const NOTHROW { return storage; }
00179         CCoreMetaProject *GetMetaProject() const NOTHROW { return metaproject; }
00180 
00181         ICoreStorage *SetStorageObject(CCoreObject *object);
00182 
00183         CCoreObject *FindObject(metaid_type metaid, objid_type objid);
00184         CComObjPtr<CCoreObject> CreateObject(metaid_type metaid, objid_type objid);
00185         CComObjPtr<CCoreObject> GetObject(metaid_type metaid, objid_type objid);
00186 
00187         CComObjPtr<CCoreObject> CreateObject(metaid_type metaid);
00188 
00189         void RegisterObject(metaid_type metaid, objid_type objid, CCoreObject *object) NOTHROW;
00190         void UnregisterObject(metaid_type metaid, objid_type objid) NOTHROW;
00191 
00192         void CastProject(ICoreProject *project) const;          // throws E_SAMEPROJECT
00193         CCoreObject *CastObject(ICoreObject *object) const;
00194         CCoreTerritory *CastTerritory(ICoreTerritory *territory) const;
00195 
00196         CCoreTerritory *GetTerritory() const;
00197         void RegisterTerritory(CCoreTerritory *territory) NOTHROW;
00198         void UnregisterTerritory(CCoreTerritory *territory) NOTHROW;
00199 };
00200 
00201 #endif//MGA_COREPROJECT_H