|
Jive reference manual
|
Provides `safe' access to a collectable object. More...
#include <jem/base/Ref.h>
Public Member Functions | |
| Ref () | |
Constructs a Ref with the value NIL. More... | |
| Ref (const Nil &nil) | |
Constructs a Ref with the value NIL. More... | |
| Ref (T *rhs) | |
Creates a Ref that points to an existing object. More... | |
| Ref (const Ref &rhs) | |
Constructs a copy of another Ref. More... | |
| Ref (const Ref< U > &rhs) | |
| Conversion constructor. More... | |
| Ref & | operator= (const Ref &rhs) |
Copies another Ref object. More... | |
| bool | operator== (const Ref &rhs) const |
Tests whether two Ref instances point two the same object. More... | |
| bool | operator== (const Nil &nil) const |
Tests whether this Ref does not point to an object. More... | |
| bool | operator!= (const Ref &rhs) const |
Tests whether two Ref instances do not point two the same object. More... | |
| bool | operator!= (const Nil &nil) const |
Tests whether this Ref points to an object. More... | |
| T * | operator-> () const |
Returns a pointer to the object that this Ref is pointing to. More... | |
| T & | operator* () const |
Returns a reference to the object that this Ref is pointing to. More... | |
| void | swap (Ref &rhs) |
Interchanges two Ref objects. More... | |
| Collectable * | getBase () const |
Returns a pointer to the Collectable subobject of the object this Ref is pointing to. More... | |
| T * | get () const |
Returns a pointer to the object that this Ref is pointing to. More... | |
Related Functions | |
(Note that these are not member functions.) | |
| template<class T , class A > | |
| Ref< T > | newInstance (const A &a) |
| Creates a collectable object of type T. More... | |
| template<class T , class A , class B > | |
| Ref< T > | newInstance (const A &a, const B &b) |
| Creates a collectable object of type T. More... | |
| template<class T , class A , class B , class C > | |
| Ref< T > | newInstance (const A &a, const B &b, const C &c) |
| Creates a collectable object of type T. More... | |
| template<class T , class A , class B , class C , class D > | |
| Ref< T > | newInstance (const A &a, const B &b, const C &c, const D &d) |
| Creates a collectable object of type T. More... | |
| template<class U , class T > | |
| Ref< U > | staticCast (const Ref< T > &r) |
| Mimics a static cast expression. More... | |
| template<class U , class T > | |
| Ref< U > | dynamicCast (const Ref< T > &r) |
| Mimics a dynamic cast expression. More... | |
| template<class U , class T > | |
| Ref< U > | checkedCast (const Ref< T > &r) |
| Mimics a dynamic cast expression and checks whether the cast succeeded. More... | |
| template<class T > | |
| void | swap (Ref< T > &lhs, Ref< T > &rhs) |
Interchanges two Ref objects. More... | |
The template class Ref encapsulates a pointer of type T* that points to a collectable object. Unlike a normal pointer, however, a Ref instance guarantees that the collectable object is not deleted. That is, the collectable object will not be deleted as long as it can be reached through one or more Ref instances.
A Ref that contains a NULL pointer is said to have the value NIL. To be precise, NIL is a pre-defined instance of the class Nil. Because several members of the Ref class have been overloaded for an argument of type Nil, one can use NIL as a special Ref object. Example:
A Ref can point to any object as long as the runtime type of the object is unambiguously derived from the Collectable class. This means that the type T does not have to be derived from the Collectable class. Example:
WeakRef. Creates a Ref that points to the collectable object rhs.
| rhs | - a pointer to an object of type T, or NULL. |
Collectable class.this->get() == rhsCollectable class. Creates a Ref that points to a subobject of the object pointed to by the Ref rhs. Example:
| rhs | - the Ref to be converted. |
this->get() == static_cast<T>( rhs.get() )explicit, it can be used as an implicit conversion constructor. | T* jem::Ref< T >::operator-> | ( | ) | const |
| T& jem::Ref< T >::operator* | ( | ) | const |
*get() this->get() != NULL | Collectable* jem::Ref< T >::getBase | ( | ) | const |
dynamic_cast<Collectable*>( this->get() )| T* jem::Ref< T >::get | ( | ) | const |
Ref is pointing to.
|
related |
Equivalent with: new T( a )
| a | - the argument to be passed to the constructor of type T. |
Ref pointing to the new object.
|
related |
Equivalent with: new T( a, b )
| a | - the first parameter to be passed to the constructor of type T. |
| b | - the second parameter to be passed to the constructor of type T. |
Ref pointing to the new object.
|
related |
Equivalent with: new T( a, b, c )
| a | - the first parameter to be passed to the constructor of type T. |
| b | - the second parameter to be passed to the constructor of type T. |
| c | - the third parameter to be passed to the constructor of type T. |
Ref pointing to the new object.
|
related |
Equivalent with: new T( a, b, c, d )
| a | - the first parameter to be passed to the constructor of type T. |
| b | - the second parameter to be passed to the constructor of type T. |
| c | - the third parameter to be passed to the constructor of type T. |
| d | - the fourth parameter to be passed to the constructor of type T. |
Ref pointing to the new object. Converts the Ref r, encapsulating a pointer of type T*, to a Ref encapsulating a pointer of type U* using a static cast expression.
| r | - the Ref that is to be converted. |
Ref that points to static_cast<U*>( r.get() ). staticCast<U>( r ).get() == static_cast<U*>( r.get() ) This function has the same effect as the dynamicCast function except that it throws an exception if the dynamic cast fails.
| r | - the Ref to be converted. |
dynamicCast<U>( r )| ClassCastException | - if the dynamic cast fails and r is not NIL. |