AnCH events library aims to provide event programming facilities (observers, event handlers and an asynchronous event bus).
It is based on C++ template. This is not a library but only header files.
This library is based on observer/observable design pattern. So the base classes are anch::events::Observer<T> and anch::events::Observable<T>.
CMake target anch::events (header only):
See installation.
AnCH events library is header only.
Events are Event<T>: a body of type T and headers (string map).
Observer<T> implements handle(const Event<T>&) . Observable<T> notifies its observers synchronously with notifyObservers . Observers can add or remove observers while being notified.
EventHandler<T, Derived> is an observer which calls a member function of Derived : a class can inherit several event handlers to handle several event types. It can register itself in an event bus, and unsubscribe .
EventBus<T> notifies its observers asynchronously, in firing order, from a dedicated thread: fireEvent does not wait for observers. EventBus<T>::getInstance() is the global bus ; other buses are plain objects. A bus destructor delivers the queued events before stopping its thread.
Output: