Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ReferenceCount.h

Go to the documentation of this file.
00001 /*
00002  * Time-stamp: <00/07/05 17:45:20 pagey>
00003  *
00004  * $Id: ReferenceCount.h,v 1.1 2000/07/06 05:09:22 pagey Exp $
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     } ; // class ReferenceCount
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       // The order of the next two statements is VERY important. The
00152       // increment should happen BEFORE the decrement to account for
00153       // the fact that somebody might try to do this:
00154       //
00155       // a = a ;
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   } ; // namespace GenSim
00174 } // extern "C++"
00175 #endif // #ifndef ReferenceCount_h

Generated at Tue Aug 8 01:37:55 2000 for libgpib by doxygen1.1.4 written by Dimitri van Heesch, © 1997-2000