FinanceSim 0.1.0
Financial Simulation Library
Loading...
Searching...
No Matches
financesim::EventBus Class Reference

#include <event_bus.hpp>

Classes

struct  Subscription
 

Public Member Functions

 EventBus ()=default
 
 EventBus (const EventBus &)=delete
 
EventBusoperator= (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< Subscriptionglobal_subscribers_
 
std::vector< EventPtrevent_log_
 
SubscriptionId next_subscription_id_ = 0
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EventBus() [1/2]

financesim::EventBus::EventBus ( )
default

◆ EventBus() [2/2]

financesim::EventBus::EventBus ( const EventBus )
delete

Member Function Documentation

◆ clear_log()

void financesim::EventBus::clear_log ( )
inline

Clear the event log.

Definition at line 89 of file event_bus.hpp.

References event_log_.

Referenced by PYBIND11_MODULE().

Here is the caller graph for this function:

◆ event_log()

const std::vector< EventPtr > & financesim::EventBus::event_log ( ) const
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().

Here is the caller graph for this function:

◆ operator=()

EventBus & financesim::EventBus::operator= ( const EventBus )
delete

◆ publish()

template<typename EventType >
void financesim::EventBus::publish ( std::shared_ptr< const EventType >  event)
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().

Here is the caller graph for this function:

◆ reset()

void financesim::EventBus::reset ( )
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().

Here is the caller graph for this function:

◆ subscribe()

template<typename EventType >
SubscriptionId financesim::EventBus::subscribe ( std::function< void(const EventType &)>  callback)
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().

Here is the caller graph for this function:

◆ subscribe_all()

SubscriptionId financesim::EventBus::subscribe_all ( EventCallback  callback)
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().

Here is the caller graph for this function:

◆ unsubscribe()

void financesim::EventBus::unsubscribe ( SubscriptionId  id)
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().

Here is the caller graph for this function:

Member Data Documentation

◆ event_log_

std::vector<EventPtr> financesim::EventBus::event_log_
private

Definition at line 107 of file event_bus.hpp.

Referenced by clear_log(), event_log(), publish(), and reset().

◆ global_subscribers_

std::vector<Subscription> financesim::EventBus::global_subscribers_
private

Definition at line 106 of file event_bus.hpp.

Referenced by publish(), reset(), subscribe_all(), and unsubscribe().

◆ next_subscription_id_

SubscriptionId financesim::EventBus::next_subscription_id_ = 0
private

Definition at line 108 of file event_bus.hpp.

Referenced by reset(), subscribe(), and subscribe_all().

◆ subscriptions_

std::unordered_map<std::type_index, std::vector<Subscription> > financesim::EventBus::subscriptions_
private

Definition at line 105 of file event_bus.hpp.

Referenced by publish(), reset(), subscribe(), and unsubscribe().


The documentation for this class was generated from the following file: