#include <RCObject.h>
Inheritance diagram for RCObject:
Public Member Functions | |
void | addReference () |
void | removeReference () |
const bool | isShared () const |
const size_t | refCnt () const |
Protected Member Functions | |
RCObject () | |
RCObject (const RCObject &rhs) | |
RCObject & | operator= (const RCObject &rhs) |
virtual | ~RCObject () |
Private Attributes | |
size_t | refCount |
This class encapsulates the reference count. The shared data class is derived from this class and is a container for the the shared data.
This class is based on the RCObject class published in More Effective C++ by Scott Meyers, Addison-Wesley, 1996. This is part of Scott Meyers reference counted String class, published in "Item 29". This code is in the public domain.
I have the first edition and first printing of Mr. Meyers' book. I've added some of the changes from Mr. Meyers' errata pages, which are not included in this edition. I've also made some to Mr. Meyers' version of RCObject. In particular, I've removed the shareable flag, since as far as I can tell, it is not needed. I have also made the reference count available for testing purposes.
Definition at line 38 of file RCObject.h.
|
Definition at line 56 of file RCObject.h.
00056 : refCount(0) {} |
|
Definition at line 59 of file RCObject.h.
00059 : refCount(0) {} |
|
Definition at line 68 of file RCObject.h.
00068 {} |
|
Definition at line 71 of file RCObject.h. References refCount.
00071 { refCount++; } |
|
Definition at line 82 of file RCObject.h. References refCount.
00083 { 00084 return refCount > 1; 00085 } |
|
Definition at line 62 of file RCObject.h.
00063 { 00064 return *this; 00065 } |
|
Definition at line 88 of file RCObject.h. References refCount. Referenced by SubString::SharedData::getRefCnt(), and RCArray< T >::SharedData::getRefCnt().
00089 { 00090 return refCount; 00091 } |
|
Definition at line 74 of file RCObject.h. References refCount.
00075 { 00076 if (--refCount == 0) { 00077 delete this; 00078 } 00079 } |
|
Definition at line 52 of file RCObject.h. Referenced by addReference(), isShared(), refCnt(), and removeReference(). |