SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
function_node.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_SYSTEMS_FUNCTION_NODE_H_
3 #define SYDEVS_SYSTEMS_FUNCTION_NODE_H_
4 
6 
7 namespace sydevs {
8 namespace systems {
9 
10 
21 class function_node : public system_node
22 {
23 public:
34  function_node(const std::string& node_name, const node_context& external_context);
35 
36  virtual ~function_node() = default;
37 
38  data_mode node_dmode() const;
39  scale time_precision() const;
40 
44  void handle_finalization_event(duration elapsed_dt);
45 
46 private:
47  void adopt_component_print_flags(const system_node& node) const;
48 
49  virtual void flow_event() = 0;
50 };
51 
52 
53 inline function_node::function_node(const std::string& node_name, const node_context& external_context)
54  : system_node(node_name, external_context)
55 {
56 }
57 
58 
60 {
61  return flow;
62 }
63 
64 
66 {
67  return no_scale;
68 }
69 
70 
72 {
73  ET().start();
74  flow_event();
75  ET().stop();
76  return duration::inf();
77 }
78 
79 
81 {
82  throw std::logic_error("Unexpected unplanned event invoked for function node");
83  return duration::inf();
84 }
85 
86 
88 {
89  throw std::logic_error("Unexpected planned event invoked for function node");
90  return duration::inf();
91 }
92 
93 
95 {
96  throw std::logic_error("Unexpected finalization event invoked for function node");
97 }
98 
99 
100 inline void function_node::adopt_component_print_flags(const system_node& node) const
101 {
102 }
103 
104 
105 } // namespace
106 } // namespace
107 
108 #endif
const std::string & node_name() const
Returns the name of the node.
Definition: system_node.h:135
void handle_finalization_event(duration elapsed_dt)
Never invoked for function nodes.
Definition: function_node.h:94
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
constexpr scale no_scale
Definition: scale.h:153
virtual ~function_node()=default
Destructor.
duration handle_initialization_event()
Invoked when all flow input ports have values; calls flow_event.
Definition: function_node.h:71
A data type which represents the general concept of scale as a dimensionless power of 1000...
Definition: scale.h:70
static constexpr quantity inf()
duration handle_unplanned_event(duration elapsed_dt)
Never invoked for function nodes.
Definition: function_node.h:80
Definition: node_context.h:16
void start()
Starts the timer.
Definition: timer.h:84
A base class for indivisible nodes in which function behavior is procedurally encoded.
Definition: function_node.h:21
scale time_precision() const
Returns no_scale for all function nodes.
Definition: function_node.h:65
data_mode node_dmode() const
Returns message for all atomic nodes.
Definition: function_node.h:59
function_node(const std::string &node_name, const node_context &external_context)
Constructs a function_node.
Definition: function_node.h:53
timer & ET() const
Returns a non-const reference to the node's event timer.
Definition: system_node.h:294
duration handle_planned_event(duration elapsed_dt)
Never invoked for function nodes.
Definition: function_node.h:87