Main Page   Modules   Class Hierarchy   Compound List   Compound Members  

GAUGE3D::GSmartPointer Class Template Reference

A reference-counting smart pointer class. More...

#include <gauge3d/object.h>

Inherits GAUGE3D::GSmartPointerBase.

List of all members.

Public Methods

tType& operator[] (int index)const
 Array access for smart pointers that point to arrays.

 operator tType * ()const
 Cast to standard pointer.

Constructors and Destructors
 GSmartPointer ()
 Sets pointer to NULL.

 GSmartPointer (tType *object)
 Cast from regular pointer. More...

 GSmartPointer (const GSmartPointer &other)
 Copy constructor.

 GSmartPointer (const GSmartPointerBase &other)
 Cast constructor from smart pointers for other types. More...

 ~GSmartPointer ()
 Decrement reference count and delete if zero.

Assignment Operators
These work like you'd expect them to.

const GSmartPointer& operator= (const GSmartPointer &other)
const GSmartPointer& operator= (const GSmartPointerBase &other)
const GSmartPointer& operator= (tType *other)
Equality Tests
These work like you'd expect them to.

bool operator== (const GSmartPointer &other)const
bool operator== (const GSmartPointerBase &other)const
bool operator== (const tType *other)const
Dereferencing
These work like you'd expect them to.

tType& operator * ()
const tType& operator * ()const
tType* operator-> ()
const tType* operator-> ()const


Detailed Description

template<class tType> class GAUGE3D::GSmartPointer

A reference-counting smart pointer class.

GSmartPointer is a reference counting smart pointer class. It can point to any class derived from GObject. For each smart pointer pointing to an object, the object's reference count will be incremented. When the smart pointer is destroyed, the reference count will be decremented. When the count hits zero, the object will be deleted.

By using smart pointers, you can forget about who has ownership of an object and should therefore delete it when done. The object will be deleted automatically when it is done with.

In GAUGE, every class that is derived from GObject has an associated typedef'd smartpointer type. The smartpointer type is named after the object with the prefix 'p'. So, pGObject is a smart pointer to a GObject, and pGFile is a smart pointer to a GFile, etc.

Some important things to remember when using smart pointers:


Constructor & Destructor Documentation

template<class tType>
GAUGE3D::GSmartPointer<tType>::GSmartPointer<tType> ( tType * object ) [inline]
 

Cast from regular pointer.

WARNING: This can be dangerous. If you have both regular pointers and smart pointers pointing to the same object, and all the smart pointers are destroyed, the regular pointers will be left dangling, and could cause a program crash. Try to avoid using both regular and smart pointers to an object.

template<class tType>
GAUGE3D::GSmartPointer<tType>::GSmartPointer<tType> ( const GSmartPointerBase & other ) [inline]
 

Cast constructor from smart pointers for other types.

Note that type checking is not performed. If you cast to a type which the object isn't, you will not be warned. If you need to do dynamic casting, you must do it manually.


The documentation for this class was generated from the following file:
Generated at Tue Jan 30 17:07:34 2001 for gauge3d by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000