|
|
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.
ref_ptr (_Tp* __p = 0)
| ref_ptr |
Construct a 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. |
ref_ptr (const ref_ptr& __r)
| ref_ptr |
Copy Constructor
Constructs a reference pointer for object. Raises reference count associated with object by 1.
ref_ptr& operator= (const ref_ptr& __r)
| operator= |
Assignment Operator
Assigns reference pointer to new object.
~ref_ptr ()
| ~ref_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& 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 _Tp* get ()
| get |
[const]
Dereference pointer to reference counted object.
Returns: pointer to object.
inline bool operator== (const ref_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.
ref_ptr (_Tp* data, int32_t index)
| ref_ptr |
void ref (const ref_ptr* __r)
| ref |
[protected const]
void unref ()
| unref |
[protected const]
mutable _Tp* _M_ptr | _M_ptr |
[protected]
mutable int32_t _M_index | _M_index |
[protected]
template <typename _Tp>
ref_ptr (const ref_ptr<_Tp>& __r)
| ref_ptr |
[protected]