Wt  4.0.0
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:
Inheritance graph
[legend]

Public Member Functions

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

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

Destructor.

Destruction may result in automatic disconnects from signal connections.

Member Function Documentation

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

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.

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

Protects a const method call against object destruction.

See also
bindSafe(void(C::*method)(Args...))
template<typename Function >
auto Wt::Core::observable::bindSafe ( const Function &  function)

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 past function object can be a std::function or a lambda.


Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11