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

RCObject.h

Go to the documentation of this file.
00001 
00002 #ifndef RCOBJECT_H
00003 #define RCOBJECT_H
00004 
00038 class RCObject {
00039 public:
00040   void addReference();
00041   void removeReference();
00042   const bool isShared() const;
00043   const size_t refCnt() const;
00044 
00045 protected:
00046   RCObject();
00047   RCObject(const RCObject& rhs);
00048   RCObject& operator=(const RCObject &rhs);
00049   virtual ~RCObject();
00050 
00051 private:
00052   size_t refCount;
00053 };
00054 
00055 inline
00056 RCObject::RCObject() : refCount(0) {}
00057 
00058 inline
00059 RCObject::RCObject(const RCObject& ) : refCount(0) {}
00060 
00061 inline
00062 RCObject& RCObject::operator=(const RCObject&)
00063 {
00064   return *this;
00065 }
00066 
00067 inline
00068 RCObject::~RCObject() {}
00069 
00070 inline
00071 void RCObject::addReference() { refCount++; }
00072 
00073 inline
00074 void RCObject::removeReference()
00075 { 
00076   if (--refCount == 0) {
00077     delete this; 
00078   }
00079 }
00080 
00081 inline
00082 const bool RCObject::isShared() const
00083 {
00084   return refCount > 1;
00085 }
00086 
00087 inline
00088 const size_t RCObject::refCnt() const
00089 {
00090   return refCount;
00091 }
00092 
00093 
00094 #endif

Generated on Mon Sep 22 20:22:58 2003 by doxygen 1.3.3