00001 00002 00003 00004 00005 00006
00007 #ifndef ReferenceCount_h
00008 #define ReferenceCount_h
00009
00010 extern "C++" {
00011 namespace LibGPIB {
00024 class ReferenceCount {
00025 public:
00029
00031
00035
00037
00041
00043
00047
00049
00056 ReferenceCount() ;
00057
00063 ReferenceCount(const ReferenceCount& other) ;
00064
00068 ~ReferenceCount() ;
00070
00078 bool IsUnique() const ;
00080
00089 ReferenceCount& operator=(const ReferenceCount& other) ;
00091
00092 protected:
00096
00098
00102
00104
00105 private:
00112 unsigned int *mCount ;
00114
00122 void Decrement() ;
00124
00125 } ;
00126
00127 inline
00128 ReferenceCount::ReferenceCount() : mCount(new unsigned int(1)) { }
00129
00130 inline
00131 ReferenceCount::ReferenceCount(const ReferenceCount& other)
00132 : mCount(other.mCount) {
00133 ++(*mCount) ;
00134 }
00135
00136 inline
00137 ReferenceCount::~ReferenceCount() {
00138 Decrement() ;
00139 }
00140
00141 inline
00142 bool
00143 ReferenceCount::IsUnique() const {
00144 return (1 == *mCount) ;
00145 }
00146
00147 inline
00148 ReferenceCount&
00149 ReferenceCount::operator=(const ReferenceCount& other) {
00150
00151
00152
00153
00154
00155
00156
00157 ++(*other.mCount) ;
00158 Decrement() ;
00159 mCount = other.mCount ;
00160 return *this ;
00161 }
00162
00163 inline
00164 void
00165 ReferenceCount::Decrement() {
00166 if( IsUnique() ) {
00167 delete mCount ;
00168 } else {
00169 --(*mCount) ;
00170 }
00171 }
00172
00173 } ;
00174 }
00175 #endif // #ifndef ReferenceCount_h