scim 1.4.18
scim::Pointer< T > Class Template Reference

Smart pointer template class. More...

#include <scim_pointer.h>

Public Member Functions

Constructors
 Pointer (T *object=0)
 
 Pointer (const Pointer &src)
 
template<typename T1 >
 Pointer (const Pointer< T1 > &src)
 
 ~Pointer ()
 
Pointeroperator= (T *object)
 
Pointeroperator= (const Pointer &src)
 
template<typename T1 >
Pointeroperator= (const Pointer< T1 > &src)
 
Accessors
Toperator* () const
 
Toperator-> () const
 
 operator T* () const
 
Tget () const
 
bool null () const
 Returns true if the Pointer has no dumb pointer.
 
Methods
Trelease ()
 
void reset (T *object=0)
 

Friends

template<typename T1 , typename T2 >
bool operator== (const Pointer< T1 > &t1, const Pointer< T2 > &t2)
 

Detailed Description

template<typename T>
class scim::Pointer< T >

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.

Constructor & Destructor Documentation

◆ Pointer() [1/3]

template<typename T >
scim::Pointer< T >::Pointer ( T * object = 0)
inline

Construct a new smart pointer.

Parameters
object- a pointer to an object allocated on the heap.


Initialize a new Pointer with any dumb pointer.

Referenced by scim::Pointer< T >::release().

◆ Pointer() [2/3]

template<typename T >
scim::Pointer< T >::Pointer ( const Pointer< T > & src)
inline

Copy constructor.

Parameters
src- a reference to a smart pointer.


Initialize a new Pointer with any compatible Pointer.

References scim::Pointer< T >::get().

◆ Pointer() [3/3]

template<typename T >
template<typename T1 >
scim::Pointer< T >::Pointer ( const Pointer< T1 > & src)
inline

Copy constructor.

Parameters
src- a Pointer to type T1 where T1 is derived from T.


Initialize a new Pointer of type T from a Pointer of type T1, only if T1 is derived from T.

References scim::Pointer< T >::get().

◆ ~Pointer()

template<typename T >
scim::Pointer< T >::~Pointer ( )
inline

Destructor. Decreases the object reference count.

Member Function Documentation

◆ operator=() [1/3]

template<typename T >
Pointer & scim::Pointer< T >::operator= ( T * object)
inline

Assignment operator.

Parameters
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.

◆ operator=() [2/3]

template<typename T >
Pointer & scim::Pointer< T >::operator= ( const Pointer< T > & src)
inline

Assignment operator.

Parameters
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.

References scim::Pointer< T >::get().

◆ operator=() [3/3]

template<typename T >
template<typename T1 >
Pointer & scim::Pointer< T >::operator= ( const Pointer< T1 > & src)
inline

Assignment operator.

Parameters
src- a Pointer to type T1 where T1 is derived from T.


Releases the current dumb pointer, if any and assigns the dumb pointer of type T1 managed by src to this Pointer as a dumb pointer of type T, only if T1 is derived from T. The reference count is incremented.

References scim::Pointer< T >::get().

◆ operator*()

template<typename T >
T & scim::Pointer< T >::operator* ( ) const
inline

Dereference operator.

Returns
a reference to the object pointed to by the dumb pointer.

References scim::Pointer< T >::get().

◆ operator->()

template<typename T >
T * scim::Pointer< T >::operator-> ( ) const
inline

Member selection operator.

Returns
the dumb pointer.

References scim::Pointer< T >::get().

◆ operator T*()

template<typename T >
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().

◆ get()

◆ null()

template<typename T >
bool scim::Pointer< T >::null ( ) const
inline

Returns true if the Pointer has no dumb pointer.

◆ release()

template<typename T >
T * scim::Pointer< T >::release ( )
inline

Releases the dumb pointer.

Returns
the regular C pointer previously managed by the 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.

References scim::Pointer< T >::Pointer().

◆ reset()

template<typename T >
void scim::Pointer< T >::reset ( T * object = 0)
inline

Sets a new dumb pointer for the Pointer to manage.

Parameters
object- the new dumb pointer.


Releases the current dumb pointer, if any, and assigns object to the Pointer, incrementing its reference count.

Friends And Related Symbol Documentation

◆ operator==

template<typename T >
template<typename T1 , typename T2 >
bool operator== ( const Pointer< T1 > & t1,
const Pointer< T2 > & t2 )
friend

Compares two Pointers.

Returns
true if both Pointers manage to same dumb pointer.

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