Jive reference manual
List of all members | Public Member Functions | Related Functions
jem::WeakRef< T > Class Template Reference

Provides `safe' acces to a collectable object without preventing the deletion of that object. More...

#include <jem/base/WeakRef.h>

Public Member Functions

 WeakRef ()
 Constructs a WeakRef that does not point to any object. More...
 
 WeakRef (const Ref< T > &rhs)
 Creates a WeakRef that points to an existing object. More...
 
 WeakRef (const WeakRef &rhs)
 Creates a copy of another WeakRef. More...
 
WeakRefoperator= (const WeakRef &rhs)
 Copies another WeakRef. More...
 
Ref< T > get () const
 Returns the object this WeakRef is pointing to. More...
 
void swap (WeakRef &rhs)
 Interchanges two WeakRef objects. More...
 

Related Functions

(Note that these are not member functions.)

template<class T >
void swap (WeakRef< T > &lhs, WeakRef< T > &rhs)
 Interchanges two WeakRef objects. More...
 

Detailed Description

template<class T>
class jem::WeakRef< T >

Like the template class Ref, the class WeakRef acts as a pointer to a collectable object of type T. Unlike a Ref, however, a WeakRef does not prevent the deletion of a collectable object. This means that if a collectable object can be reached only through one or more WeakRef instances, the collectable object will eventually be deleted.

A WeakRef is safe in the sense that it will return a NIL Ref instance when the collectable object no longer exists.

See also
Ref.

Constructor & Destructor Documentation

template<class T>
jem::WeakRef< T >::WeakRef ( )

Constructs a WeakRef that does not point to any object.

Postcondition
this->get() == NIL
template<class T>
jem::WeakRef< T >::WeakRef ( const Ref< T > &  rhs)

Creates a WeakRef that points to the same object as the Ref rhs.

Parameters
rhs- a Ref object.
Postcondition
this->get() == rhs
template<class T>
jem::WeakRef< T >::WeakRef ( const WeakRef< T > &  rhs)

Creates a WeakRef that points to the same object as the WeakRef rhs.

Parameters
rhs- the WeakRef to be copied.
Postcondition
this->get() == rhs.get()

Member Function Documentation

template<class T>
WeakRef& jem::WeakRef< T >::operator= ( const WeakRef< T > &  rhs)

Copies the WeakRef rhs to this WeakRef.

Parameters
rhs- the WeakRef to be copied.
Returns
*this
Postcondition
this->get() == rhs.get()
template<class T>
Ref<T> jem::WeakRef< T >::get ( ) const

Returns a Ref that is either NIL or that points to the collectable object this WeakRef is pointing to.

Returns
A Ref object pointing to the object this WeakRef is pointing to.
template<class T>
void jem::WeakRef< T >::swap ( WeakRef< T > &  rhs)

Interchanges two WeakRef objects. This function is equivalent with:

WeakRef<T> tmp( *this );
(*this) = rhs;
rhs = tmp;
Parameters
rhs- the WeakRef with which this WeakRef should be swapped.

Friends And Related Function Documentation

template<class T >
void swap ( WeakRef< T > &  lhs,
WeakRef< T > &  rhs 
)
related

Swaps two WeakRef objects. This function is equivalent with: lhs.swap( rhs ).

Parameters
lhs- a WeakRef object.
rhs- another WeakRef object.