#include <RCPtr.h>
Inheritance diagram for RCPtr< T >:
Public Member Functions | |
RCPtr (T *realPtr=0) | |
RCPtr (const RCPtr &rhs) | |
~RCPtr () | |
bool | operator== (const RCPtr &rhs) |
RCPtr & | operator= (const RCPtr &rhs) |
Assign to the "smart pointer". | |
T * | operator-> () const |
T & | operator * () const |
Private Member Functions | |
void | init () |
Private Attributes | |
T * | pointee |
This template is designed to be used with the RCObject base class for reference counted objects.
This template was published in More Effective C++ by Scott Meyers, Addison-Wesley, 1996. The RCPtr template is part of Scott Meyers reference counted String class, published in "Item 29".
The RCPtr template is used to instantiate a shared data object for a reference counted object. A simplified version of the SubString object is shown below. Note that the SubString class variable value is an instance of the local shared data object SharedData.
class SubString { private:
public: SharedData(); }; // class sharedData
RCPtr<SharedData> value; }The RCPtr "smart pointer" is designed to be instantiated with a class that is derived from RCObject. RCObject support the reference count. The RCPtr "smart pointer" handles assignment by deleting the shared data of "this" and assigning it the shared data from the right hand side object. The RCPtr template also decrements the reference count when the destructor is called.
Definition at line 62 of file RCPtr.h.
|
Definition at line 93 of file RCPtr.h. References RCPtr< T >::init().
|
|
Definition at line 100 of file RCPtr.h. References RCPtr< T >::init().
|
|
Definition at line 108 of file RCPtr.h. References RCPtr< T >::pointee.
|
|
Definition at line 83 of file RCPtr.h. References RCPtr< T >::pointee. Referenced by RCPtr< T >::operator=(), and RCPtr< T >::RCPtr().
|
|
Definition at line 160 of file RCPtr.h. References RCPtr< T >::pointee.
00161 { 00162 return *pointee; 00163 } |
|
Definition at line 152 of file RCPtr.h. References RCPtr< T >::pointee.
00153 { 00154 return pointee; 00155 } |
|
Assign to the "smart pointer". The "smart pointer" should be instantiated with an object derived from RCObject. The RCObject base class supports the removeReference function which deallocates "this". In the code below, the new value for the smart pointer is assigned to pointee. The reference count is incremented to 1 (in init()) and the old object (oldPointee) is deallocated. Definition at line 127 of file RCPtr.h. References RCPtr< T >::init(), and RCPtr< T >::pointee.
|
|
Definition at line 143 of file RCPtr.h. References RCPtr< T >::pointee.
|
|
Definition at line 76 of file RCPtr.h. Referenced by RCPtr< T >::init(), RCPtr< T >::operator *(), RCPtr< T >::operator->(), RCPtr< T >::operator=(), RCPtr< T >::operator==(), and RCPtr< T >::~RCPtr(). |