scim
1.4.9
|
Smart pointer template class. More...
#include <scim_pointer.h>
Public Member Functions | |
T & | operator* () const |
T * | operator-> () const |
operator T * () const | |
T * | get () const |
bool | null () const |
Returns true if the Pointer has no dumb pointer. | |
T * | release () |
void | reset (T *object=0) |
Constructors | |
Pointer (T *object=0) | |
Pointer (Pointer &src) | |
template<typename T1 > | |
Pointer (const Pointer< T1 > &src) | |
~Pointer () | |
Pointer & | operator= (T *object) |
Pointer & | operator= (const Pointer &src) |
template<typename T1 > | |
Pointer & | operator= (const Pointer< T1 > &src) |
Friends | |
template<typename T1 , typename T2 > | |
bool | operator== (const Pointer< T1 > &t1, const Pointer< T2 > &t2) |
Smart pointer template class.
Pointer is a standard auto_ptr-like smart pointer for managing heap allocated reference counted objects. T must be a class derived from scim::ReferencedObject.
scim::Pointer< T >::Pointer | ( | T * | object = 0 | ) | [inline] |
Construct a new smart pointer.
object | - a pointer to an object allocated on the heap. |
Initialize a new Pointer with any dumb pointer.
scim::Pointer< T >::Pointer | ( | Pointer< T > & | src | ) | [inline] |
scim::Pointer< T >::Pointer | ( | const Pointer< T1 > & | src | ) | [inline] |
scim::Pointer< T >::~Pointer | ( | ) | [inline] |
Destructor. Decreases the object reference count.
Pointer& scim::Pointer< T >::operator= | ( | T * | object | ) | [inline] |
Assignment operator.
object | - a pointer to an object allocated on the heap. |
Releases the current dumb pointer, if any and assigns object to this Pointer, incrementing its reference count.
Pointer& scim::Pointer< T >::operator= | ( | const Pointer< T > & | src | ) | [inline] |
Assignment operator.
src | - a reference to a smart pointer. |
Releases the current dumb pointer, if any and assigns the dumb pointer managed by src to this Pointer, incrementing its reference count.
Pointer& scim::Pointer< T >::operator= | ( | const Pointer< T1 > & | src | ) | [inline] |
T& scim::Pointer< T >::operator* | ( | ) | const [inline] |
Dereference operator.
T* scim::Pointer< T >::operator-> | ( | ) | const [inline] |
Member selection operator.
scim::Pointer< T >::operator T * | ( | ) | const [inline] |
Conversion operator. Converts a Pointer into its dumb pointer: the C pointer it manages. Normally it is considered pretty evil to mix smart and regular pointers. In scim you can safely if you just follow the reference counting rules for each of them. You can never call delete on Pointer either because you don't call delete on scim objects; you call unref().
T* scim::Pointer< T >::get | ( | ) | const [inline] |
Returns the dumb pointer; the regular C pointer managed by the Pointer.
Referenced by scim::cast_const(), scim::cast_dynamic(), scim::cast_static(), scim::Pointer< IMEngineFactoryBase >::operator=(), scim::Pointer< IMEngineFactoryBase >::Pointer(), and scim::Node::slot().
bool scim::Pointer< T >::null | ( | ) | const [inline] |
Returns true if the Pointer has no dumb pointer.
T* scim::Pointer< T >::release | ( | ) | [inline] |
Releases the dumb pointer.
Before releasing the dumb pointer its reference count is incremented to prevent it being destroyed. You must call unref() on the pointer to prevent a memory leak.
void scim::Pointer< T >::reset | ( | T * | object = 0 | ) | [inline] |
bool operator== | ( | const Pointer< T1 > & | t1, |
const Pointer< T2 > & | t2 | ||
) | [friend] |
Compares two Pointers.