ug4
|
Holds and automatically deletes a pointer, similar to std::auto_ptr. USE WITH CARE! More...
#include <owned_pointer.h>
Public Types | |
typedef T * | TPtr |
typedef T & | TRef |
Public Member Functions | |
TPtr & | get () const |
operator bool () const | |
TRef | operator* () const |
TPtr | operator-> () const |
OwnedPtr & | operator= (const OwnedPtr &op) |
Transfers ownership of the associated object from ap to this. More... | |
OwnedPtr (const OwnedPtr &op) | |
Transfers ownership of the associated object from ap to this. More... | |
OwnedPtr (TPtr p=0) | |
void | reset (TPtr p=0) |
Private Member Functions | |
void | invalidate () const |
This method is a hack, to allow that only one instance owns the pointer. More... | |
Private Attributes | |
TPtr | m_p |
Holds and automatically deletes a pointer, similar to std::auto_ptr. USE WITH CARE!
WARNING: USE WITH CARE! Class shows uncommon behavior when copied.
The behavior of this class is very similar to std::auto_ptr and somewhat similar to boost::scoped_ptr. It takes a pointer in its constructor and automatically deletes the associated object in its destructor or in a call to reset. The most notable property of OwnedPtr is that an OwnedPtr 'owns' the associated object. That means that two OwnedPtrs should never point to the same instance. The copy-constructor thus shows the somewhat irritating behavior of invalidating the original copy and transferring the ownership of the associated object to the new copy of OwnedPtr. This behavior again is the same in std::auto_ptr, however, in contrary to std::auto_ptr, instances of OwnedPtr can be used in standard containers like std::vector. This is explicitly not advised, since many algorithms working with iterators or standard containers will not work with OwnedPtrs. Storing OwnedPtrs in lib_grids attachments may sometimes be useful. Therefore this slightly dangerous class was introduced.
typedef T* ug::OwnedPtr< T >::TPtr |
typedef T& ug::OwnedPtr< T >::TRef |
|
inline |
References p.
|
inline |
Transfers ownership of the associated object from ap to this.
Note that ap looses ownership of the associated object. ap thus is not const at all, despite beeing declared const.
References ug::OwnedPtr< T >::get(), ug::OwnedPtr< T >::invalidate(), and ug::OwnedPtr< T >::m_p.
|
inline |
References ug::OwnedPtr< T >::m_p.
Referenced by ug::OwnedPtr< T >::operator=(), and ug::OwnedPtr< T >::OwnedPtr().
|
inlineprivate |
This method is a hack, to allow that only one instance owns the pointer.
References ug::OwnedPtr< T >::m_p.
Referenced by ug::OwnedPtr< T >::operator=(), and ug::OwnedPtr< T >::OwnedPtr().
|
inline |
References ug::OwnedPtr< T >::m_p.
|
inline |
References ug::OwnedPtr< T >::m_p.
|
inline |
References ug::OwnedPtr< T >::m_p.
|
inline |
Transfers ownership of the associated object from ap to this.
Note that ap looses ownership of the associated object. ap thus is not const at all, despite beeing declared const.
References ug::OwnedPtr< T >::get(), ug::OwnedPtr< T >::invalidate(), and ug::OwnedPtr< T >::reset().
|
inline |
References ug::OwnedPtr< T >::m_p, and p.
Referenced by ug::OwnedPtr< T >::operator=().
|
mutableprivate |