-
Notifications
You must be signed in to change notification settings - Fork 12
/
plus_node.h
59 lines (45 loc) · 1.3 KB
/
plus_node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#ifndef SYDEVS_EXAMPLES_PLUS_NODE_H_
#define SYDEVS_EXAMPLES_PLUS_NODE_H_
#include <sydevs/systems/function_node.h>
namespace sydevs_examples {
using namespace sydevs;
using namespace sydevs::systems;
/**
* This node adds flow inputs "a" and "b" to produce flow output "c".
*/
template<typename T>
class plus_node : public function_node
{
public:
// Constructor/Destructor:
plus_node(const std::string& node_name, const node_context& external_context);
virtual ~plus_node() = default;
// Ports:
port<flow, input, T> a_input;
port<flow, input, T> b_input;
port<flow, output, T> c_output;
private:
// Event Handlers:
virtual void flow_event();
};
template<typename T>
inline plus_node<T>::plus_node(const std::string& node_name, const node_context& external_context)
: function_node(node_name, external_context)
, a_input("a_input", external_interface())
, b_input("b_input", external_interface())
, c_output("c_output", external_interface())
{
}
template<typename T>
inline void plus_node<T>::flow_event()
{
// Get the two flow input values, add them together, and assign the result
// to the flow output port.
const T& a = a_input.value();
const T& b = b_input.value();
T c = a + b;
c_output.assign(c);
}
} // namespace
#endif