SyDEVS  v0.6.5
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
node_interface.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_SYSTEMS_NODE_INTERFACE_H_
3 #define SYDEVS_SYSTEMS_NODE_INTERFACE_H_
4 
9 
10 namespace sydevs {
11 namespace systems {
12 
13 class system_node;
14 
15 
17 {
18 public:
19  node_interface(const std::string& node_name, system_node* node_ptr, const node_context& external_context);
20 
21  node_interface(const node_interface&) = delete;
22  node_interface& operator=(const node_interface&) = delete;
23  node_interface(node_interface&&) = delete;
25  virtual ~node_interface() = default;
26 
27  const std::string& node_name();
28  const std::string& full_name();
29  int64 node_index();
30 
32 
33  int64 add_flow_input_port(const std::string& port_name);
35  const std::string& flow_input_port_name(int64 port_index);
36  const pointer& flow_input_port_value(int64 port_index);
37  void clear_flow_inputs();
38  void assign_flow_input(int64 port_index, const pointer& val);
40  void set_flow_input_printable(int64 port_index, tostring_function tostring_func);
41 
42  int64 add_message_input_port(const std::string& port_name);
44  const std::string& message_input_port_name(int64 port_index);
45  const pointer& message_input_port_value(int64 port_index);
47  void clear_message_input();
48  void set_message_input(int64 port_index, const pointer& val);
50  void set_message_input_printable(int64 port_index, tostring_function tostring_func);
51 
52  int64 add_message_output_port(const std::string& port_name);
54  const std::string& message_output_port_name(int64 port_index);
56  int64 message_output_index(int64 list_index);
57  const pointer& message_output_value(int64 list_index);
58  void clear_message_outputs();
59  void append_message_output(int64 port_index, const pointer& val);
61  void set_message_output_printable(int64 port_index, tostring_function tostring_func);
62 
63  int64 add_flow_output_port(const std::string& port_name);
65  const std::string& flow_output_port_name(int64 port_index);
66  const pointer& flow_output_port_value(int64 port_index);
67  void clear_flow_outputs();
68  void assign_flow_output(int64 port_index, const pointer& val);
70  void set_flow_output_printable(int64 port_index, tostring_function tostring_func);
71 
73  void deactivate();
74 
75  bool active() const;
76  data_mode dmode() const;
77  data_goal dgoal() const;
78 
81 
82  void print_port_value(const std::string& port_name, const std::string& val_string);
83  void print_flow_input(int64 port_index);
84  void print_message_input(int64 port_index);
85  void print_message_output(int64 list_index, int64 port_index);
86  void print_flow_output(int64 port_index);
87 
88  void print_command_text(const std::string& command, const std::string& text);
89 
90  bool print_on_event_flag();
91  void print_on_event(bool flag = true);
92  void print_event(const std::string& text);
93 
95  void print_on_elapsed_duration(bool flag);
96  void print_elapsed_duration(duration elapsed_dt);
97 
99  void print_on_planned_duration(bool flag);
100  void print_planned_duration(duration planned_dt);
101 
102 private:
103  void print(const std::string& text);
104 
105  std::string node_name_;
106  std::string full_name_;
107  int64 node_index_;
108 
109  node_context& external_context_;
110 
111  std::vector<std::string> flow_input_port_names_;
112  std::vector<tostring_function> flow_input_port_tostring_funcs_;
113  std::vector<pointer> flow_input_port_vals_;
114 
115  std::vector<std::string> message_input_port_names_;
116  std::vector<tostring_function> message_input_port_tostring_funcs_;
117  std::vector<pointer> message_input_port_vals_;
118  int64 message_input_port_index_;
119 
120  std::vector<std::string> message_output_port_names_;
121  std::vector<tostring_function> message_output_port_tostring_funcs_;
122  std::vector<int64> message_output_indices_;
123  std::vector<pointer> message_output_vals_;
124 
125  std::vector<std::string> flow_output_port_names_;
126  std::vector<tostring_function> flow_output_port_tostring_funcs_;
127  std::vector<pointer> flow_output_port_vals_;
128 
129  bool active_;
130  data_mode dmode_;
131  data_goal dgoal_;
132 
133  bool print_on_event_;
134  bool print_on_elapsed_duration_;
135  bool print_on_planned_duration_;
136 };
137 
138 
139 inline const std::string& node_interface::node_name()
140 {
141  return node_name_;
142 }
143 
144 
145 inline const std::string& node_interface::full_name()
146 {
147  return full_name_;
148 }
149 
150 
152 {
153  return node_index_;
154 }
155 
156 
158 {
159  return external_context_;
160 }
161 
162 
164 {
165  active_ = true;
166  dmode_ = dmode;
167  dgoal_ = dgoal;
168 }
169 
170 
172 {
173  active_ = false;
174 }
175 
176 
177 inline bool node_interface::active() const
178 {
179  return active_;
180 }
181 
182 
184 {
185  return dmode_;
186 }
187 
188 
190 {
191  return dgoal_;
192 }
193 
194 
195 } // namespace
196 } // namespace
197 
198 #endif
void clear_flow_outputs()
Definition: node_interface.cpp:244
node_interface & operator=(const node_interface &)=delete
No copy assignment.
const std::string & flow_output_port_name(int64 port_index)
Definition: node_interface.cpp:232
int64 message_input_port_count()
Definition: node_interface.cpp:101
void print_message_input(int64 port_index)
Definition: node_interface.cpp:311
void assign_flow_output(int64 port_index, const pointer &val)
Definition: node_interface.cpp:250
int64 add_message_input_port(const std::string &port_name)
Definition: node_interface.cpp:92
void clear_message_input()
Definition: node_interface.cpp:125
tostring_function message_output_tostring_func(int64 port_index)
Definition: node_interface.cpp:205
int64 missing_flow_input()
Definition: node_interface.cpp:268
int64 node_index()
Definition: node_interface.h:151
const std::string & message_output_port_name(int64 port_index)
Definition: node_interface.cpp:167
bool print_on_event_flag()
Definition: node_interface.cpp:350
std::function< std::string(const pointer &)> tostring_function
Definition: qualified_type.h:19
data_mode
Indicates the relevant data communication paradigm: dataflow (flow) or message-passing (message)...
Definition: data_mode.h:16
A base class for all nodes from which systems models are constructed.
Definition: system_node.h:41
const pointer & message_output_value(int64 list_index)
Definition: node_interface.cpp:185
void print_on_event(bool flag=true)
Definition: node_interface.cpp:356
void print_elapsed_duration(duration elapsed_dt)
Definition: node_interface.cpp:382
void print_flow_input(int64 port_index)
Definition: node_interface.cpp:300
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
tostring_function flow_input_tostring_func(int64 port_index)
Definition: node_interface.cpp:80
void print_message_output(int64 list_index, int64 port_index)
Definition: node_interface.cpp:322
void set_flow_input_printable(int64 port_index, tostring_function tostring_func)
Definition: node_interface.cpp:86
void clear_message_outputs()
Definition: node_interface.cpp:191
const std::string & flow_input_port_name(int64 port_index)
Definition: node_interface.cpp:56
data_goal dgoal() const
Definition: node_interface.h:189
void deactivate()
Definition: node_interface.h:171
node_context & external_context()
Definition: node_interface.h:157
virtual ~node_interface()=default
Destructor.
int64 add_message_output_port(const std::string &port_name)
Definition: node_interface.cpp:153
void print_flow_output(int64 port_index)
Definition: node_interface.cpp:333
int64 message_input_port_index()
Definition: node_interface.cpp:119
int64 message_output_port_count()
Definition: node_interface.cpp:161
void print_on_planned_duration(bool flag)
Definition: node_interface.cpp:396
bool print_on_elapsed_duration_flag()
Definition: node_interface.cpp:370
const std::string & node_name()
Definition: node_interface.h:139
bool print_on_planned_duration_flag()
Definition: node_interface.cpp:390
int64 message_output_list_size()
Definition: node_interface.cpp:173
void print_port_value(const std::string &port_name, const std::string &val_string)
Definition: node_interface.cpp:294
int64 flow_output_port_count()
Definition: node_interface.cpp:226
data_goal
Indicates whether data is meant to serve as input or output.
Definition: data_goal.h:15
node_interface(const std::string &node_name, system_node *node_ptr, const node_context &external_context)
Definition: node_interface.cpp:8
int64 flow_input_port_count()
Definition: node_interface.cpp:50
tostring_function flow_output_tostring_func(int64 port_index)
Definition: node_interface.cpp:256
void set_message_output_printable(int64 port_index, tostring_function tostring_func)
Definition: node_interface.cpp:211
void set_flow_output_printable(int64 port_index, tostring_function tostring_func)
Definition: node_interface.cpp:262
Definition: node_context.h:16
Definition: node_interface.h:16
void clear_flow_inputs()
Definition: node_interface.cpp:68
void activate(data_mode dmode, data_goal dgoal)
Definition: node_interface.h:163
void print_event(const std::string &text)
Definition: node_interface.cpp:362
int64 add_flow_output_port(const std::string &port_name)
Definition: node_interface.cpp:217
bool active() const
Definition: node_interface.h:177
void print_planned_duration(duration planned_dt)
Definition: node_interface.cpp:402
int64 add_flow_input_port(const std::string &port_name)
Definition: node_interface.cpp:41
void set_message_input(int64 port_index, const pointer &val)
Definition: node_interface.cpp:134
int64 message_output_index(int64 list_index)
Definition: node_interface.cpp:179
void print_on_elapsed_duration(bool flag)
Definition: node_interface.cpp:376
tostring_function message_input_tostring_func(int64 port_index)
Definition: node_interface.cpp:141
void append_message_output(int64 port_index, const pointer &val)
Definition: node_interface.cpp:198
const pointer & flow_input_port_value(int64 port_index)
Definition: node_interface.cpp:62
void set_message_input_printable(int64 port_index, tostring_function tostring_func)
Definition: node_interface.cpp:147
void assign_flow_input(int64 port_index, const pointer &val)
Definition: node_interface.cpp:74
const pointer & message_input_port_value(int64 port_index)
Definition: node_interface.cpp:113
int64 missing_flow_output()
Definition: node_interface.cpp:281
const std::string & message_input_port_name(int64 port_index)
Definition: node_interface.cpp:107
const pointer & flow_output_port_value(int64 port_index)
Definition: node_interface.cpp:238
data_mode dmode() const
Definition: node_interface.h:183
A data type which represents a pointer to anything.
Definition: pointer.h:27