SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parameter_node.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_SYSTEMS_PARAMETER_NODE_H_
3 #define SYDEVS_SYSTEMS_PARAMETER_NODE_H_
4 
6 
7 namespace sydevs {
8 namespace systems {
9 
10 
19 template<typename T>
21 {
22 public:
35  parameter_node(const std::string& node_name, const node_context& external_context);
36 
50  parameter_node(const std::string& node_name, const node_context& external_context, const T& X);
51 
53 
54  const T& value() const;
55  void set_value(const T& X);
56 
57 private:
58  pointer val_;
59 
60  virtual void flow_event();
61 };
62 
63 
64 template<typename T>
65 inline parameter_node<T>::parameter_node(const std::string& node_name, const node_context& external_context)
66  : function_node(node_name, external_context)
67  , parameter("parameter", external_interface())
68  , val_()
69 {
70 }
71 
72 
73 template<typename T>
74 inline parameter_node<T>::parameter_node(const std::string& node_name, const node_context& external_context, const T& X)
75  : function_node(node_name, external_context)
76  , parameter("parameter", external_interface())
77  , val_(qualified_type<T>::copy(X))
78 {
79 }
80 
81 
82 template<typename T>
83 inline const T& parameter_node<T>::value() const
84 {
85  if (!val_) throw std::logic_error("No value provided for parameter node (" + full_name() + ")");
86  return val_.dereference<T>();
87 }
88 
89 
90 template<typename T>
91 inline void parameter_node<T>::set_value(const T& X)
92 {
93  val_ = qualified_type<T>::copy(X);
94 }
95 
96 
97 template<typename T>
99 {
100  parameter.assign(value());
101 }
102 
103 
104 } // namespace
105 } // namespace
106 
107 #endif
port< flow, output, T > parameter
The flow output port on which the parameter value is provided.
Definition: parameter_node.h:52
const std::string & node_name() const
Returns the name of the node.
Definition: system_node.h:135
Definition: qualified_type.h:24
A class template for nodes which supply parameter values.
Definition: parameter_node.h:20
parameter_node(const std::string &node_name, const node_context &external_context)
Constructs a parameter_node.
Definition: parameter_node.h:65
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_context.h:16
void set_value(const T &X)
Sets the parameter value to X.
Definition: parameter_node.h:91
A base class for indivisible nodes in which function behavior is procedurally encoded.
Definition: function_node.h:21
A class template for flow output ports.
Definition: port.h:183
const T & value() const
Returns the parameter value.
Definition: parameter_node.h:83
A data type which represents a pointer to anything.
Definition: pointer.h:27