Public Member Functions | |
| SmartPointer () | |
| template<class Q> | |
| SmartPointer (const SmartPointer< T, Q > &tt) | |
| SmartPointer (const SmartPointer< T, P > &tt) | |
| SmartPointer (T *t, const char *id) | |
| SmartPointer (T *t) | |
| ~SmartPointer () | |
| SmartPointer< T, P > & | operator= (T *tt) |
| template<class Q> | |
| SmartPointer< T, P > & | operator= (const SmartPointer< T, Q > &tt) |
| SmartPointer< T, P > & | operator= (const SmartPointer< T, P > &tt) |
| operator T * () const | |
| T & | operator* () const |
| T * | operator-> () const |
| template<class Q> | |
| void | swap (SmartPointer< T, Q > &tt) |
| void | swap (T *&tt) |
| unsigned int | memory_consumption () const |
Private Attributes | |
| T * | t |
| const char *const | id |
* and -> operators and through casting) but make sure that the object pointed to is not deleted in the course of use of the pointer by signalling the pointee its use.Objects pointed to, that is ,the class T, should inherit Subscriptor or must implement the same functionality. Null pointers are an exception from this rule and are allowed, too.
The second template argument P only serves a single purpose: if a constructor without a debug string is used, then the name of P is used as the debug string.
SmartPointer does NOT implement any memory handling! Especially, deleting a SmartPointer does not delete the object. Writing
SmartPointer<T,P> dont_do_this = new T;
T* p = new T; { SmartPointer<T,P> t(p); ... } delete p;
Note that a smart pointer can handle constness of an object, i.e. a SmartPointer<const ABC> really behaves as if it were a pointer to a constant object (disallowing write access when dereferenced), while SmartPointer<ABC> is a mutable pointer.
| SmartPointer< T, P >::SmartPointer | ( | ) | [inline] |
Standard constructor for null pointer. The id of this pointer is set to the name of the class P.
| SmartPointer< T, P >::SmartPointer | ( | const SmartPointer< T, Q > & | tt | ) | [inline] |
References SmartPointer< T, P >::t.
| SmartPointer< T, P >::SmartPointer | ( | const SmartPointer< T, P > & | tt | ) | [inline] |
References SmartPointer< T, P >::t.
| SmartPointer< T, P >::SmartPointer | ( | T * | t, | |
| const char * | id | |||
| ) | [inline] |
Constructor taking a normal pointer. If possible, i.e. if the pointer is not a null pointer, the constructor subscribes to the given object to lock it, i.e. to prevent its destruction before the end of its use.
The id is used in the call to Subscriptor::subscribe(id) and by ~SmartPointer() in the call to Subscriptor::unsubscribe().
| SmartPointer< T, P >::SmartPointer | ( | T * | t | ) | [inline] |
Constructor taking a normal pointer. If possible, i.e. if the pointer is not a null pointer, the constructor subscribes to the given object to lock it, i.e. to prevent its destruction before the end of its use. The id of this pointer is set to the name of the class P.
| SmartPointer< T, P >::~SmartPointer | ( | ) | [inline] |
Destructor, removing the subscription.
References SmartPointer< T, P >::t.
| SmartPointer< T, P > & SmartPointer< T, P >::operator= | ( | T * | tt | ) | [inline] |
Assignment operator for normal pointers. The pointer subscribes to the new object automatically and unsubscribes to an old one if it exists. It will not try to subscribe to a null-pointer, but stilll delete the old subscription.
References SmartPointer< T, P >::t.
| SmartPointer< T, P > & SmartPointer< T, P >::operator= | ( | const SmartPointer< T, Q > & | tt | ) | [inline] |
Assignment operator for SmartPointer. The pointer subscribes to the new object automatically and unsubscribes to an old one if it exists.
References LAPACKSupport::T, and SmartPointer< T, P >::t.
| SmartPointer< T, P > & SmartPointer< T, P >::operator= | ( | const SmartPointer< T, P > & | tt | ) | [inline] |
Assignment operator for SmartPointer. The pointer subscribes to the new object automatically and unsubscribes to an old one if it exists.
References LAPACKSupport::T, and SmartPointer< T, P >::t.
| SmartPointer< T, P >::operator T * | ( | ) | const [inline] |
Conversion to normal pointer.
References SmartPointer< T, P >::t.
| T & SmartPointer< T, P >::operator* | ( | ) | const [inline] |
Dereferencing operator. This operator throws an ExcNotInitialized if the pointer is a null pointer.
References Assert, StandardExceptions::ExcNotInitialized(), and SmartPointer< T, P >::t.
| T * SmartPointer< T, P >::operator-> | ( | ) | const [inline] |
Dereferencing operator. This operator throws an ExcNotInitialized if the pointer is a null pointer.
References Assert, StandardExceptions::ExcNotInitialized(), and SmartPointer< T, P >::t.
| void SmartPointer< T, P >::swap | ( | SmartPointer< T, Q > & | tt | ) | [inline] |
Exchange the pointers of this object and the argument. Since both the objects to which is pointed are subscribed to before and after, we do not have to change their subscription counters.
Note that this function (with two arguments) and the respective functions where one of the arguments is a pointer and the other one is a C-style pointer are implemented in global namespace.
References swap(), and SmartPointer< T, P >::t.
Referenced by swap().
| void SmartPointer< T, P >::swap | ( | T *& | tt | ) | [inline] |
Swap pointers between this object and the pointer given. As this releases the object pointed to presently, we reduce its subscription count by one, and increase it at the object which we will point to in the future.
Note that we indeed need a reference of a pointer, as we want to change the pointer variable which we are given.
References swap(), and SmartPointer< T, P >::t.
| unsigned int SmartPointer< T, P >::memory_consumption | ( | ) | const [inline] |
Return an estimate of the amount of memory (in bytes) used by this class. Note in particular, that this only includes the amount of memory used by this object, not by the object pointed to.
Referenced by MGMatrix< MATRIX, VECTOR >::memory_consumption().
T* SmartPointer< T, P >::t [private] |
Pointer to the object we want to subscribt to. Since it is often necessary to follow this pointer when debugging, we have deliberately chosen a short name.
Referenced by SmartPointer< T, P >::operator T *(), SmartPointer< T, P >::operator*(), SmartPointer< T, P >::operator->(), SmartPointer< T, P >::operator=(), SmartPointer< T, P >::SmartPointer(), SmartPointer< T, P >::swap(), and SmartPointer< T, P >::~SmartPointer().
const char* const SmartPointer< T, P >::id [private] |
The identification for the subscriptor.
documentation generated on Wed Jul 28 23:06:41 2010 by
doxygen
1.5.6