Wt: Wt::Core::observing_ptr< T > Class Template Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::Core::observing_ptr< T > Class Template Reference

A safe smart pointer for an observable. More...

## Public Member Functions
| observing_ptr (T *t=nullptr) noexcept
| Constructor.
| observing_ptr (const observing_ptr< T > &other) noexcept
| Copy constructor.
| observing_ptr (observing_ptr< T > &&other) noexcept
| Move constructor.
observing_ptr< T > & | operator= (const observing_ptr< T > &other) noexcept
| Copy assignment operator.
observing_ptr< T > & | operator= (observing_ptr< T > &&other) noexcept
| Move assignment operator.
template<typename S , typename = typename std::enable_if<std::is_convertible<S*, T*>::value>::type>
| observing_ptr (const observing_ptr< S > &other) noexcept
| Copy constructor with type conversion.
template<typename S , typename = typename std::enable_if<std::is_convertible<S*, T*>::value>::type>
| observing_ptr (observing_ptr< S > &&other) noexcept
| Move constructor with type conversion.
template<typename S , typename = typename std::enable_if<std::is_convertible<S*, T*>::value>::type>
observing_ptr< T > & | operator= (const observing_ptr< S > &other) noexcept
| Copy assignment operator with type conversion.
template<typename S , typename = typename std::enable_if<std::is_convertible<S*, T*>::value>::type>
observing_ptr< T > & | operator= (observing_ptr< S > &&other) noexcept
| Move assignment operator with type conversion.
T * | get () const noexcept
| Returns the pointer value.
void | reset (T *v=nullptr) noexcept
| Resets the value.
T * | operator-> () const
| Dereferences the pointer.
T & | operator* () const
| Dereferences the pointer.
| operator bool () const noexcept
| Returns whether the pointer is still valid.
bool | observedDeleted () const noexcept
| Returns whether the observed object has been deleted.

## Detailed Description

template<typename T>
class Wt::Core::observing_ptr< T >

A safe smart pointer for an observable.

This smart pointer can point only to objects that are observable. They are safe in the sense that they are aware of the life-time of the observed object, and thus cannot dangle. When dereferencing a pointer to an already destroyed object, an exception is thrown.

See also
  observable

## Constructor & Destructor Documentation

## ◆ observing_ptr()

template<typename T >

Wt::Core::observing_ptr< T >::observing_ptr | ( | T * | t = nullptr | ) |
| noexcept

Constructor.

See also
  reset()

## Member Function Documentation

## ◆ get()

template<typename T >

T * Wt::Core::observing_ptr< T >::get | ( |  | ) | const
| noexcept

Returns the pointer value.

Returns the value set to it, or `null` if the object was deleted.

See also
  reset()

## ◆ observedDeleted()

template<typename T >

bool Wt::Core::observing_ptr< T >::observedDeleted | ( |  | ) | const
| noexcept

Returns whether the observed object has been deleted.

Returns if the pointed object has been deleted.

## ◆ operator bool()

template<typename T >

Wt::Core::observing_ptr< T >::operator bool | ( |  | ) | const
| explicitnoexcept

Returns whether the pointer is still valid.

Returns if the pointer does not point to `null` and the pointed object isn't deleted.

## ◆ operator*()

template<typename T >

T & Wt::Core::observing_ptr< T >::operator* | ( |  | ) | const

Dereferences the pointer.

This throws a std::runtime_error if the pointer cannot be dereferenced.

## ◆ operator->()

template<typename T >

T * Wt::Core::observing_ptr< T >::operator-> | ( |  | ) | const

Dereferences the pointer.

This throws a std::runtime_error if the pointer cannot be dereferenced.