Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Private Member Functions | Private Attributes | List of all members
orxonox::WeakPtr< T > Class Template Reference

WeakPtr wraps a pointer to an object, which becomes nullptr if the object is deleted. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/CorePrereqs.h>

Inheritance diagram for orxonox::WeakPtr< T >:
orxonox::DestructionListener

Public Member Functions

 WeakPtr ()
 Constructor: Initializes the weak pointer with a null pointer. More...
 
 WeakPtr (T *pointer)
 Constructor: Initializes the weak pointer with a pointer to an object. More...
 
 WeakPtr (const WeakPtr &other)
 Copy-constructor. More...
 
template<class O >
 WeakPtr (const WeakPtr< O > &other)
 Copy-constructor for weak pointers to objects of another class. More...
 
virtual ~WeakPtr ()
 Destructor. More...
 
T * get () const
 Returns the wrapped pointer as T*. More...
 
DestroyablegetBase () const
 Returns the wrapped pointer as Destroyable*. More...
 
const FunctorPtrgetCallback () const
 Returns the registered callback. More...
 
 operator bool () const
 Returns true if the pointer is not nullptr. More...
 
 operator T * () const
 Implicitly converts the WeakPtr to a pointer of type T*. More...
 
T & operator* () const
 Overloaded operator, returns a reference to the stored object. More...
 
T * operator-> () const
 Overloaded operator, returns a pointer to the stored object. More...
 
WeakPtroperator= (T *pointer)
 Assigns a new pointer. More...
 
WeakPtroperator= (WeakPtr other)
 Assigns the wrapped pointer of another WeakPtr. More...
 
template<class O >
WeakPtroperator= (const WeakPtr< O > &other)
 Assigns the wrapped pointer of a WeakPtr of another class. More...
 
void reset ()
 Resets the weak pointer (equivalent to assigning a nullptr). More...
 
void setCallback (const FunctorPtr &callback)
 Registers a callback that will be executed if the stored object is destroyed. More...
 
void swap (WeakPtr &other)
 Swaps the contents of two weak pointers. More...
 

Private Member Functions

virtual void objectDeleted () override
 Will be called by Destroyable::~Destroyable() if the stored object is deleted. Resets the wrapped pointer and executes the callback. More...
 

Private Attributes

Destroyablebase_
 The wrapped pointer, casted up to Destroyable (this is needed because with just a T* pointer, WeakPtr couln't be used with forward declarations) More...
 
FunctorPtr callback_
 This callback will be executed if the stored object is deleted. More...
 
T * pointer_
 The wrapped pointer to an object of type T. More...
 

Additional Inherited Members

- Protected Member Functions inherited from orxonox::DestructionListener
virtual ~DestructionListener ()
 
void registerAsDestructionListener (Destroyable *object)
 
void unregisterAsDestructionListener (Destroyable *object)
 

Detailed Description

template<class T>
class orxonox::WeakPtr< T >

WeakPtr wraps a pointer to an object, which becomes nullptr if the object is deleted.

See also
See this description for more information and an example.

Constructor & Destructor Documentation

template<class T>
orxonox::WeakPtr< T >::WeakPtr ( )
inline

Constructor: Initializes the weak pointer with a null pointer.

template<class T>
orxonox::WeakPtr< T >::WeakPtr ( T *  pointer)
inline

Constructor: Initializes the weak pointer with a pointer to an object.

template<class T>
orxonox::WeakPtr< T >::WeakPtr ( const WeakPtr< T > &  other)
inline

Copy-constructor.

template<class T>
template<class O >
orxonox::WeakPtr< T >::WeakPtr ( const WeakPtr< O > &  other)
inline

Copy-constructor for weak pointers to objects of another class.

template<class T>
virtual orxonox::WeakPtr< T >::~WeakPtr ( )
inlinevirtual

Destructor.

Member Function Documentation

template<class T>
T* orxonox::WeakPtr< T >::get ( ) const
inline

Returns the wrapped pointer as T*.

template<class T>
Destroyable* orxonox::WeakPtr< T >::getBase ( ) const
inline

Returns the wrapped pointer as Destroyable*.

template<class T>
const FunctorPtr& orxonox::WeakPtr< T >::getCallback ( ) const
inline

Returns the registered callback.

template<class T>
virtual void orxonox::WeakPtr< T >::objectDeleted ( )
inlineoverrideprivatevirtual

Will be called by Destroyable::~Destroyable() if the stored object is deleted. Resets the wrapped pointer and executes the callback.

Implements orxonox::DestructionListener.

template<class T>
orxonox::WeakPtr< T >::operator bool ( ) const
inlineexplicit

Returns true if the pointer is not nullptr.

template<class T>
orxonox::WeakPtr< T >::operator T * ( ) const
inline

Implicitly converts the WeakPtr to a pointer of type T*.

template<class T>
T& orxonox::WeakPtr< T >::operator* ( ) const
inline

Overloaded operator, returns a reference to the stored object.

template<class T>
T* orxonox::WeakPtr< T >::operator-> ( ) const
inline

Overloaded operator, returns a pointer to the stored object.

template<class T>
WeakPtr& orxonox::WeakPtr< T >::operator= ( T *  pointer)
inline

Assigns a new pointer.

template<class T>
WeakPtr& orxonox::WeakPtr< T >::operator= ( WeakPtr< T >  other)
inline

Assigns the wrapped pointer of another WeakPtr.

template<class T>
template<class O >
WeakPtr& orxonox::WeakPtr< T >::operator= ( const WeakPtr< O > &  other)
inline

Assigns the wrapped pointer of a WeakPtr of another class.

template<class T>
void orxonox::WeakPtr< T >::reset ( )
inline

Resets the weak pointer (equivalent to assigning a nullptr).

template<class T>
void orxonox::WeakPtr< T >::setCallback ( const FunctorPtr callback)
inline

Registers a callback that will be executed if the stored object is destroyed.

template<class T>
void orxonox::WeakPtr< T >::swap ( WeakPtr< T > &  other)
inline

Swaps the contents of two weak pointers.

Member Data Documentation

template<class T>
Destroyable* orxonox::WeakPtr< T >::base_
private

The wrapped pointer, casted up to Destroyable (this is needed because with just a T* pointer, WeakPtr couln't be used with forward declarations)

template<class T>
FunctorPtr orxonox::WeakPtr< T >::callback_
private

This callback will be executed if the stored object is deleted.

template<class T>
T* orxonox::WeakPtr< T >::pointer_
private

The wrapped pointer to an object of type T.


The documentation for this class was generated from the following files: