Skip to content

CheckedWeakPointer

INCLUDE FILE
#include <tpau-cpp-kernal/CheckedWeakPointer.h>

class CheckedWeakPointer

A weak pointer that throws an exception when it has expired.

This class behaves like a std::weak_ptr, except that it distinguishes between having been initialized with a valid pointer that expired and having been initialized with a nullptr.

When the pointer has expired, it throws an exception when trying to access the pointer, e. g. via lock().

DEFINITION
template <typename T> class CheckedWeakPointer;

constructor CheckedWeakPointer

Create an empty checked weak pointer.

DEFINITION
CheckedWeakPointer ( );

constructor CheckedWeakPointer

Create a checked weak pointer pointing to an object.

DEFINITION
CheckedWeakPointer ( std::weak_ptr< T >  weak_ptr );
PARAMETERDESCRIPTION
weak_ptr

The weak pointer to create the checked weak pointer from.

method emptyconst

Check if the checked weak pointer was initialized with a nullptr.

DEFINITION
bool  empty ( ) const;
RETURNSDESCRIPTION
bool

true if the checked weak pointer is empty, false otherwise.

method expiredconst

Check if the checked weak pointer has expired, i.e. it was set but the referenced object has been destroyed.

DEFINITION
bool  expired ( ) const;
RETURNSDESCRIPTION
bool

true if the checked weak pointer has expired, false otherwise.

method lockconst

Lock the checked weak pointer and obtain a shared pointer.

DEFINITION
std::shared_ptr< T >  lock ( ) const;
RETURNSDESCRIPTION
std::shared_ptr< T >

A shared pointer to the managed object.

THROWSDESCRIPTION
Exception

if the checked weak pointer has expired.

method operator boolconst

Interpret as bool, i. e. check if the checked weak pointer was not initialized with a nullptr.

DEFINITION
operator bool ( ) const;

method operator=

Assign a checked weak pointer to another.

DEFINITION
CheckedWeakPointer< T > & operator= ( CheckedWeakPointer< T >  other );
PARAMETERDESCRIPTION
other

The checked weak pointer to assign from.

RETURNSDESCRIPTION
CheckedWeakPointer< T > &

A reference to this checked weak pointer.

method operator=

Assign a weak pointer.

DEFINITION
CheckedWeakPointer< T > & operator= ( std::weak_ptr< T >  weak_ptr );
PARAMETERDESCRIPTION
weak_ptr

The weak pointer to assign from.

RETURNSDESCRIPTION
CheckedWeakPointer< T > &

A reference to this checked weak pointer.

method operator==const

Compare with another checked weak pointer.

DEFINITION
bool  operator== ( const CheckedWeakPointer< T > & other ) const;
PARAMETERDESCRIPTION
other

The checked weak pointer to compare with.

RETURNSDESCRIPTION
bool

true if both checked weak pointers are equal, false otherwise.

method operator==const

Compare with a shared pointer.

DEFINITION
bool  operator== ( const std::shared_ptr< T > & other ) const;
PARAMETERDESCRIPTION
other

The shared pointer to compare with.

RETURNSDESCRIPTION
bool

true if the checked weak pointer and the shared pointer are equal, false otherwise.

method operator==const

Compare with a weak pointer.

DEFINITION
bool  operator== ( const std::weak_ptr< T > & other ) const;
PARAMETERDESCRIPTION
other

The weak pointer to compare with.

RETURNSDESCRIPTION
bool

true if the checked weak pointer and the weak pointer are equal, false otherwise.

method reset

Reset the checked weak pointer to a nullptr.

DEFINITION
void  reset ( );