Crystal Space: csWeakRef< T > Class Template Reference (Crystal Space Public API Reference)

| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# csWeakRef< T > Class Template Reference

A weak reference. More...

`#include <csutil/weakref.h>`

List of all members.

## Public Member Functions
| csWeakRef (const csPtr< T > &newobj)
| Construct a weak reference from a csPtr.
| csWeakRef (csWeakRef const &other)
| Weak pointer copy constructor.
| csWeakRef (csRef< T > const &newobj)
| Construct a weak reference from a csRef<>.
| csWeakRef (T *newobj)
| Construct a weak reference from a normal pointer.
| csWeakRef ()
| Construct an empty weak reference.
bool | IsValid () const
| Weak pointer validity check.
T & | operator * () const
| Dereference underlying object.
| operator T * () const
| Cast weak reference to a pointer to the underlying object.
T * | operator-> () const
| Dereference underlying object.
csWeakRef & | operator= (csWeakRef const &other)
| Assign another object to this weak reference.
csWeakRef & | operator= (csPtr< T > newobj)
| Assign a csPtr reference to this weak reference.
csWeakRef & | operator= (csRef< T > const &newobj)
| Assign a csRef<> to this weak reference.
csWeakRef & | operator= (T *newobj)
| Assign a raw object reference to this weak reference.
| ~csWeakRef ()
| Weak pointer destructor.
## Friends
bool | operator!= (T *obj, const csWeakRef &r1)
| Test if object pointed to by reference is different from obj.
bool | operator!= (const csWeakRef &r1, T *obj)
| 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 different object.
bool | operator== (T *obj, const csWeakRef &r1)
| Test if object pointed to by reference is same as obj.
bool | operator== (const csWeakRef &r1, T *obj)
| Test if object pointed to by reference is same as obj.
bool | operator== (const csWeakRef &r1, const csWeakRef &r2)
| Test if the two references point to same object.

## Detailed Description

### template<class T>
class csWeakRef< T >

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:

- AddRefOwner()
- RemoveRefOwner()

Definition at line 46 of file weakref.h.

## Constructor & Destructor Documentation

template<class T>

csWeakRef< T >::csWeakRef | ( |  | ) | `[inline]`

Construct an empty weak reference.

Definition at line 77 of file weakref.h.

template<class T>

csWeakRef< T >::csWeakRef | ( | T * | newobj | ) | `[inline]`

Construct a weak reference from a normal pointer.

Definition at line 82 of file weakref.h.

template<class T>

csWeakRef< T >::csWeakRef | ( | csRef< T > const & | newobj | ) | `[inline]`

Construct a weak reference from a csRef<>.

Definition at line 91 of file weakref.h.

template<class T>

csWeakRef< T >::csWeakRef | ( | csWeakRef< T > const & | other | ) | `[inline]`

Weak pointer copy constructor.

Definition at line 100 of file weakref.h.

template<class T>

csWeakRef< T >::csWeakRef | ( | const csPtr< T > & | newobj | ) | `[inline]`

Construct a weak reference from a csPtr.

This will put the object in the weak reference and then it will release the reference.

Definition at line 109 of file weakref.h.

template<class T>

csWeakRef< T >::~csWeakRef | ( |  | ) | `[inline]`

Weak pointer destructor.

Definition at line 119 of file weakref.h.

## Member Function Documentation

template<class T>

bool csWeakRef< T >::IsValid | ( |  | ) | const`[inline]`

Weak pointer validity check.

Returns true if weak reference is pointing at an actual object, otherwise returns false.

Definition at line 224 of file weakref.h.

template<class T>

T& csWeakRef< T >::operator * | ( |  | ) | const`[inline]`

Dereference underlying object.

Definition at line 217 of file weakref.h.

template<class T>

csWeakRef< T >::operator T * | ( |  | ) | const`[inline]`

Cast weak reference to a pointer to the underlying object.

Definition at line 213 of file weakref.h.

template<class T>

T* csWeakRef< T >::operator-> | ( |  | ) | const`[inline]`

Dereference underlying object.

Definition at line 209 of file weakref.h.

template<class T>

csWeakRef& csWeakRef< T >::operator= | ( | csWeakRef< T > const & | other | ) | `[inline]`

Assign another object to this weak reference.

Definition at line 171 of file weakref.h.

template<class T>

csWeakRef& csWeakRef< T >::operator= | ( | csPtr< T > | newobj | ) | `[inline]`

Assign a csPtr reference to this weak reference.

This will cause a DecRef() on the pointer.

Definition at line 156 of file weakref.h.

template<class T>

csWeakRef& csWeakRef< T >::operator= | ( | csRef< T > const & | newobj | ) | `[inline]`

Assign a csRef<> to this weak reference.

Definition at line 141 of file weakref.h.

template<class T>

csWeakRef& csWeakRef< T >::operator= | ( | T * | newobj | ) | `[inline]`

Assign a raw object reference to this weak reference.

Definition at line 127 of file weakref.h.

Referenced by csWeakRef< csEventQueue >::operator=().

## Friends And Related Function Documentation

template<class T>

bool operator!= | ( | T * | obj,
|  | const csWeakRef< T > & | r1 |
| ) |  |  | `[friend]`

Test if object pointed to by reference is different from obj.

Definition at line 203 of file weakref.h.

template<class T>

bool operator!= | ( | const csWeakRef< T > & | r1,
|  | T * | obj |
| ) |  |  | `[friend]`

Test if object pointed to by reference is different from obj.

Definition at line 193 of file weakref.h.

template<class T>

bool operator!= | ( | const csWeakRef< T > & | r1,
|  | const csWeakRef< T > & | r2 |
| ) |  |  | `[friend]`

Test if the two references point to different object.

Definition at line 183 of file weakref.h.

template<class T>

bool operator== | ( | T * | obj,
|  | const csWeakRef< T > & | r1 |
| ) |  |  | `[friend]`

Test if object pointed to by reference is same as obj.

Definition at line 198 of file weakref.h.

template<class T>

bool operator== | ( | const csWeakRef< T > & | r1,
|  | T * | obj |
| ) |  |  | `[friend]`

Test if object pointed to by reference is same as obj.

Definition at line 188 of file weakref.h.

template<class T>

bool operator== | ( | const csWeakRef< T > & | r1,
|  | const csWeakRef< T > & | r2 |
| ) |  |  | `[friend]`

Test if the two references point to same object.

Definition at line 178 of file weakref.h.

The documentation for this class was generated from the following file:

- csutil/weakref.h