Wt  4.10.4
Public Member Functions | List of all members
Wt::Core::observable Class Reference

A base class for objects whose life-time can be tracked. More...

Inheritance diagram for Wt::Core::observable:
[legend]

Public Member Functions

 observable () noexcept
 Default constructor.
 
virtual ~observable ()
 Destructor. More...
 
template<typename... Args, typename C >
auto bindSafe (void(C::*method)(Args...)) noexcept
 Protects a method call against object destruction. More...
 
template<typename... Args, typename C >
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 Protects a const method call against object destruction. More...
 
template<typename Function >
auto bindSafe (const Function &function) noexcept
 Protects a function against object destruction. More...
 

Detailed Description

A base class for objects whose life-time can be tracked.

This class provides the ability to be observed by a observing_ptr, which is a smart pointer that is aware of the deletion of this object. It is used by the signal/slot system to automatically disconnect a slot when the receiving object has been deleted, and can wrap itself inside a function that guards against deletion of the object using bindSafe().

See also
Signal

Constructor & Destructor Documentation

◆ ~observable()

Wt::Core::observable::~observable ( )
virtual

Destructor.

Destruction may result in automatic disconnects from signal connections.

Member Function Documentation

◆ bindSafe() [1/3]

template<typename Function >
auto Wt::Core::observable::bindSafe ( const Function &  function)
noexcept

Protects a function against object destruction.

This is useful only if somehow the function depends on the object to be valid.

This guarantees that the result function can safely be called regardless of whether the object was deleted in the mean-time. If the object was deleted, a call to the resulting function will result in a no-op. This is useful when the method will be called sometime in the future by for example an async method such as WServer::post().

The resulting function object has the same signature as the passed function.

The passed function object can be a std::function or a lambda.

◆ bindSafe() [2/3]

template<typename... Args, typename C >
auto Wt::Core::observable::bindSafe ( void(C::*)(Args...) const  method) const
noexcept

Protects a const method call against object destruction.

See also
bindSafe(void(C::*method)(Args...))

◆ bindSafe() [3/3]

template<typename... Args, typename C >
auto Wt::Core::observable::bindSafe ( void(C::*)(Args...)  method)
noexcept

Protects a method call against object destruction.

This returns a function that binds the current object to the method (as with std::bind()), but guarantees that the resulting function can safely be called regardless of whether the object was deleted in the mean-time. If the object was deleted, a call to the resulting function will result in a no-op. This is useful when the method will be called sometime in the future by for example an async method such as WServer::post().

The resulting function object has the same signature as the passed method.