Simo 0.0.1
Loading...
Searching...
No Matches
Simo::Context Class Reference

#include <Context.h>

Public Types

enum struct  State : uint8_t {
  INITIALIZATION , PORT_CONNECTION , RUNNING , STOPPED ,
  ERROR
}
enum struct  RunStatus : uint8_t { EVENTS_IN_QUEUE , STOPPED }

Public Member Functions

InitializationStatus initialize ()
std::expected< RunStatus, InitializationStatusrun (const Time &time_delta)
std::expected< RunStatus, InitializationStatusrun_at (const Time &final_time)
void schedule_at (const Time &time_target, const SimulationCallable &callable)
 Schedule event at time_target time.
void schedule_at (const Time &time_target, const std::function< void()> &callable)
 Schedule event at time_target time.
void schedule_in (const Time &time_delta, const SimulationCallable &callable)
 Schedule an event for time current_time + time_delta.
void schedule_in (const Time &time_delta, const std::function< void()> &callable)
 Schedule an event for time current_time + time_delta.
template<typename T>
Parameter::ParameterTyped< T > & add_parameter (const std::string &name, const T &value)
 Add parameter of specific type. Return reference to parameter.
void add (Module &module, Parameters &)
void remove (const Module &module)
 Remove a modules from the context before initialization occurs.
template<typename Function>
void foreach_module (Function f) const
State get_state () const
Time current_time () const

Detailed Description

Manage Module initialization and schedule simulation events

The initial state of the simulation is INITIALIZATION. In this phase:

  • Modules can be added
  • Events can be scheduled with any time. After the simulation starts (ie a call to a run* method is performed), the state becomes RUNNING. In this state, events can only be scheduled for a time in the future. The current time can be probed with current_time() method. When no events are schedules, the state transitions to STOPPED. New events can be scheduled even in this state

Member Function Documentation

◆ add()

void Simo::Context::add ( Module & module,
Parameters & p )

Add module with a set of parameters to the context.

Modules are going to be initialized during initialization

◆ initialize()

InitializationStatus Simo::Context::initialize ( )
nodiscard

Initialize the context and the registered modules

This can be done before the first call to run method

◆ run()

std::expected< Context::RunStatus, InitializationStatus > Simo::Context::run ( const Time & time_delta)

Run for the time expressed in time_delta

If the simulation current_time is t and this function is called, current_time will be t + time_delta at the end of the function If the context is not initialized, the initialize method is going to be called before the execution

◆ run_at()

std::expected< Context::RunStatus, InitializationStatus > Simo::Context::run_at ( const Time & final_time)

Run at the time expressed in time_target

Run the simulation untile time_target is reached.


The documentation for this class was generated from the following files:
  • include/Simo/core/Context.h
  • src/core/Context.cc