H3DUtil::AutoRef< NodeType > Class Template Reference

The AutoRef class is similar to the auto_ptr class, but it requires that the pointer to Node or a subclass of Node. More...

#include <H3DUtil/AutoRef.h>

List of all members.

Public Types

typedef NodeType element_type
 The type of the encapsulated Node.

Public Member Functions

 AutoRef (NodeType *n=0) throw ()
 Constructor.
 AutoRef (const AutoRef< NodeType > &ar) throw ()
 Copy constructor.
template<class Y >
 AutoRef (const AutoRef< Y > &ar) throw ()
 Copy constructor from other type of AutoRef.
AutoRef< NodeType > & operator= (const AutoRef< NodeType > &ar) throw ()
 Assignment operator.
template<class Y >
AutoRef< NodeType > & operator= (const AutoRef< Y > &ar) throw ()
 Assignment operator for other type of AutoRef.
NodeType & operator* () const throw ()
 Returns what the encapsulated Node * points to.
NodeType * operator-> () const throw ()
 Returns the encapsulated Node pointer.
NodeType * get () const throw ()
 Returns the encapsulated Node pointer.
void reset (NodeType *p=0) throw ()
 Change the Node pointer that is encapsulated.

Protected Member Functions

virtual void ref (NodeType *n)
 This function is called when a Node * is to be held by the AutoRef.
virtual void unref (NodeType *n)
 This function is called when a Node * is released by the AutoRef.


Detailed Description

template<class NodeType>
class H3DUtil::AutoRef< NodeType >

The AutoRef class is similar to the auto_ptr class, but it requires that the pointer to Node or a subclass of Node.

It will keep a reference to the Node pointer it encapsulates, i.e. ref() will be called. When destructed the AutoRef does not delete the pointer, but instead unreferences the Node (if this causes the reference count for the Node to go down to 0 then it will be deleted though).


Member Function Documentation

template<class NodeType >
virtual void H3DUtil::AutoRef< NodeType >::ref ( NodeType *  n  )  [inline, protected, virtual]

This function is called when a Node * is to be held by the AutoRef.

It increments the reference counter of the Node by calling the ref() function. Subclasses can override this function in order to get specialized behaviour.

Parameters:
n The node that is to be held by the AutoRef

Referenced by H3DUtil::AutoRef< BBPrimitiveTree >::AutoRef(), and H3DUtil::AutoRef< BBPrimitiveTree >::reset().

template<class NodeType >
void H3DUtil::AutoRef< NodeType >::reset ( NodeType *  p = 0  )  throw () [inline]

Change the Node pointer that is encapsulated.

Will cause an unref on the current Node * and a ref on the new.

Parameters:
p The new Node pointer to encapsulate.

Referenced by H3DUtil::AutoRef< BBPrimitiveTree >::AutoRef(), and H3DUtil::AutoRef< BBPrimitiveTree >::operator=().

template<class NodeType >
virtual void H3DUtil::AutoRef< NodeType >::unref ( NodeType *  n  )  [inline, protected, virtual]

This function is called when a Node * is released by the AutoRef.

It decrements the reference counter of the Node by calling the unref() function. Subclasses can override this function in order to get specialized behaviour.

Parameters:
n The node being released by the AutoRef.

Referenced by H3DUtil::AutoRef< BBPrimitiveTree >::reset().


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

Generated on Fri Nov 7 10:23:44 2008 for H3DUtil by  doxygen 1.5.7