00001 #ifndef _CTBsharedObjPtr_HXX 00002 #define _CTBsharedObjPtr_HXX 1 00003 00008 /*----------------------------------------------------------------------------*/ 00009 /* C Tool Box: Designed and implemented by: */ 00010 /* Walter F.J. Mueller Gesellschaft fuer Schwerionenforschung (GSI) */ 00011 /* Planckstrasse 1, D-64291 Darmstadt, Germany */ 00012 /* Email: W.F.J.Mueller@gsi.de */ 00013 /* WWW: http://www-kp3.gsi.de/www/kp3/people/mueller.html */ 00014 /*------------------------------------------+---------------------------------*/ 00015 00016 #include "CTBreferenceCounter.hxx" 00017 00018 template <class T> 00019 class CTBsharedCObjPtr { 00020 public: 00021 CTBsharedCObjPtr(); 00022 CTBsharedCObjPtr(const CTBsharedCObjPtr<T>& rhs); 00023 CTBsharedCObjPtr(T* p); 00024 00025 ~CTBsharedCObjPtr(); 00026 00027 bool IsUnique() const; 00028 bool IsShared() const; 00029 CTBint ShareCount() const; 00030 00031 bool Equal(const CTBsharedCObjPtr<T>& rhs) const; 00032 void ToStream(ostream& os) const; 00033 00034 CTBsharedCObjPtr<T>& operator=(const CTBsharedCObjPtr<T>& rhs); 00035 CTBsharedCObjPtr<T>& operator=(T* rhs); 00036 00037 const T& operator*() const; 00038 const T* operator->() const; 00039 00040 bool operator !() const; 00041 operator void*() const; 00042 00043 private: 00044 void Clear(); 00045 00046 protected: 00047 T* mp_obj; 00048 CTBreferenceCounter* mp_refcount; 00049 }; 00050 00051 template <class T> 00052 bool operator==(const CTBsharedCObjPtr<T>& lhs, const CTBsharedCObjPtr<T>& rhs); 00053 00054 template <class T> 00055 ostream& operator<<(ostream& os, const CTBsharedCObjPtr<T>& obj); 00056 00057 //############################################################################## 00058 00059 template <class T> 00060 class CTBsharedObjPtr : public CTBsharedCObjPtr<T> { 00061 public: 00062 CTBsharedObjPtr(); 00063 CTBsharedObjPtr(const CTBsharedObjPtr<T>& rhs); 00064 CTBsharedObjPtr(T* p); 00065 00066 CTBsharedObjPtr<T>& operator=(T* rhs); 00067 00068 T& operator*() const; 00069 T* operator->() const; 00070 }; 00071 00072 // Notes: 00073 // -- proofed: xx-xxx-xxxx(x) 00074 00075 #include "CTBsharedObjPtr.icc" 00076 00077 #endif