-
Notifications
You must be signed in to change notification settings - Fork 0
/
adder_node.h
72 lines (52 loc) · 1.93 KB
/
adder_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
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef SYDEVS_YAML_ADDER_NODE_H
#define SYDEVS_YAML_ADDER_NODE_H
#include <registerer/registerer.h>
#include <sydevs-yaml/systems/generic_own_node.h>
#include <utility>
using namespace sydevs::systems;
using namespace sydevs::generics;
class adder_node : public generic_own_node {
REGISTER("adder_node", generic_own_node, const std::string&, const node_context&, node_config);
public:
// Constructor/Destructor:
adder_node(const std::string& node_name, const node_context& external_context, node_config config);
~adder_node() override = default;
// Attributes:
scale time_precision() const override;
protected:
// Event Handlers:
duration initialization_event() override;
duration unplanned_event(duration elapsed_dt) override;
duration planned_event(duration elapsed_dt) override;
void finalization_event(duration elapsed_dt) override;
};
inline scale adder_node::time_precision() const {
return sydevs::nano;
}
inline adder_node::adder_node(const std::string& node_name, const node_context& external_context, node_config config)
: generic_own_node(node_name, external_context, std::move(config))
{
// Ports are declared in the .yaml config!
// Ports added here will be ignored!
}
inline duration adder_node::initialization_event()
{
print("Hello! Init");
return 0_s;
}
inline duration adder_node::unplanned_event(duration elapsed_dt)
{
print("Hello! UnPlanned_event");
if(port_received("adder")) print(get_port_as<double>("adder"));
return 0_s;
}
inline duration adder_node::planned_event(duration elapsed_dt)
{
print("Hello! Planned_event");
return 1_s;
}
inline void adder_node::finalization_event(duration elapsed_dt)
{
print("Hello! finalize");
}
#endif //SYDEVS_YAML_ADDER_NODE_H