00001 00006 /*----------------------------------------------------------------------------*/ 00007 /* C Tool Box: Designed and implemented by: */ 00008 /* Walter F.J. Mueller Gesellschaft fuer Schwerionenforschung (GSI) */ 00009 /* Planckstrasse 1, D-64291 Darmstadt, Germany */ 00010 /* Email: W.F.J.Mueller@gsi.de */ 00011 /* WWW: http://www-kp3.gsi.de/www/kp3/people/mueller.html */ 00012 /*------------------------------------------+---------------------------------*/ 00013 00014 //------------------------------------------+----------------------------------- 00016 00017 template <class T> 00018 inline CTBsharedBuffer<T>::CTBsharedBuffer() 00019 : mp_data(0), 00020 mi_size(0), 00021 mp_refcount(0) 00022 {} 00023 00024 //------------------------------------------+----------------------------------- 00026 00027 template <class T> 00028 inline CTBsharedBuffer<T>::CTBsharedBuffer(CTBint i_size) 00029 { 00030 CreateBuffer(i_size); 00031 } 00032 00033 //------------------------------------------+----------------------------------- 00035 00036 template <class T> 00037 inline CTBsharedBuffer<T>::CTBsharedBuffer(const CTBsharedBuffer<T>& rhs) 00038 : mp_data(rhs.mp_data), 00039 mi_size(rhs.mi_size), 00040 mp_refcount(rhs.mp_refcount) 00041 { 00042 if (mp_refcount) mp_refcount->Increment(); 00043 } 00044 00045 //------------------------------------------+----------------------------------- 00047 00048 template <class T> 00049 CTBsharedBuffer<T>::CTBsharedBuffer(CTBsharedBuffer<T>& rhs, bool) 00050 : mp_data(rhs.mp_data), 00051 mi_size(rhs.mi_size), 00052 mp_refcount(rhs.mp_refcount) 00053 { 00054 rhs.mp_data = 0; 00055 rhs.mi_size = 0; 00056 rhs.mp_refcount = 0; 00057 } 00058 00059 //------------------------------------------+----------------------------------- 00061 00062 template <class T> 00063 inline CTBsharedBuffer<T>::~CTBsharedBuffer() 00064 { 00065 Release(); 00066 } 00067 00068 //------------------------------------------+----------------------------------- 00070 00071 template <class T> 00072 inline T* CTBsharedBuffer<T>::Data() const 00073 { 00074 return mp_data; 00075 } 00076 00077 //------------------------------------------+----------------------------------- 00079 00080 template <class T> 00081 inline CTBint CTBsharedBuffer<T>::Size() const 00082 { 00083 return mi_size; 00084 } 00085 00086 //------------------------------------------+----------------------------------- 00088 00089 template <class T> 00090 inline bool CTBsharedBuffer<T>::IsNull() const 00091 { 00092 return mp_data == 0; 00093 } 00094 00095 //------------------------------------------+----------------------------------- 00097 00098 template <class T> 00099 inline bool CTBsharedBuffer<T>::IsUnique() const 00100 { 00101 return mp_refcount && mp_refcount->IsUnique(); 00102 } 00103 00104 //------------------------------------------+----------------------------------- 00106 00107 template <class T> 00108 inline bool CTBsharedBuffer<T>::IsShared() const 00109 { 00110 return mp_refcount && mp_refcount->IsShared(); 00111 } 00112 00113 //------------------------------------------+----------------------------------- 00115 00116 template <class T> 00117 inline CTBsharedBuffer<T>& CTBsharedBuffer<T>::operator=( 00118 const CTBsharedBuffer<T>& rhs) 00119 { 00120 SharedCopy(rhs); 00121 return *this; 00122 } 00123 00124 //------------------------------------------+----------------------------------- 00126 00127 template <class T> 00128 inline const T& CTBsharedBuffer<T>::operator[](CTBint i_ind) const 00129 { 00130 #ifndef CTB__IndexCheck 00131 return mp_data[i_ind]; 00132 #else 00133 return At(i_ind); 00134 #endif 00135 } 00136 00137 //------------------------------------------+----------------------------------- 00139 00140 template <class T> 00141 inline T& CTBsharedBuffer<T>::operator[](CTBint i_ind) 00142 { 00143 #ifndef CTB__IndexCheck 00144 return mp_data[i_ind]; 00145 #else 00146 return At(i_ind); 00147 #endif 00148 } 00149 00150 //------------------------------------------+----------------------------------- 00152 00153 template <class T> 00154 inline bool CTBsharedBuffer<T>::operator==(const CTBsharedBuffer<T>& rhs) const 00155 { 00156 return mp_data == rhs.mp_data; 00157 } 00158 00159 //------------------------------------------+----------------------------------- 00161 00162 template <class T> 00163 inline bool CTBsharedBuffer<T>::operator! () const 00164 { 00165 return mp_data == 0; 00166 } 00167 00168 //------------------------------------------+----------------------------------- 00170 00171 template <class T> 00172 inline CTBsharedBuffer<T>::operator bool() const 00173 { 00174 return mp_data; 00175 }