| Home | C-Bits Package Documentation | Project Page |
#include <ref_ptr.h>
Inheritance diagram for cbits::ref_ptr:
Public Methods | |
| ref_ptr (T *t) | |
| Create a pointer to T. More... | |
| ref_ptr (const ref_ptr< T > &r) | |
| Copy construct a pointer to T. More... | |
| ref_ptr< T > & | operator= (const ref_ptr< T > &r) |
| Assign pointer to T. More... | |
| const long | getRefCount () const |
| Access number of references. More... | |
| bool | operator== (const ref_ptr< T > &r) |
| Test for equality to pointer T. More... | |
| T * | operator-> () |
| Access member of T. More... | |
| T & | operator * () |
| Access member of T. More... | |
| virtual | ~ref_ptr () |
| Destroy reference to T. More... | |
Protected Attributes | |
| T * | _t |
| The underlying object. More... | |
| long * | _refs |
| Number of references to the object. More... | |
Private Methods | |
| void | freeObject () |
| Free the object, the reference count var, and the 'mutex'. More... | |
| void | lock () const |
| Lock this ptr (e.g. More... | |
| void | unlock () const |
| Unlock this ptr. More... | |
Instead of:
A* a = new A(...); a->...;use
ref_ptr<A> a( new A(...) ); a->...;
Note that the reference counting semantics are thread-safe, but not necessarily the embedded object.
|
||||||||||
|
Create a pointer to T. This sets the initial reference count to one (1). |
|
||||||||||
|
Copy construct a pointer to T. This increments the reference count by one (1). |
|
|||||||||
|
Destroy reference to T. This decrements the reference count by one (1). If no more references remain, the underlying object is deleted. |
|
|||||||||
|
Free the object, the reference count var, and the 'mutex'.
|
|
|||||||||
|
Access number of references.
|
|
|||||||||
|
Lock this ptr (e.g. while changing ref count). |
|
|||||||||
|
Access member of T. This doesn't affect the reference count. Reimplemented in cbits::safe_ptr. |
|
|||||||||
|
Access member of T. This doesn't affect the reference count. Reimplemented in cbits::safe_ptr. |
|
||||||||||
|
Assign pointer to T. This increments the reference count by one (1). |
|
||||||||||
|
Test for equality to pointer T. This doesn't affect the reference count. |
|
|||||||||
|
Unlock this ptr.
|
|
|||||
|
Number of references to the object.
|
|
|||||
|
The underlying object.
|
|
|