![]() |
Public API Reference |
![]() |
A weak reference. More...
#include <csutil/weakref.h>
Public Member Functions | |
csWeakRef () | |
Construct an empty weak reference. | |
csWeakRef (T *newobj) | |
Construct a weak reference from a normal pointer. | |
csWeakRef (csRef< T > const &newobj) | |
Construct a weak reference from a csRef<>. | |
csWeakRef (csWeakRef const &other) | |
Weak pointer copy constructor. | |
csWeakRef (const csPtr< T > &newobj) | |
Construct a weak reference from a csPtr. | |
uint | GetHash () const |
Return a hash value for this smart pointer. | |
bool | IsValid () const |
Weak pointer validity check. | |
operator T * () const | |
Cast weak reference to a pointer to the underlying object. | |
T & | operator* () const |
Dereference underlying object. | |
T * | operator-> () const |
Dereference underlying object. | |
csWeakRef & | operator= (T *newobj) |
Assign a raw object reference to this weak reference. | |
csWeakRef & | operator= (csRef< T > const &newobj) |
Assign a csRef<> to this weak reference. | |
csWeakRef & | operator= (csPtr< T > newobj) |
Assign a csPtr reference to this weak reference. | |
csWeakRef & | operator= (csWeakRef const &other) |
Assign another object to this weak reference. | |
~csWeakRef () | |
Weak pointer destructor. | |
Friends | |
bool | operator!= (const csWeakRef &r1, const csWeakRef &r2) |
Test if the two references point to different object. | |
bool | operator!= (const csWeakRef &r1, T *obj) |
Test if object pointed to by reference is different from obj. | |
bool | operator!= (T *obj, const csWeakRef &r1) |
Test if object pointed to by reference is different from obj. | |
bool | operator== (const csWeakRef &r1, const csWeakRef &r2) |
Test if the two references point to same object. | |
bool | operator== (const csWeakRef &r1, T *obj) |
Test if object pointed to by reference is same as obj. | |
bool | operator== (T *obj, const csWeakRef &r1) |
Test if object pointed to by reference is same as obj. |
A weak reference.
This is a reference to a reference counted object but in itself it doesn't increment the ref counter. As soon as the object is destroyed (i.e. the last REAL reference to it is removed) all weak references pointing to that object are cleared. This kind of reference is useful if you want to maintain some kind of cached objects that can safely be removed as soon as the last reference to it is gone.
Note: this class assumes that the T type implements at least the following functions:
csWeakRef< T >::operator T * | ( | ) | const [inline] |
T& csWeakRef< T >::operator* | ( | ) | const [inline] |
T* csWeakRef< T >::operator-> | ( | ) | const [inline] |
bool operator!= | ( | const csWeakRef< T > & | r1, |
T * | obj | ||
) | [friend] |
bool operator!= | ( | T * | obj, |
const csWeakRef< T > & | r1 | ||
) | [friend] |
bool operator== | ( | const csWeakRef< T > & | r1, |
T * | obj | ||
) | [friend] |
bool operator== | ( | T * | obj, |
const csWeakRef< T > & | r1 | ||
) | [friend] |