A templated smart pointer class. More...
#include <vbl_fwd.h>
Public Member Functions | |
| vbl_smart_ptr () | |
| template<class Y > | |
| vbl_smart_ptr (vbl_smart_ptr< Y > const &p) | |
| vbl_smart_ptr (vbl_smart_ptr< T > const &p) | |
| vbl_smart_ptr (T *p) | |
| ~vbl_smart_ptr () | |
| vbl_smart_ptr< T > & | operator= (vbl_smart_ptr< T > const &r) |
| Assignment. More... | |
| vbl_smart_ptr< T > & | operator= (T *r) |
| operator bool () const | |
| Cast to bool. More... | |
| bool | operator! () const |
| Inverse boolean value. More... | |
| T & | operator * () const |
| Dereferencing the pointer. More... | |
| T * | operator -> () const |
| These methods all return the raw/dumb pointer. More... | |
| T * | ptr () const |
| These methods all return the raw/dumb pointer. More... | |
| T * | as_pointer () const |
| These methods all return the raw/dumb pointer. More... | |
| void | unprotect () |
| Used for breaking circular references (see above). More... | |
| bool | is_protected () const |
| Is this smart pointer responsible for the object being pointed to. More... | |
| bool | operator== (T const *p) const |
| Do a shallow equality. More... | |
| bool | operator!= (T const *p) const |
| Do a shallow inequality. More... | |
| bool | operator== (vbl_smart_ptr< T >const &p) const |
| Do a shallow equality. More... | |
| bool | operator!= (vbl_smart_ptr< T >const &p) const |
| Do a shallow inequality. More... | |
| bool | operator< (vbl_smart_ptr< T >const &p) const |
| bool | operator> (vbl_smart_ptr< T >const &p) const |
| bool | operator<= (vbl_smart_ptr< T >const &p) const |
| bool | operator>= (vbl_smart_ptr< T >const &p) const |
Static Private Member Functions | |
| static void | ref (T *p) |
| static void | unref (T *p) |
Private Attributes | |
| bool | protected_ |
| The protected flag says whether or not the object held will be unref()fed when the smart pointer goes out of scope. More... | |
| T * | ptr_ |
| Pointer to object, or 0. More... | |
A templated smart pointer class.
This class requires that the class being templated over has the following signatures (methods) :
By default, the vbl_smart_ptr<T> will ref() the object given to it upon construction and unref() it upon destruction. In some cases, however, it is useful to cause an unref() immediately and to avoid an unref() in the constructor. For example, in the cyclic data structure
The refcounts on A, B, C, D, E are 2, 1, 1, 1, 1 so when 'start' goes out of scope, the refcount will be 1, 1, 1, 1, 1 and therefore the ring never gets deleted. Calling unprotect() on 'E' solves this as it effectively transfers ownership of 'A' from 'E' to 'start'.
Although unprotect() can be handy, it should be used with care. It can sometimes (but not always) be avoided by assigning 0 (null pointer) to one of the nodes in the ring.
See also vbl_ref_count
|
inline |
Definition at line 65 of file vbl_smart_ptr.h.
|
inline |
Definition at line 69 of file vbl_smart_ptr.h.
|
inline |
Definition at line 72 of file vbl_smart_ptr.h.
|
inline |
Definition at line 75 of file vbl_smart_ptr.h.
|
inline |
Definition at line 78 of file vbl_smart_ptr.h.
|
inline |
These methods all return the raw/dumb pointer.
WARNING : Do not add an automatic cast to T*. This is intrinsically incorrect as you loose the smartness! In cases where you really need the pointer, it is better to be explicit about it and use one of the methods.
Definition at line 143 of file vbl_smart_ptr.h.
|
inline |
Is this smart pointer responsible for the object being pointed to.
If this value is false, the object does not have to save it.
Definition at line 154 of file vbl_smart_ptr.h.
|
inline |
Dereferencing the pointer.
Definition at line 129 of file vbl_smart_ptr.h.
|
inline |
These methods all return the raw/dumb pointer.
Definition at line 132 of file vbl_smart_ptr.h.
|
inline |
Cast to bool.
Definition at line 123 of file vbl_smart_ptr.h.
|
inline |
Inverse boolean value.
Definition at line 126 of file vbl_smart_ptr.h.
|
inline |
Do a shallow inequality.
Do the smart pointers not point to the same object.
Definition at line 175 of file vbl_smart_ptr.h.
|
inline |
Do a shallow inequality.
Do the smart pointers not point to the same object.
Definition at line 183 of file vbl_smart_ptr.h.
|
inline |
Definition at line 184 of file vbl_smart_ptr.h.
|
inline |
Definition at line 186 of file vbl_smart_ptr.h.
|
inline |
Assignment.
Definition at line 94 of file vbl_smart_ptr.h.
|
inline |
Definition at line 99 of file vbl_smart_ptr.h.
|
inline |
Do a shallow equality.
Do they point to the same object.
Definition at line 171 of file vbl_smart_ptr.h.
|
inline |
Do a shallow equality.
Do they point to the same object.
Definition at line 179 of file vbl_smart_ptr.h.
|
inline |
Definition at line 185 of file vbl_smart_ptr.h.
|
inline |
Definition at line 187 of file vbl_smart_ptr.h.
|
inline |
These methods all return the raw/dumb pointer.
Definition at line 135 of file vbl_smart_ptr.h.
|
staticprivate |
Definition at line 15 of file vbl_smart_ptr.hxx.
|
inline |
Used for breaking circular references (see above).
Definition at line 146 of file vbl_smart_ptr.h.
|
staticprivate |
Definition at line 22 of file vbl_smart_ptr.hxx.
|
private |
The protected flag says whether or not the object held will be unref()fed when the smart pointer goes out of scope.
Definition at line 59 of file vbl_smart_ptr.h.
|
private |
Pointer to object, or 0.
Definition at line 62 of file vbl_smart_ptr.h.
1.8.15