Smart pointer template class.
More...
#include <scim_pointer.h>
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.
◆ Pointer() [1/3]
Construct a new smart pointer.
- Parameters
-
object | - a pointer to an object allocated on the heap. <BR>Initialize a new Pointer with any dumb pointer. |
◆ Pointer() [2/3]
Copy constructor.
- Parameters
-
src | - a reference to a smart pointer. <BR>Initialize a new Pointer with any compatible Pointer. |
◆ Pointer() [3/3]
template<typename T>
template<typename T1 >
Copy constructor.
- Parameters
-
src | - a Pointer to type T1 where T1 is derived from T. <BR>Initialize a new Pointer of type T from a Pointer of type T1,
only if T1 is derived from T. |
◆ ~Pointer()
Destructor. Decreases the object reference count.
◆ operator=() [1/3]
Assignment operator.
- Parameters
-
object | - a pointer to an object allocated on the heap. <BR>Releases the current dumb pointer, if any and assigns <EM>object</EM>
to this Pointer, incrementing its reference count. |
◆ operator=() [2/3]
Assignment operator.
- Parameters
-
src | - a reference to a smart pointer. <BR>Releases the current dumb pointer, if any and assigns the dumb pointer
managed by <EM>src</EM> to this Pointer, incrementing its reference count. |
◆ operator=() [3/3]
template<typename T>
template<typename T1 >
Assignment operator.
- Parameters
-
src | - a Pointer to type T1 where T1 is derived from T. <BR>Releases the current dumb pointer, if any and assigns the dumb pointer
of type T1 managed by <EM>src</EM> to this Pointer as a dumb pointer of type T,
only if T1 is derived from T. The reference count is incremented. |
◆ operator*()
Dereference operator.
- Returns
- a reference to the object pointed to by the dumb pointer.
◆ operator->()
Member selection operator.
- Returns
- the dumb pointer.
◆ operator T*()
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()
Returns true if the Pointer has no dumb pointer.
◆ release()
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.
◆ reset()
Sets a new dumb pointer for the Pointer to manage.
- Parameters
-
object | - the new dumb pointer. <BR>Releases the current dumb pointer, if any, and assigns <EM>object</EM>
to the Pointer, incrementing its reference count. |
◆ 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: