#include <CTBsharedObjPtr.hxx>
Inheritance diagram for CTBsharedCObjPtr:
Public Methods | |
CTBsharedCObjPtr () | |
CTBsharedCObjPtr (const CTBsharedCObjPtr< T > &rhs) | |
CTBsharedCObjPtr (T *p) | |
~CTBsharedCObjPtr () | |
bool | IsUnique () const |
bool | IsShared () const |
CTBint | ShareCount () const |
bool | Equal (const CTBsharedCObjPtr< T > &rhs) const |
void | ToStream (ostream &os) const |
CTBsharedCObjPtr< T > & | operator= (const CTBsharedCObjPtr< T > &rhs) |
CTBsharedCObjPtr< T > & | operator= (T *rhs) |
const T & | operator * () const |
const T * | operator-> () const |
bool | operator! () const |
operator void * () const | |
Protected Attributes | |
T * | mp_obj |
CTBreferenceCounter * | mp_refcount |
Private Methods | |
void | Clear () |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const CTBsharedCObjPtr< T > &lhs, const CTBsharedCObjPtr< T > &rhs) |
ostream & | operator<< (ostream &os, const CTBsharedCObjPtr< T > &obj) |
This is a `smart pointer' implementing a many-to-one correspondence between pointers and an object on the heap. A reference count keeps track of how many pointers refer to the same object.
The copy constructor and the assignment operator increment and decrement the reference count. The controled object is deleted when the last controling pointer is destroyed or assigned with another value.
For obvious reasons there is no operator T *()
method. But sometimes it is necessary to have an explicit pointer to the controlled object. Use &(*p)
at your own risk, it can compromise the lifetime control of CTBsharedObjPtr
.
T
. It doesn't require a copy constructor and can thus be used for abstract base classes.~T()
Definition at line 19 of file CTBsharedObjPtr.hxx.
|
Default constructor.
Definition at line 48 of file CTBsharedObjPtr.icc. |
|
Copy constructor. If rhs is non-zero, the reference count of the object controlled by rhs is increased by one. Definition at line 61 of file CTBsharedObjPtr.icc. |
|
Construct from pointer.
The object refered to by p becomes a controlled object, its reference count is set to one. In most cases the argument is the CTBsharedCObjPtr<foo> p(new foo(a1,a2)); Definition at line 79 of file CTBsharedObjPtr.icc. |
|
Destructor. The reference count of the controlled object will be decreased by one. If this was the last pointer refering to the object (the reference count reaches zero), the controlled object is deleted. Definition at line 93 of file CTBsharedObjPtr.icc. |
|
Returns
Note, that Definition at line 107 of file CTBsharedObjPtr.icc. |
|
Returns
Is Definition at line 120 of file CTBsharedObjPtr.icc. |
|
Returns the count of pointers refering to the controlled object.
A zero is returned if the pointer is zero. See also Definition at line 133 of file CTBsharedObjPtr.icc. |
|
Returns
Definition at line 142 of file CTBsharedObjPtr.icc. Referenced by operator==().
|
|
ostream insertion.
Definition at line 151 of file CTBsharedObjPtr.icc. |
|
Assign reference. This pointer will refer to the same object as pointer rhs does. Definition at line 185 of file CTBsharedObjPtr.icc. Referenced by CTBsharedObjPtr::operator=().
|
|
Make rhs the controlled object.
Reimplemented in CTBsharedObjPtr. Definition at line 199 of file CTBsharedObjPtr.icc. |
|
Dereference pointer (access controlled object).
Reimplemented in CTBsharedObjPtr. Definition at line 211 of file CTBsharedObjPtr.icc. |
|
Access member of controlled object.
Reimplemented in CTBsharedObjPtr. Definition at line 220 of file CTBsharedObjPtr.icc. |
|
Returns
Definition at line 229 of file CTBsharedObjPtr.icc. |
|
Returns non-zero pointer if pointer not null.
Definition at line 238 of file CTBsharedObjPtr.icc. |
|
Clear pointer. The reference count of the controlled object will be decreased by one. If the reference count reaches zero, the controlled object is deleted. Definition at line 165 of file CTBsharedObjPtr.icc. Referenced by operator=(), and ~CTBsharedCObjPtr().
|
|
Returns
Definition at line 250 of file CTBsharedObjPtr.icc. |
|
ostream insertion operator.
Definition at line 263 of file CTBsharedObjPtr.icc. |
|
pointer to controlled object.
Definition at line 47 of file CTBsharedObjPtr.hxx. |
|
pointer to reference count.
Definition at line 48 of file CTBsharedObjPtr.hxx. |