home *** CD-ROM | disk | FTP | other *** search
- #ifndef _INC_OBJBIND_HPP
- #define _INC_OBJBIND_HPP
- class TC_CPsInstID;
- class TC_CPsInstance;
- class TC_CPsObject;
-
- class TC_CPsCollection;
- template <class T> class TC_TPsArray;
- template <class T> class TC_TPsSortedArray;
-
- class TC_CPsRef;
- template <class T> class TC_TPsRef;
-
- class TC_CPsDemRef;
- template <class T> class TC_TPsDemRef;
- #define TC_PS_ID TC_CPsInstID
- #define TC_PS_NULL_OID 0
- enum {
- dem_NoResolve = 1,
- };
- #define TC_PSGetNoResolve(o) Get((o),dem_NoResolve)
- #define TC_PS_OBJSTATE_NEW 0x00000001L
- #define TC_PS_OBJSTATE_DELETED 0x00000002L
- #define TC_PS_OBJSTATE_DIRTY 0x00000004L
- enum TCPsRefStat {
- ref_UnResolved,
- ref_UnAssigned,
- ref_Assigned,
- };
-
- // **********************************************************************
- class TC_PS_EXPORT TC_CPsInstID
- {
- public: TCPsHClass m_hClass ;
- public: ULONG m_oid ;
- public: TC_CPsInstID () ;
- public: TC_CPsInstID (TCPsHClass cl, ULONG oid) ;
- public: TC_CPsInstID (ULONG cid, ULONG oid) ;
- public: ULONG GetCID () ;
- public: BOOL IsValid () ;
- public: operator BOOL () ;
- public: void Set (TCPsHClass cl, ULONG oid) ;
- public: void Set (ULONG cid, ULONG oid) ;
- public: void Clear () ;
- public: BOOL operator == (TC_CPsInstID &inst_id) ;
- public: BOOL operator == (TC_CPsInstID * inst_id) ;
-
- }; // end of class TC_CPsInstID
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_PS_EXPORT TC_CPsInstance
- {
- friend class PsInstMgr;
- friend class PsObjGraph;
-
- protected: TC_CPsInstID m_InstID ;
- public: void SetOID ( ULONG oid) ;
- public: ULONG GetOID () ;
- public: ULONG GetCID () ;
- protected: virtual void SetClass (TCPsHClass hClass) ;
- public: TCPsHClass HClass () ;
- public: TC_CPsInstID * GetInstID () ;
- public: TC_CPsInstance () ;
- public: TC_CPsInstance (TC_CPsInstID & inst_id) ;
- public: TC_CPsInstance (TCPsHClass cl, ULONG oid) ;
-
- }; // end of class TC_CPsInstance
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_PS_EXPORT TC_CPsObject
- : public TC_CPsInstance
- {
- friend class TC_CPsTxRsc;
- friend class PsObjGraph;
- friend class TC_CPsResSet;
- friend class TC_CPsRef;
- private:
- TC_CPsObject& operator = (const TC_CPsObject&);
- TC_CPsObject (const TC_CPsObject&);
- private: int m_RefCount ;
-
- // **********************************************************************
- protected:
- class TC_PS_EXPORT RelOIDSet
- {
-
- // **********************************************************************
- public:
- class TC_PS_EXPORT RelOID
- {
- public: ULONG m_oid ;
- public: char * m_AttrName ;
- public: RelOID (char * attr_name) ;
-
- }; // end of class RelOID
-
- // **********************************************************************
- private: TC_TArrayPTR <class RelOID> m_RelOIDs ;
- public: RelOIDSet () ;
- public: void Create (TCPsHClass hClass) ;
- public: BOOL SetOID (char * attr_name, ULONG id) ;
- public: ULONG GetOID (char * attr_name) ;
-
- }; // end of class RelOIDSet
-
- // **********************************************************************
-
- // **********************************************************************
- private:
- class TC_PS_EXPORT SmartRefs
- {
- private: TC_TArrayPTR <TC_CPsRef> m_Refs ;
- public: SmartRefs () ;
- public: void UnrefAll () ;
- public: void Add (TC_CPsRef * ref) ;
- public: void Remove (TC_CPsRef * ref) ;
- public: int Count () ;
- public: void Trace () ;
-
- }; // end of class SmartRefs
-
- // **********************************************************************
- private: BOOL m_Registered ;
- private: ULONG m_State ;
- private: BOOL m_IsDeep ;
- private: SmartRefs m_SmartRefs ;
- protected: RelOIDSet m_RelOIDSet ;
- public: TC_CPsObject () ;
- public: virtual ~TC_CPsObject () ;
- protected: void SetClass (TCPsHClass hClass) ;
- private: void AddSmartRef (TC_CPsRef * ref) ;
- private: void RemoveSmartRef (TC_CPsRef * ref) ;
- public: int SmartRefCount () ;
- public: void RemoveRef () ;
- public: void AddRef () ;
- public: int RefCount () ;
- public: TC_CPsClassInfo GetClassInfo () ;
- public: BOOL IsModified () ;
- public: BOOL IsNew () ;
- public: TCPsRetCode SetModified (TCPsSetOpt setOpt = opt_Set) ;
- public: ULONG GetState () ;
- public: TC_CString InfoStr () ;
- public: void Trace (char * title = "") ;
- public: BOOL SetRelOID (char * attr_name, ULONG id) ;
- public: ULONG GetRelOID (char * attr_name) ;
- public: virtual void OnRestore () ;
- public: virtual TCPsRetCode Store (TCPsDepthMode depth = Depth_Default) TC_PS_THROW_FUNC ;
- public: virtual TCPsRetCode Remove () TC_PS_THROW_FUNC ;
-
- }; // end of class TC_CPsObject
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_PS_EXPORT TC_CPsRef
- {
- friend class TC_CPsObject::SmartRefs;
- private: TC_CPsObject * m_Object ;
- public: static void Ref (TC_CPsRef & ref) ;
- public: static void UnRef (TC_CPsRef & ref) ;
- public: static void Assign (TC_CPsRef & ref, TC_CPsObject * obj) ;
-
- }; // end of class TC_CPsRef
-
- // **********************************************************************
-
- // **********************************************************************
- template <class T>
- class TC_TPsRef
- {
- private: T * m_Object ;
- public: TC_TPsRef ( T * obj = 0)
- {
- m_Object = obj;
- TC_CPsRef::Ref(*this);
-
-
-
-
-
-
-
- } // end of func
- // **********************************************************************
-
- public: TC_TPsRef (TC_TPsRef<T> &ps_ref)
- {
- m_Object = ps_ref.m_Object;
- TC_CPsRef::Ref(*this);
-
-
-
-
-
-
-
- } // end of func
- // **********************************************************************
-
- public: ~TC_TPsRef ()
- {
- TC_CPsRef::UnRef(*this);
-
-
- } // end of func
- // **********************************************************************
-
- public: T* operator-> ()
- {
- return m_Object;
- } // end of func
- // **********************************************************************
-
- public: TC_TPsRef<T> & operator = (TC_TPsRef<T> &ps_ref)
- {
- TC_CPsRef::Assign(*this, ps_ref.m_Object);
- return *this;
-
- } // end of func
- // **********************************************************************
-
- public: TC_TPsRef<T> & operator = (T * obj)
- {
- TC_CPsRef::Assign(*this, obj);
- return *this;
-
- } // end of func
- // **********************************************************************
-
- public: operator T* ()
- {
- return m_Object;
- } // end of func
- // **********************************************************************
-
- public: operator TC_CPsRef& ()
- {
- return *(TC_CPsRef*)this;
- } // end of func
- // **********************************************************************
-
- public: BOOL operator == (T* obj)
- {
- return m_Object == obj;
- } // end of func
- // **********************************************************************
-
- public: BOOL operator == (TC_TPsRef<T> &ps_ref)
- {
- return m_Object == ps_ref.m_Object;
- } // end of func
- // **********************************************************************
-
- public: BOOL operator != (T* obj)
- {
- return m_Object != obj;
- } // end of func
- // **********************************************************************
-
- public: BOOL operator != (TC_TPsRef<T> &ps_ref)
- {
- return m_Object != ps_ref.m_Object;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TPsRef
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_PS_EXPORT TC_CPsCollection
- {
- public: virtual ~TC_CPsCollection () ;
- public: virtual TC_CPsObject * GetObject (int idx) =0 ;
- public: virtual int AddObject (TC_CPsObject * obj) =0 ;
- public: virtual void RemoveObject (TC_CPsObject * obj) =0 ;
- public: virtual void RemoveObject (int idx) =0 ;
- public: virtual void Release () ;
- public: virtual void SetImpl (void * impl) =0 ;
- public: virtual void * GetImpl () =0 ;
- public: virtual void * CreateImpl () =0 ;
- public: virtual void CreatePrivateImpl () =0 ;
- public: virtual TC_CPsCollection * Copy () =0 ;
- public: virtual int Count () =0 ;
- public: virtual int ContainsInstance (TC_CPsInstID inst_id) ;
- public: virtual int ContainsObject (TC_CPsObject * obj) ;
-
- }; // end of class TC_CPsCollection
-
- // **********************************************************************
-
- // **********************************************************************
- template <class T>
- class TC_TPsArray
- : public TC_CPsCollection
- {
- typedef TC_TArrayPTR <T> ObjPtrCltn;
- protected: ObjPtrCltn * m_Cltn ;
- protected: BOOL m_Own ;
- public: TC_TPsArray ()
- {
- m_Cltn = 0;
- m_Own = FALSE;
- } // end of func
- // **********************************************************************
-
- public: TC_TPsArray ( ObjPtrCltn * cltn)
- {
- m_Cltn = cltn;
- m_Own = FALSE;
- } // end of func
- // **********************************************************************
-
- public: ~TC_TPsArray ()
- {
- Clear();
- } // end of func
- // **********************************************************************
-
- private: void Clear ()
- {
- if(m_Own) {
- Release();
- delete m_Cltn;
- }
- } // end of func
- // **********************************************************************
-
- public: TC_CPsObject * GetObject (int idx)
- {
- return m_Cltn->Get(idx);
- } // end of func
- // **********************************************************************
-
- public: int AddObject (TC_CPsObject * obj)
- {
- return m_Cltn->Add((T*)obj);
- } // end of func
- // **********************************************************************
-
- public: void RemoveObject (TC_CPsObject * obj)
- {
- m_Cltn->Remove((T*)obj);
- } // end of func
- // **********************************************************************
-
- public: void RemoveObject (int idx)
- {
- m_Cltn->Remove(idx);
- } // end of func
- // **********************************************************************
-
- public: void SetImpl (void * impl)
- {
- Clear();
- m_Own = FALSE;
- m_Cltn = (ObjPtrCltn*)impl;
- } // end of func
- // **********************************************************************
-
- public: void * GetImpl ()
- {
- return m_Cltn;
- } // end of func
- // **********************************************************************
-
- public: void * CreateImpl ()
- {
- return new ObjPtrCltn;
- } // end of func
- // **********************************************************************
-
- public: void CreatePrivateImpl ()
- {
- Clear();
- m_Own = TRUE;
- m_Cltn = new ObjPtrCltn;
-
- } // end of func
- // **********************************************************************
-
- public: TC_CPsCollection * Copy ()
- {
- return new TC_TPsArray<T>;
- } // end of func
- // **********************************************************************
-
- public: int Count ()
- {
- return m_Cltn->Count();
- } // end of func
- // **********************************************************************
-
- public: T * operator [] (int idx)
- {
- return (T*)GetObject(idx);
-
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TPsArray
-
- // **********************************************************************
-
- // **********************************************************************
- template <class T>
- class TC_TPsSortedArray
- : public TC_CPsCollection
- {
- typedef TC_TPtrMap <T, T> ObjPtrMap;
- typedef int (*CMP_FUNC)(const T*, const T*);
- protected: ObjPtrMap * m_Map ;
- protected: BOOL m_Own ;
- protected: CMP_FUNC m_CmpFunc ;
- public: TC_TPsSortedArray (CMP_FUNC cmp_func)
- {
- m_Map = 0;
- m_Own = FALSE;
- m_CmpFunc = cmp_func;
- } // end of func
- // **********************************************************************
-
- public: TC_TPsSortedArray ( ObjPtrMap * map)
- {
- m_Map = map;
- m_Own = FALSE;
- m_CmpFunc = (CMP_FUNC)map->GetCmpFunc();
-
-
- } // end of func
- // **********************************************************************
-
- public: ~TC_TPsSortedArray ()
- {
- Clear();
- } // end of func
- // **********************************************************************
-
- private: void Clear ()
- {
- if(m_Own) {
- Release();
- delete m_Map;
- }
- } // end of func
- // **********************************************************************
-
- public: TC_CPsObject * GetObject (int idx)
- {
- return m_Map->ValByIdx(idx);
- } // end of func
- // **********************************************************************
-
- public: int AddObject (TC_CPsObject * obj)
- {
- return m_Map->InsertAssoc((T*)obj,(T*)obj);
- //return m_Map->GetCurPos();
- } // end of func
- // **********************************************************************
-
- public: void RemoveObject (TC_CPsObject * obj)
- {
- m_Map->RemoveAssoc((T*)obj);
- } // end of func
- // **********************************************************************
-
- public: void RemoveObject (int idx)
- {
- m_Map->RemoveByIdx(idx);
- } // end of func
- // **********************************************************************
-
- public: void SetImpl (void * impl)
- {
- Clear();
- m_Own = FALSE;
- m_Map = (ObjPtrMap*)impl;
- } // end of func
- // **********************************************************************
-
- public: void * GetImpl ()
- {
- return m_Map;
- } // end of func
- // **********************************************************************
-
- public: void * CreateImpl ()
- {
- return new ObjPtrMap((TC_TPtrMap<T,T>::MapCmpFunc)m_CmpFunc);
- } // end of func
- // **********************************************************************
-
- public: void CreatePrivateImpl ()
- {
- Clear();
- m_Own = TRUE;
- m_Map = new ObjPtrMap(m_CmpFunc);
-
- } // end of func
- // **********************************************************************
-
- public: TC_CPsCollection * Copy ()
- {
- return new TC_TPsSortedArray<T>(m_CmpFunc);
- } // end of func
- // **********************************************************************
-
- public: int Count ()
- {
- return m_Map->Count();
- } // end of func
- // **********************************************************************
-
- public: int ContainsObject (TC_CPsObject * obj)
- {
- if(m_Map->Search((T*)obj)==0)
- return m_Map->GetCurPos();
- return -1;
- } // end of func
- // **********************************************************************
-
- public: T * operator [] (int idx)
- {
- return (T*)GetObject(idx);
-
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TPsSortedArray
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_PS_EXPORT TC_CPsDemRef
- {
- protected: int m_RefStatus ;
- protected: TCPsRetCode ReleaseRef (TCPsHClass hClass) ;
- public: TC_CPsDemRef () ;
- public: int RefStatus () ;
- public: void UnResolve () ;
- public: TCPsRetCode GetObject (TC_CPsObject * owner_obj, char * attr_name) TC_PS_THROW_FUNC ;
- public: void SetRef (void * obj) ;
- public: BOOL IsResolved () ;
- public: BOOL IsAssigned () ;
-
- }; // end of class TC_CPsDemRef
-
- // **********************************************************************
- template <class T> TCPsHClass _Get_HClass(T*);
-
- // **********************************************************************
- template <class T>
- class TC_TPsDemRef
- : public TC_CPsDemRef
- {
- friend class TC_CPsDemRef;
- protected: T * m_Object ;
- public: TC_TPsDemRef ()
- {
- m_Object = 0;
- } // end of func
- // **********************************************************************
-
- public: ~TC_TPsDemRef ()
- {
- Release();
- } // end of func
- // **********************************************************************
-
- public: TCPsRetCode Release ()
- {
- //return IsAssigned() ? ReleaseRef(_Get_HClass(m_Object)) : rcOk;
- return rcOk;
- } // end of func
- // **********************************************************************
-
- public: T* operator = (T * obj)
- {
- SetRef(obj);
- return obj;
- } // end of func
- // **********************************************************************
-
- public: T* GetRef ()
- {
- return m_Object;
- } // end of func
- // **********************************************************************
-
- public: T* operator * ()
- {
- return m_Object;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TPsDemRef
-
- // **********************************************************************
-
- #endif // _INC_OBJBIND_HPP
-