2 #ifndef SYDEVS_SYSTEMS_SYSTEM_NODE_H_
3 #define SYDEVS_SYSTEMS_SYSTEM_NODE_H_
61 void print(
const T& X);
62 void print(
const char* raw_text);
63 void print(
const std::string& text);
114 virtual void adopt_component_print_flags(
const system_node& node)
const = 0;
116 virtual duration handle_initialization_event() = 0;
119 virtual void handle_finalization_event(
duration elapsed_dt) = 0;
130 explicit error(
const std::string& what_arg);
131 explicit error(
const char* what_arg);
174 print(std::string(raw_text));
194 planned_dt = handle_initialization_event();
202 catch (
const std::exception& e) {
207 throw error(
"Aborting event in node (" +
full_name() +
") due to error (\"" + e.what() +
"\")");
217 planned_dt = handle_unplanned_event(elapsed_dt);
225 catch (
const std::exception& e) {
230 throw error(
"Aborting event in node (" +
full_name() +
") due to error (\"" + e.what() +
"\")");
240 planned_dt = handle_planned_event(elapsed_dt);
248 catch (
const std::exception& e) {
253 throw error(
"Aborting event in node (" +
full_name() +
") due to error (\"" + e.what() +
"\")");
262 handle_finalization_event(elapsed_dt);
270 catch (
const std::exception& e) {
275 throw error(
"Aborting event in node (" +
full_name() +
") due to error (\"" + e.what() +
"\")");
281 : rng(const_cast<
node_context&>(external_context).rng())
282 , external_interface_(node_name, this, external_context)
296 return const_cast<timer&
>(event_timer_);
301 : runtime_error(what_arg)
307 : runtime_error(what_arg)
void process_finalization_event(duration elapsed_dt)
Processes a finalization event after an elapsed duration elapsed_dt.
Definition: system_node.h:259
std::string tostring(const T &val)
Definition: qualified_type.h:35
const std::string & node_name() const
Returns the name of the node.
Definition: system_node.h:135
int64 node_index() const
Returns the index of the node within the parent node.
Definition: system_node.h:147
int64 node_index()
Definition: node_interface.h:151
data_mode
Indicates the relevant data communication paradigm: dataflow (flow) or message-passing (message)...
Definition: data_mode.h:16
duration stop()
Stops the timer and returns the measured interval of wallclock time.
Definition: timer.h:93
A base class for all nodes from which systems models are constructed.
Definition: system_node.h:41
void print_on_event(bool flag=true)
Definition: node_interface.cpp:356
duration process_initialization_event()
Processes an initialization event; returns a planned duration.
Definition: system_node.h:190
duration process_planned_event(duration elapsed_dt)
Processes a planned event after an elapsed duration elapsed_dt; returns a planned duration...
Definition: system_node.h:236
virtual ~system_node()=default
Destructor.
void print_command_text(const std::string &command, const std::string &text)
Definition: node_interface.cpp:344
const std::string & full_name()
Definition: node_interface.h:145
virtual data_mode node_dmode() const =0
Returns flow if the node has data flow elements only, and message otherwise.
void print_on_event(bool flag=true) const
If flag is true, all event types are printed for this node.
Definition: system_node.h:184
A class for measuring and accumulating intervals of wallclock time.
Definition: timer.h:24
const std::string & full_name() const
Returns the full name of the node, including parent nodes.
Definition: system_node.h:141
system_node & operator=(const system_node &)=delete
No copy assignment.
error(const std::string &what_arg)
Definition: system_node.h:300
A data type which represents the general concept of scale as a dimensionless power of 1000...
Definition: scale.h:70
const std::string & node_name()
Definition: node_interface.h:139
Definition: node_context.h:16
Definition: node_interface.h:16
duration process_unplanned_event(duration elapsed_dt)
Processes an unplanned event after an elapsed duration elapsed_dt; returns a planned duration...
Definition: system_node.h:213
quantity< seconds > duration
Definition: quantity.h:1006
system_node(const system_node &)=delete
No copy constructor.
void print(const T &X)
Prints X while indicating the simulation time and node.
Definition: system_node.h:166
Definition: system_node.h:127
std::mt19937 & rng
Reference to the random number generator.
Definition: system_node.h:78
duration scale_planned_dt(duration planned_dt) const
Adjusts the planned duration obtained from other nodes' event handlers.
Definition: system_node.cpp:46
const timer & event_timer() const
Returns the object that accumulated wallclock event durations.
Definition: system_node.h:159
void adopt_print_flags(const system_node &node) const
Adopts the print flags of node.
Definition: system_node.cpp:7
node_interface & external_IO() const
Returns a non-const reference to the node's external interface.
Definition: system_node.h:288
const node_interface & external_interface() const
Returns the object responsible for exchanging information between the node and its surrounding contex...
Definition: system_node.h:153
timer & ET() const
Returns a non-const reference to the node's event timer.
Definition: system_node.h:294
virtual scale time_precision() const =0
Returns the time precision associated with the node, or no_scale.