Gyoto
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gyoto::SmartPointer< T > Class Template Reference

Pointers performing reference counting. More...

Public Member Functions

 SmartPointer (T *orig=NULL)
 Constructor from a standard pointer-to-class.
 SmartPointer (const SmartPointer< T > &orig)
 Copy constructor from same type.
template<class U >
 SmartPointer (const SmartPointer< U > &orig)
 Copy constructor from compatible type (used for casting)
T & operator* ()
 Dereference operator "*".
const T & operator* () const
 Dereference operator "*".
T * operator-> ()
 Dereference operator "->".
T * operator-> () const
bool operator== (const SmartPointer< T > &right)
 Comparison operator between two SmartPointer of same kind.
bool operator!= (const SmartPointer< T > &right)
 Comparison operator between two SmartPointer of same kind.
SmartPointer< T > & operator= (SmartPointer< T > &right)
 Copy a SmartPointer to another (already defined) SmartPointer of same kind.
SmartPointer< T > & operator= (T *right)
 Copy a normal pointer to an (already defined) SmartPointer of same kind.
 operator T * ()
 Cast SmartPointer to normal pointer.
 operator const T * ()
 operator bool ()
 Check whether SmartPointer is valid.
bool operator! () const
 Check whether SmartPointer is valid.
const T * operator() () const
 Get standard, non-smart pointer to object. Use with care.

Private Member Functions

void decRef ()
 Decrement the reference counter. Warning: don't mess with it.

Private Attributes

T * obj
 Real pointer, don't mess with it.

Detailed Description

template<class T>
class Gyoto::SmartPointer< T >

Pointers performing reference counting.

Pointee must inherit from class SmartPointee.

To create an object and a SmartPointer pointing to it:

SmartPointer<Gyoto::Metric::Generic> ObjPtr (new Gyoto::Metric(...))

Constructor & Destructor Documentation

template<class T>
Gyoto::SmartPointer< T >::SmartPointer ( T *  orig = NULL)
inline

Constructor from a standard pointer-to-class.

Parameters
obj: a pointer to an instance of class T, created using new T().

Example:

SmartPointer<Gyoto::Metric::Generic> ObjPtr (new Gyoto::Metric(...)) // create SmartPointer ObjPtr
template<class T>
Gyoto::SmartPointer< T >::SmartPointer ( const SmartPointer< T > &  orig)
inline

Copy constructor from same type.

Parameters
orig: a SmartPointer to an instance of class T

Example:

SmartPointer<Gyoto::Metric::Generic> ObjPtr (new Gyoto::Metric(...)) // create SmartPointer ObjPtr
SmartPointer<Gyoto::Metric::Generic> ObjPtr2 = ObjPtr // create SmartPointer ObjPtr2

ObjPtr and ObjPtr2 point to the same instance of class T. Copying increments the reference counter.

template<class T>
template<class U >
Gyoto::SmartPointer< T >::SmartPointer ( const SmartPointer< U > &  orig)
inline

Copy constructor from compatible type (used for casting)

Parameters
orig: a SmartPointer to an instance of another class U

Example: MetricPtr is a SmartPoiter<Metric>, but really points to an instance of the child class Gyoto::Kerr:

SmartPointer<Gyoto::Kerr> KerrPtr (MetricPtr)

MetricPtr and KerrPtr point to the same instance of class Kerr. The methods specific to class Kerr are available only to KerrPtr.

Member Function Documentation

template<class T>
Gyoto::SmartPointer< T >::operator bool ( )
inline

Check whether SmartPointer is valid.

Returns
0 if SmartPointer is NULL, 1 if valid.
template<class T>
bool Gyoto::SmartPointer< T >::operator! ( ) const
inline

Check whether SmartPointer is valid.

Returns
1 if SmartPointer is NULL, 0 if valid.
template<class T>
const T* Gyoto::SmartPointer< T >::operator() ( ) const
inline

Get standard, non-smart pointer to object. Use with care.

This public method is needed to cast from a SmartPointer flavor to another. It should almost certainly never be used in user code, except perhaps for debugging purposes.

Returns
usual pointer to object, T*.
template<class T>
T& Gyoto::SmartPointer< T >::operator* ( )
inline

Dereference operator "*".

Returns
address of the pointed-to-object
template<class T>
const T& Gyoto::SmartPointer< T >::operator* ( ) const
inline

Dereference operator "*".

Returns
address of the pointed-to-object
template<class T>
T* Gyoto::SmartPointer< T >::operator-> ( )
inline

Dereference operator "->".

Access to the pointed-to-object's members.


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