Wt
4.5.0
|
A base class for objects whose life-time can be tracked. More...
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... | |
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().
|
virtual |
Destructor.
Destruction may result in automatic disconnects from signal connections.
|
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.
|
noexcept |
Protects a const method call against object destruction.
|
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.