CXXR (C++ R) API
Public Member Functions
CXXR::GCRoot< T > Class Template Reference

Smart pointer to protect a GCNode from garbage collection. More...

#include <GCRoot.h>

Inheritance diagram for CXXR::GCRoot< T >:
Inheritance graph
[legend]
Collaboration diagram for CXXR::GCRoot< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GCRoot (T *node=0)
 GCRoot (const GCRoot &source)
 Copy constructor.
GCRootoperator= (const GCRoot &source)
GCRootoperator= (T *node)
T * operator-> () const
 Access member via encapsulated pointer.
T & operator* () const
 Dereference the encapsulated pointer.
 operator T * () const
 Implicit conversion to encapsulated pointer type.
T * get () const
 Access the encapsulated pointer.

Additional Inherited Members

- Static Public Member Functions inherited from CXXR::GCRootBase
static void visitRoots (GCNode::const_visitor *v)
 Conduct a const visitor to all 'root' GCNode objects.
- Protected Member Functions inherited from CXXR::GCRootBase
 GCRootBase (const GCNode *node)
 Primary constructor.
 GCRootBase (const GCRootBase &source)
 Copy constructor.
GCRootBaseoperator= (const GCRootBase &source)
void redirect (const GCNode *node)
 Change the node protected by this GCRootBase.
const GCNodeptr () const
 Access the encapsulated pointer.

Detailed Description

template<class T = RObject>
class CXXR::GCRoot< T >

Smart pointer to protect a GCNode from garbage collection.

This class encapsulates a pointer to an object of a type derived from GCNode. For as long as the GCRoot object exists, the GCNode that it points to will not be garbage collected.

This class performs a similar function to GCStackRoot, but is intended for variables that are not allocated on the stack. Unlike GCStackRoot objects, there is no requirement that GCRoot objects be destroyed in the reverse order of their creation; the price of this is that there is a slightly greater time overhead to construction and destruction.

It is not recommended to declare a GCRoot (or indeed any object requiring non-trivial construction) at file or namespace scope in circumstances where the order of initialisation of data in different source files may be an issue. See the way in which Environment::s_base is declared and initialised in Environment.cpp for a preferable approach.

Template Parameters:
TGCNode or a type publicly derived from GCNode. This may be qualified by const, so for example a const String* may be encapsulated in a GCRoot using the type GCRoot<const String>.

Constructor & Destructor Documentation

template<class T = RObject>
CXXR::GCRoot< T >::GCRoot ( T *  node = 0)
inlineexplicit
Parameters:
nodePointer the node to be pointed to, and protected from the garbage collector, or a null pointer.
template<class T = RObject>
CXXR::GCRoot< T >::GCRoot ( const GCRoot< T > &  source)
inline

Copy constructor.

The constructed GCRoot will protect the same GCNode as source. (There is probably no reason to use this constructor.)


Member Function Documentation

template<class T = RObject>
T* CXXR::GCRoot< T >::get ( ) const
inline

Access the encapsulated pointer.

Returns:
the pointer currently encapsulated by the node.
template<class T = RObject>
CXXR::GCRoot< T >::operator T * ( ) const
inline

Implicit conversion to encapsulated pointer type.

Returns:
the pointer currently encapsulated by the node. The pointer is of type T* const to prevent its use as an lvalue, the effect of which would probably not be what the programmer wanted.
template<class T = RObject>
T& CXXR::GCRoot< T >::operator* ( ) const
inline

Dereference the encapsulated pointer.

Returns:
a reference to the object pointed to by the encapsulated pointer. The effect is undefined if this object encapsulates a null pointer.
template<class T = RObject>
T* CXXR::GCRoot< T >::operator-> ( ) const
inline

Access member via encapsulated pointer.

Returns:
the pointer currently encapsulated by the node.
template<class T = RObject>
GCRoot& CXXR::GCRoot< T >::operator= ( const GCRoot< T > &  source)
inline

This will cause this GCRoot to protect the same GCNode as is protected by source. (There is probably no reason to use this method.)

template<class T = RObject>
GCRoot& CXXR::GCRoot< T >::operator= ( T *  node)
inline

This will cause this GCRoot to point to and protect node, instead of the node (if any) it currently points to and protects.

Parameters:
nodePointer to the GCNode that is now to be pointed to and protected from the garbage collector.

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