2 #ifndef SYDEVS_SYSTEMS_PORT_H_
3 #define SYDEVS_SYSTEMS_PORT_H_
17 template<data_mode dmode, data_goal dgoal,
typename T>
38 const std::string port_name_;
39 const int64 port_index_;
52 template<data_mode dmode, data_goal dgoal,
typename T>
90 const T& value()
const;
92 void print_on_use(
bool flag =
true)
const;
128 bool received()
const;
129 const T& value()
const;
131 void print_on_use(
bool flag =
true)
const;
167 void send(
const T& val);
169 void print_on_use(
bool flag =
true)
const;
205 void assign(
const T& val);
207 void print_on_use(
bool flag =
true)
const;
211 template<data_mode dmode, data_goal dgoal,
typename T>
218 template<data_mode dmode, data_goal dgoal,
typename T>
225 template<data_mode dmode, data_goal dgoal,
typename T>
228 return external_interface_.node_index();
232 template<data_mode dmode, data_goal dgoal,
typename T>
235 return external_interface_;
239 template<data_mode dmode, data_goal dgoal,
typename T>
241 : port_name_(port_name)
242 , port_index_(port_index)
243 , external_interface_(external_interface)
247 throw std::logic_error(
"Invalid data type for port (" + this->
port_name() +
") " +
248 "of node (" + full_node_name +
")");
257 const_cast<
node_interface&>(external_interface).add_flow_input_port(port_name),
268 throw std::logic_error(
"Attempt to get value on flow input port (" + this->
port_name() +
") " +
269 "of inactive node (" + full_node_name +
")");
272 return const_cast<const T&
>(val.template dereference<T>());
279 auto tostring_func = flag ? tostring_converter<T>() :
nullptr;
288 const_cast<
node_interface&>(external_interface).add_message_input_port(port_name),
299 throw std::logic_error(
"Attempt to check message input port (" + this->
port_name() +
") " +
300 "of inactive node (" + full_node_name +
")");
304 throw std::logic_error(
"Attempt to check message input port (" + this->
port_name() +
") " +
305 "of node (" + full_node_name +
") outside of unplanned event");
316 throw std::logic_error(
"Attempt to get value on message input port (" + this->
port_name() +
") " +
317 "of inactive node (" + full_node_name +
")");
321 throw std::logic_error(
"Attempt to get value on message input port (" + this->
port_name() +
") " +
322 "of node (" + full_node_name +
") outside of unplanned event");
325 return const_cast<const T&
>(val.template dereference<T>());
332 auto tostring_func = flag ? tostring_converter<T>() :
nullptr;
341 const_cast<
node_interface&>(external_interface).add_message_output_port(port_name),
352 throw std::logic_error(
"Attempt to send value on message output port (" + this->
port_name() +
") " +
353 "of inactive node (" + full_node_name +
")");
357 throw std::logic_error(
"Attempt to send value on message output port (" + this->
port_name() +
") " +
358 "of node (" + full_node_name +
") outside of planned event");
367 auto tostring_func = flag ? tostring_converter<T>() :
nullptr;
376 const_cast<
node_interface&>(external_interface).add_flow_output_port(port_name),
387 throw std::logic_error(
"Attempt to assign value on flow output port (" + this->
port_name() +
") " +
388 "of inactive node (" + full_node_name +
")");
392 throw std::logic_error(
"Attempt to assign value on flow output port (" + this->
port_name() +
") " +
393 "of node (" + full_node_name +
") outside of initialization or finalization event");
402 auto tostring_func = flag ? tostring_converter<T>() :
nullptr;
const auto output
Equivalent to data_goal::output.
Definition: data_goal.h:22
A base class template for all port classes.
Definition: port.h:18
const auto input
Equivalent to data_goal::input.
Definition: data_goal.h:21
A generic port class template declaration.
Definition: port.h:53
Definition: qualified_type.h:24
port_base(const port_base &)=delete
No copy constructor.
const std::string & port_name() const
Returns the name of the port.
Definition: port.h:212
port_base & operator=(const port_base &)=delete
No copy assignment.
static pointer copy(const T &X)
If T is a qualified type, returns a deep copy of X.
Definition: qualified_type.h:174
Definition: node_interface.h:16
const auto flow
Equivalent to data_mode::flow.
Definition: data_mode.h:22
Indicates message-passing.
const auto message
Equivalent to data_mode::message.
Definition: data_mode.h:23
int64 node_index() const
Returns the index of the node within the encompassing node_structure object.
Definition: port.h:226
int64 port_index() const
Returns the index of the port within the encompassing node_interface object.
Definition: port.h:219
virtual ~port_base()=default
Destructor.
const node_interface & external_interface() const
Returns the encomassing node_interface object.
Definition: port.h:233