|
xorp
|
Reference Counted Pointer Class. More...
#include <ref_ptr.hh>
Public Member Functions | |
| ref_ptr (_Tp *__p=0) | |
| Construct a reference pointer for object. | |
| ref_ptr (const ref_ptr &__r) | |
| Copy Constructor. | |
| ref_ptr & | operator= (const ref_ptr &__r) |
| Assignment Operator. | |
| ~ref_ptr () | |
| Destruct reference pointer instance and lower reference count on object being tracked. | |
| _Tp & | operator* () const |
| Dereference reference counted object. | |
| _Tp * | operator-> () const |
| Dereference pointer to reference counted object. | |
| _Tp * | get () const |
| Dereference pointer to reference counted object. | |
| bool | operator== (const ref_ptr &rp) const |
| Equality Operator. | |
| bool | is_empty () const |
| Check if reference pointer refers to an object or whether it has been assigned a null object. | |
| bool | is_only () const |
| bool | at_least (int32_t n) const |
| void | release () const |
| Release reference on object. | |
| void | reset () const |
| ref_ptr (_Tp *data, int32_t index) | |
Protected Member Functions | |
| void | ref (const ref_ptr *__r) const |
| Add reference. | |
| void | unref () const |
| Remove reference. | |
Protected Attributes | |
| _Tp * | _M_ptr |
| int32_t | _M_index |
Reference Counted Pointer Class.
The ref_ptr class is a strong reference class. It maintains a count of how many references to an object exist and releases the memory associated with the object when the reference count reaches zero. The reference pointer can be dereferenced like an ordinary pointer to call methods on the reference counted object.
At the time of writing the only supported memory management is through the new and delete operators. At a future date, this class should support the STL allocator classes or an equivalent to provide greater flexibility.
Construct a reference pointer for object.
| p | pointer to object to be reference counted. p must be allocated using operator new as it will be destructed using delete when the reference count reaches zero. |
Copy Constructor.
Constructs a reference pointer for object. Raises reference count associated with object by 1.
| bool ref_ptr< _Tp >::at_least | ( | int32_t | n | ) | const [inline] |
| n | minimum count. |
| _Tp* ref_ptr< _Tp >::get | ( | ) | const [inline] |
Dereference pointer to reference counted object.
| bool ref_ptr< _Tp >::is_empty | ( | ) | const [inline] |
Check if reference pointer refers to an object or whether it has been assigned a null object.
| bool ref_ptr< _Tp >::is_only | ( | ) | const [inline] |
| _Tp& ref_ptr< _Tp >::operator* | ( | ) | const [inline] |
Dereference reference counted object.
| _Tp* ref_ptr< _Tp >::operator-> | ( | ) | const [inline] |
Dereference pointer to reference counted object.
Assignment Operator.
Assigns reference pointer to new object.
Equality Operator.
| void ref_ptr< _Tp >::release | ( | ) | const [inline] |
Release reference on object.
The reference pointers underlying object is set to null, and the former object is destructed if necessary.