c++-gtk-utils
|
A class to execute callbacks connected to it, with provision for automatic disconnection. More...
#include <c++-gtk-utils/emitter.h>
Public Member Functions | |
void | operator() (typename Cgu::Param< FreeArgs >::ParamType... args) const |
void | emit (typename Cgu::Param< FreeArgs >::ParamType... args) const |
bool | test_emit (typename Cgu::Param< FreeArgs >::ParamType... args) const |
Callback::FunctorArg< FreeArgs... > | connect (const Callback::FunctorArg< FreeArgs... > &f) |
Callback::FunctorArg< FreeArgs... > | connect (const Callback::FunctorArg< FreeArgs... > &f, Releaser &r) |
void | disconnect (const Callback::FunctorArg< FreeArgs... > &f) |
void | block (const Callback::FunctorArg< FreeArgs... > &f) |
void | unblock (const Callback::FunctorArg< FreeArgs... > &f) |
EmitterArg ()=default | |
EmitterArg (const EmitterArg &)=delete | |
EmitterArg & | operator= (const EmitterArg &)=delete |
~EmitterArg () | |
Friends | |
class | Releaser |
A class to execute callbacks connected to it, with provision for automatic disconnection.
Callback::FunctorArg objects may be connected to Emitter classes, and will be executed when EmitterArg::emit() or EmitterArg::operator()() are called.
One version of the connect() method takes a Releaser object as an argument. Such a Releaser object should be a public member of any target class which wants functors representing (or calling into) any of its methods to be disconnected automatically from the EmitterArg object when the target class object is destroyed.
A connection may be explicitly disconnected by calling the disconnect() method, and may also be temporarily blocked and subsequently unblocked with the block() and unblock() methods.
The template types are the types of the unbound arguments, if any. EmitterArg<> is typedef'ed to Emitter.
Usage
These are examples:
For further background, including about thread-safety and exception safety and other matters, read this: emitter.h, or for more information about bound and unbound arguments, read this: Cgu::Callback.
|
default |
std::bad_alloc | The constructor might throw std::bad_alloc if memory is exhausted and the system throws in that case. |
|
delete |
This class cannot be copied. The copy constructor is deleted.
Cgu::EmitterArg::~EmitterArg | ( | ) |
The destructor does not throw provided that the destructors of any bound arguments do not throw (as they should not do), and assuming that merely iterating through a list does not throw (as it would not on any sane implementation).
void Cgu::EmitterArg::block | ( | const Callback::FunctorArg< FreeArgs... > & | f | ) |
Blocks a connected functor from executing when emit() or operator()() is called until unblock() is called. This method does not throw (assuming that merely iterating through a list does not throw, as it would not on any sane implementation).
f | The functor to block. |
Callback::FunctorArg<FreeArgs...> Cgu::EmitterArg::connect | ( | const Callback::FunctorArg< FreeArgs... > & | f | ) |
Connects a functor.
f | The functor to connect. |
std::bad_alloc | The method might throw std::bad_alloc if memory is exhausted and the system throws in that case. |
Callback::FunctorArg<FreeArgs...> Cgu::EmitterArg::connect | ( | const Callback::FunctorArg< FreeArgs... > & | f, |
Releaser & | r | ||
) |
Connects a functor.
f | The functor to connect. |
r | A Releaser object for automatic disconnection of the functor if the object whose method it represents is destroyed. |
std::bad_alloc | The method might throw std::bad_alloc if memory is exhausted and the system throws in that case. |
void Cgu::EmitterArg::disconnect | ( | const Callback::FunctorArg< FreeArgs... > & | f | ) |
Disconnects a functor previously connected. This does not throw provided that the destructors of any bound arguments do not throw (as they should not do), and assuming that merely iterating through a list does not throw (as it would not on any sane implementation).
f | The functor to disconnect. |
void Cgu::EmitterArg::emit | ( | typename Cgu::Param< FreeArgs >::ParamType... | args | ) | const |
This will execute the connected functors.
args | The unbound arguments to be passed to the referenced function or class method, if any. |
std::bad_alloc | The method might throw std::bad_alloc if memory is exhausted and the system throws in that case. In addition, it will throw if the functions or class methods referenced by the functors throw (or if the copy constructor of a free or bound argument throws and it is not a reference argument). |
|
inline |
This will execute the connected functors.
args | The unbound arguments to be passed to the referenced function or class method, if any. |
std::bad_alloc | The method might throw std::bad_alloc if memory is exhausted and the system throws in that case. In addition, it will throw if the functions or class methods referenced by the functors throw (or if the copy constructor of a free or bound argument throws and it is not a reference argument). |
|
delete |
This class cannot be copied. The assignment operator is deleted.
bool Cgu::EmitterArg::test_emit | ( | typename Cgu::Param< FreeArgs >::ParamType... | args | ) | const |
This will execute the connected functors, but it also reports whether in fact there were any connected functors to execute. (It is not necessary to use this function just because it is not known whether a functor is connected - if the standard emit() function is called when no functor is connected, nothing will happen. The feature of this method is that it will report the outcome.)
args | The unbound arguments to be passed to the connected functions or class methods, if any. |
std::bad_alloc | The method might throw std::bad_alloc if memory is exhausted and the system throws in that case. In addition, it will throw if the functions or class methods referenced by the functors throw (or if the copy constructor of a free or bound argument throws and it is not a reference argument). |
void Cgu::EmitterArg::unblock | ( | const Callback::FunctorArg< FreeArgs... > & | f | ) |
Unblocks a previously blocked functor. This method does not throw (assuming that merely iterating through a list does not throw, as it would not on any sane implementation).
f | The functor to unblock. |
|
friend |