#include <pointer.h>
Inheritance diagram for HBCI::Pointer< T >:
Public Methods | |
Pointer () | |
Pointer (T *obj) | |
Pointer (const Pointer< T > &p) | |
virtual | ~Pointer () |
Copy Operators | |
void | operator= (T *obj) |
void | operator= (Pointer< T > &p) |
void | operator= (const Pointer< T > &p) |
Object Access | |
T & | ref () const |
T & | operator * () const |
virtual T * | ptr () const |
virtual int | refCount () const |
Type cast | |
template<class U> Pointer< U > | cast () const |
Returns a type-safe casted Pointer of the given type. | |
Equality | |
bool | operator== (const Pointer< T > &p) const |
bool | operator!= (const Pointer< T > &p) const |
bool | sharingData (const Pointer< T > &p) const |
Protected Methods | |
virtual void | _deleteObject (void *p) |
Pointer (const PointerBase &p) | |
Friends | |
class | PointerCastBase< T > |
This class serves as a smart pointer class that is used in OpenHBCI to avoid memory leaks. It does automatic reference counting for the objects pointed to, like so: Each time a new Pointer to the same object is created, the reference counter is incremented. Each time a Pointer to an object is deleted, the reference counter is decremented. When the reference counter reaches zero, the object is deleted.
Use it instead of normal pointers, for example: instead of
structXYZ *pointer;
pointer = new structXYZ;
use this one:
Pointer<structXYZ> pointer;
pointer = new structXYZ;
You can access the data easily by using the "*" operator, e.g:
structXYZ xyz = *pointer;
To access members of the object, either use the "*" operator or the ref() method:
a = (*pointer).a;
or
b = pointer.ref().a;
|
|
|
Empty Constructor. |
|
Constructor with object to be pointing to. |
|
Copy constructor |
|
Destructor. If this one gets called, it automagically decrements the usage counter of the object pointed to. If it reaches zero, then no other pointer points to the object and the object will be deleted.
|
|
This method actually deletes the object. Since the base class does not know the type of this object, we have to make this method virtual. The template class MUST override this. |
|
Returns a type-safe casted Pointer of the given type.
This method returns a type-safe casted Pointer of the given type. This obeys the same rules as a Use it like this: class type_X; class type_Y : public type_X; Pointer<type_X> pX; Pointer<type_Y> pY = new type_Y; pX = pY.cast<type_X>(); The casting fails if it is impossibe to safely cast the "type_Y" to "type_X". In that case, an HBCI::Error is thrown. Also, if you call this method on an invalid Pointer, a HBCI::Error is thrown.
|
|
Returns a reference to the object pointed to. If the Pointer is invalid, this throws a HBCI::Error. |
|
Inequality operator for the object pointed to. This operator checks whether another pointer and this one are not pointing to the same data.
|
|
Copy operator with another const Pointer. This operator handles the case where you give another pointer as argument. (like pointer1=pointer2).
|
|
Copy operator with another Pointer. This operator handles the case where you give another pointer as argument. (like pointer1=pointer2).
|
|
Copy operator with object pointed to.
This operator handles the case where you do something like this:
|
|
Equality operator for the object pointed to. This operator checks whether another pointer and this one are pointing to the same data.
|
|
Returns a raw pointer to the stored data. If you can continue using only Pointer's, you should not really need to use this. This method is necessary if and only if you need to use a "raw C pointer" of the object pointed to. So if you need to use this method while there is still a Pointer pointing to it, please never delete the object returned. The last remaining Pointer's will take care of deletion. On the other hand, if you need to use this pointer longer than the last Pointer would exist, then either try to keep a Pointer around long enough, or you need to consider setting PointerBase::setAutoDelete appropriately. (Because if the last Pointer stops pointing to an object, then that object will get deleted unless PointerBase::setAutoDelete was changed.)
|
|
Returns a reference to the object pointed to. If the Pointer is invalid, this throws a HBCI::Error. |
|
Reimplemented from HBCI::PointerBase. |
|
Checks whether both pointers share their data object.
This method checks whether another pointer and this one share the same internal data object and thus also the same data pointed to. This is a stronger condition than
|
|
|