GME  13
CoreTerritory.h
Go to the documentation of this file.
00001 
00002 #ifndef MGA_CORETERRITORY_H
00003 #define MGA_CORETERRITORY_H
00004 
00005 #include "CoreTransactionItem.h"
00006 
00007 #include <list>
00008 #include <hash_map>
00009 
00010 class CCoreProject;
00011 class CCoreLockAttribute;
00012 
00013 // --------------------------- CCoreTerritory
00014 
00015 class ATL_NO_VTABLE CCoreTerritory : 
00016         public CComObjectRootEx<CComSingleThreadModel>,
00017         public IDispatchImpl<ICoreTerritory, &__uuidof(ICoreTerritory), &__uuidof(__MGACoreLib)>,
00018         public CCoreFinalTrItemImpl<&__uuidof(ICoreTerritory)>,
00019         public CCoreTransactionItem
00020 {
00021 public:
00022         CCoreTerritory();
00023         virtual ~CCoreTerritory();
00024 
00025         static CCoreTerritory *Create(CCoreProject *project);
00026 
00027 BEGIN_COM_MAP(CCoreTerritory)
00028         COM_INTERFACE_ENTRY(ICoreTerritory)
00029         COM_INTERFACE_ENTRY(IDispatch)
00030         COM_INTERFACE_ENTRY(ISupportErrorInfo)
00031 END_COM_MAP()
00032 
00033 // ------- Attributes
00034 
00035 protected:
00036         CComObjPtr<CCoreProject> project;
00037 
00038         typedef unsigned char status_type;
00039         status_type status;
00040 
00041 // ------- COM methods
00042 
00043 public:
00044         STDMETHODIMP get_Project(ICoreProject **p);
00045         STDMETHODIMP get_Attributes(ICoreAttributes **p);
00046         STDMETHODIMP Clear();
00047 
00048 // ------- Methods
00049 
00050 public:
00051         CCoreProject *GetProject() const { return project; }
00052 
00053 // ------- Status
00054 
00055 #define CORETERRITORY_DIRTY                             0x0001
00056 #define CORETERRITORY_FINAL                             0x0002
00057 
00058 private:
00059         void SetStatusFlag(status_type flags) { status |= flags; }
00060         void ResetStatusFlag(status_type flags) { status &= ~flags; }
00061 
00062         void ChangeStatusFlag(status_type flag, bool set) { if(set) status |= flag; else status &= ~flag; }
00063         bool GetStatusFlag(status_type flag) const { return (status & flag) != 0; }
00064 
00065         bool InTransaction() const;
00066 
00067 // ------- NestedTrItem
00068 
00069 public:
00070         virtual bool IsDirty() const NOTHROW { return GetStatusFlag(CORETERRITORY_DIRTY); }
00071         virtual void ChangeDirty(bool dirty) NOTHROW { ChangeStatusFlag(CORETERRITORY_DIRTY, dirty); }
00072 
00073         virtual void AbortNestedTransaction() NOTHROW { ResetStatusFlag(CORETERRITORY_DIRTY); }
00074         virtual void DiscardPreviousValue() NOTHROW { }
00075 
00076 // ------- FinalTrItem
00077 
00078 public:
00079         virtual void AbortFinalTransaction() NOTHROW { ResetStatusFlag(CORETERRITORY_DIRTY); }
00080         virtual void CommitFinalTransaction() {}
00081         virtual void CommitFinalTransactionFinish(bool undo) NOTHROW { ResetStatusFlag(CORETERRITORY_DIRTY); }
00082 };
00083 
00084 #ifndef _ATL_DEBUG_INTERFACES
00085 inline IUnknown *CastToUnknown(CCoreTerritory *p) { return (IUnknown*)(ICoreTerritory*)p; }
00086 inline CCoreTerritory *CastToTerritory(IUnknown *p) { return (CCoreTerritory*)(ICoreTerritory*)p; }
00087 #else
00088 inline IUnknown *CastToUnknown(CCoreTerritory *p) {
00089         DebugBreak();
00090         return (IUnknown*)(ICoreTerritory*)p;
00091 }
00092 inline CCoreTerritory *CastToTerritory(IUnknown *p)
00093 {
00094         return (CCoreTerritory*)(ICoreTerritory*)((ATL::_QIThunk *)(p))->m_pUnk;
00095 }
00096 #endif
00097 
00098 #endif//MGA_CORETERRITORY_H
00099