|
|
The cref_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.
In contrast to the ref_ptr class, accessing the pointer requires two levels of indirection as the pointer is stored in the same table as the counter. This is a performance hit, but means each cref_ptr only consumes 4-bytes.
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.
cref_ptr (_Tp* __p = 0)
| cref_ptr |
Construct a compact reference pointer for object.
Parameters:
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. |
cref_ptr (const cref_ptr& __r)
| cref_ptr |
Copy Constructor
Constructs a reference pointer for object. Raises reference count associated with object by 1.
cref_ptr& operator= (const cref_ptr& __r)
| operator= |
Assignment Operator
Assigns reference pointer to new object.
~cref_ptr ()
| ~cref_ptr |
Destruct reference pointer instance and lower reference count on object being tracked. The object being tracked will be deleted if the reference count falls to zero because of the destruction of the reference pointer.
inline _Tp* get ()
| get |
[const]
Dereference pointer to reference counted object.
Returns: pointer to object.
inline _Tp& operator* ()
| operator* |
[const]
Dereference reference counted object.
Returns: reference to object.
inline _Tp* operator-> ()
| operator-> |
[const]
Dereference pointer to reference counted object.
Returns: pointer to object.
inline bool operator== (const cref_ptr& rp)
| operator== |
[const]
Equality Operator
Returns: true if reference pointers refer to same object.
inline bool is_empty ()
| is_empty |
[const]
Check if reference pointer refers to an object or whether it has been assigned a null object.
Returns: true if reference pointer refers to a null object.
inline bool is_only ()
| is_only |
[const]
Returns: true if reference pointer represents only reference to object.
bool at_least (int32_t n)
| at_least |
[const]
Parameters:
n | minimum count. |
Returns: true if there are at least n references to object.
inline void release ()
| release |
[const]
Release reference on object. The reference pointers underlying object is set to null, and the former object is destructed if necessary.