casa
5.7.0-16
|
Hold and delete pointers not deleted by object destructors. More...
#include <PtrHolder.h>
Public Member Functions | |
SPtrHolder (T *ptr=0) | |
Construct an SPtrHolder from a pointer which MUST have been allocated from new , since the destructor will After the pointer is placed into the holder, the user should not manually delete the pointer unless the transfer function is called. More... | |
~SPtrHolder () | |
void | reset (T *ptr) |
Reset the pointer. More... | |
T * | transfer () |
Transfer ownership of the pointer. More... | |
void | release () |
Release the pointer. More... | |
T & | operator* () |
Make it possible to dereference the pointer object. More... | |
const T & | operator* () const |
T * | operator-> () const |
Make it possible to use -> on the pointer object. More... | |
T * | ptr () |
Get the pointer for use. More... | |
const T * | ptr () const |
Private Member Functions | |
SPtrHolder (const SPtrHolder< T > &other) | |
SPrtHolder cannot be copied. More... | |
SPtrHolder< T > & | operator= (const SPtrHolder< T > &other) |
Private Attributes | |
T * | itsPtr |
Hold and delete pointers not deleted by object destructors.
Public interface
SPtrHolder
s hold allocated pointers to non-array objects which should be deleted when an exception is thrown. SPtrHolder is similar to PtrHolder, but easier to use and only valid for pointer to a single object, thus not to a C-array of objects.
If an exception is thrown in function func
, the Table will be deleted automatically. After the function call, the ownership is tranfered back to the 'user'
std::auto_ptr
is harder to use and its future is unclear.
PtrHolder
is not fully inlined and has C-array overhead. Furthermore the automatic conversion to a T* is dangerous, because the programmer may not be aware that the pointer is maybe taken over.
Definition at line 197 of file PtrHolder.h.
|
inlineexplicit |
Construct an SPtrHolder
from a pointer which MUST have been allocated from new
, since the destructor will After the pointer is placed into the holder, the user should not manually delete the pointer unless the transfer function is called.
The pointer must also only be put into one holder to avoid double deletion.
Definition at line 206 of file PtrHolder.h.
|
inline |
Definition at line 209 of file PtrHolder.h.
|
private |
SPrtHolder cannot be copied.
|
inline |
Make it possible to dereference the pointer object.
Definition at line 227 of file PtrHolder.h.
|
inline |
Definition at line 229 of file PtrHolder.h.
|
inline |
Make it possible to use -> on the pointer object.
Definition at line 234 of file PtrHolder.h.
|
private |
|
inline |
Get the pointer for use.
Definition at line 239 of file PtrHolder.h.
|
inline |
Definition at line 241 of file PtrHolder.h.
|
inline |
Release the pointer.
Definition at line 222 of file PtrHolder.h.
|
inline |
Reset the pointer.
Definition at line 213 of file PtrHolder.h.
|
inline |
Transfer ownership of the pointer.
I.e. return the pointer and set it to 0 in the object.
Definition at line 218 of file PtrHolder.h.
|
private |
Definition at line 253 of file PtrHolder.h.