#include <gauge3d/object.h>
Inherits GAUGE3D::GSmartPointerBase.
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 |
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:
|
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. |
|
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. |