-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleModel.cpp
81 lines (74 loc) · 1.88 KB
/
ExampleModel.cpp
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
73
74
75
76
77
78
79
80
81
#include "ExampleModel.h"
#include "StringConversions.h"
ExampleModel::ExampleModel()
: Model({"iParam", "fParam"}, {"sInput", "vfInput"}, {"viOutput", "bOutput"}) {}
void ExampleModel::Process(float t, const float dt) {
if (t == 0) {
bOutput = false;
viOutput = {1, 4, -3};
}
else {
viOutput = {9, 8, -10};
}
if (t == 3)
bOutput = true;
}
void ExampleModel::SetParam(const int index, const std::string& valueString) {
switch (index) {
case 0:
iParam = FromString<int>(valueString);
break;
case 1:
fParam = FromString<float>(valueString);
break;
default:
std::cerr << "Given parameter index out of bounds! Possible mismatch between parameter file and model.\n";
exit(1);
}
}
void ExampleModel::SetInput(const int index, const std::string& valueString) {
switch (index) {
case 0:
sInput = valueString;
break;
case 1:
vfInput = VectorFromString<float>(valueString);
break;
default:
std::cerr << "Given input index out of bounds! Possible mismatch between input file and model.\n";
exit(1);
}
}
std::string ExampleModel::GetParam(const int index) const {
switch (index) {
case 0:
return std::to_string(iParam);
case 1:
return std::to_string(fParam);
default:
std::cerr << "Given parameter index out of bounds! Possible mismatch between parameter file and model.\n";
exit(1);
}
}
std::string ExampleModel::GetInput(const int index) const {
switch (index) {
case 0:
return sInput;
case 1:
return VectorToString<float>(vfInput);
default:
std::cerr << "Given output index out of bounds! Possible mismatch between output file and model.\n";
exit(1);
}
}
std::string ExampleModel::GetOutput(const int index) const {
switch (index) {
case 0:
return VectorToString<int>(viOutput);
case 1:
return std::to_string(bOutput);
default:
std::cerr << "Requested output index out of bounds! Possible mismatch between output file and model.\n";
exit(1);
}
}