|
FinanceSim 0.1.0
Financial Simulation Library
|
#include <event_bus.hpp>
Classes | |
| struct | Subscription |
Public Member Functions | |
| EventBus ()=default | |
| EventBus (const EventBus &)=delete | |
| EventBus & | operator= (const EventBus &)=delete |
| template<typename EventType > | |
| SubscriptionId | subscribe (std::function< void(const EventType &)> callback) |
| SubscriptionId | subscribe_all (EventCallback callback) |
| Subscribe to all events. | |
| void | unsubscribe (SubscriptionId id) |
| Unsubscribe using subscription ID. | |
| template<typename EventType > | |
| void | publish (std::shared_ptr< const EventType > event) |
| Publish an event to all subscribers. | |
| const std::vector< EventPtr > & | event_log () const |
| Get all events in chronological order (for replay/debugging) | |
| void | clear_log () |
| Clear the event log. | |
| void | reset () |
| Reset the bus (clear all subscriptions and log) | |
Private Attributes | |
| std::unordered_map< std::type_index, std::vector< Subscription > > | subscriptions_ |
| std::vector< Subscription > | global_subscribers_ |
| std::vector< EventPtr > | event_log_ |
| SubscriptionId | next_subscription_id_ = 0 |
Central pub/sub event bus for model communication All communication between models goes through this bus
Definition at line 20 of file event_bus.hpp.
|
default |
|
delete |
|
inline |
Clear the event log.
Definition at line 89 of file event_bus.hpp.
References event_log_.
Referenced by PYBIND11_MODULE().
|
inline |
Get all events in chronological order (for replay/debugging)
Definition at line 86 of file event_bus.hpp.
References event_log_.
Referenced by PYBIND11_MODULE().
|
inline |
Publish an event to all subscribers.
Definition at line 69 of file event_bus.hpp.
References event_log_, global_subscribers_, and subscriptions_.
Referenced by financesim::AccountBase::emit(), financesim::AssetsBase::emit(), financesim::ExpensesBase::emit(), financesim::IncomeBase::emit(), and financesim::LiabilitiesBase::emit().
|
inline |
Reset the bus (clear all subscriptions and log)
Definition at line 92 of file event_bus.hpp.
References event_log_, global_subscribers_, next_subscription_id_, and subscriptions_.
Referenced by PYBIND11_MODULE().
|
inline |
Subscribe to a specific event type Returns a subscription ID that can be used to unsubscribe
Definition at line 31 of file event_bus.hpp.
References next_subscription_id_, and subscriptions_.
Referenced by financesim::AccountBase::initialize().
|
inline |
Subscribe to all events.
Definition at line 45 of file event_bus.hpp.
References global_subscribers_, and next_subscription_id_.
Referenced by financesim::Logger::attach(), and PYBIND11_MODULE().
|
inline |
Unsubscribe using subscription ID.
Definition at line 52 of file event_bus.hpp.
References global_subscribers_, and subscriptions_.
Referenced by financesim::Logger::detach(), PYBIND11_MODULE(), and financesim::AccountBase::reset().
|
private |
Definition at line 107 of file event_bus.hpp.
Referenced by clear_log(), event_log(), publish(), and reset().
|
private |
Definition at line 106 of file event_bus.hpp.
Referenced by publish(), reset(), subscribe_all(), and unsubscribe().
|
private |
Definition at line 108 of file event_bus.hpp.
Referenced by reset(), subscribe(), and subscribe_all().
|
private |
Definition at line 105 of file event_bus.hpp.
Referenced by publish(), reset(), subscribe(), and unsubscribe().