/
hekto_builder.cpp
107 lines (93 loc) · 3.5 KB
/
hekto_builder.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2021 Zusitools
#include "hekto_builder.hpp"
#include "templates.hpp"
#include <boost/algorithm/string/replace.hpp>
#include <array>
#include <cassert>
#include <string>
#include <string_view>
#include <unordered_map>
namespace HektoBuilder {
void
Build(FILE* fd,
#ifdef LGV
Standort standort,
#endif
Kilometrierung kilometrierung)
{
const bool ist_negativ = kilometrierung.istNegativ();
const int zahl_oben = std::abs(kilometrierung.km);
const int ziffer_unten = std::abs(kilometrierung.hm);
assert(zahl_oben >= 0);
assert(zahl_oben <= 999);
assert(ziffer_unten >= 0);
assert(ziffer_unten <= 9);
std::unordered_map<std::string, float> replacements;
const auto& set_ziffer = [&](std::string_view prefix, int ziffer) {
if (ziffer == 8) {
replacements[std::string(prefix) + "_lo_u"] = 1000.0 / 2550.0;
replacements[std::string(prefix) + "_lo_v"] = 2000.0 / 2550.0;
replacements[std::string(prefix) + "_ro_u"] = 1000.0 / 2550.0;
replacements[std::string(prefix) + "_ro_v"] = 2550.0 / 2550.0;
replacements[std::string(prefix) + "_lu_u"] = 0.0 / 2550.0;
replacements[std::string(prefix) + "_lu_v"] = 2000.0 / 2550.0;
replacements[std::string(prefix) + "_ru_u"] = 0.0 / 2550.0;
replacements[std::string(prefix) + "_ru_v"] = 2550.0 / 2550.0;
} else {
std::array<double, 10> xoffsets = { 550.0, 1650.0, 0.0, 1650.0, 550.0,
1100.0, 550.0, 1100.0, 0.0, 0.0 };
std::array<double, 10> yoffsets = {
1000.0, 0.0, 0.0, 1000.0, 0.0, 0.0, 2000.0, 1000.0, 0.0, 1000.0
};
double breite = (ziffer == 6 ? -550.0 : 550.0);
double hoehe = (ziffer == 6 ? -1000.0 : 1000.0);
replacements[std::string(prefix) + "_lo_u"] = xoffsets[ziffer] / 2550.0;
replacements[std::string(prefix) + "_lo_v"] = yoffsets[ziffer] / 2550.0;
replacements[std::string(prefix) + "_ro_u"] =
(xoffsets[ziffer] + breite) / 2550.0;
replacements[std::string(prefix) + "_ro_v"] = yoffsets[ziffer] / 2550.0;
replacements[std::string(prefix) + "_lu_u"] = xoffsets[ziffer] / 2550.0;
replacements[std::string(prefix) + "_lu_v"] =
(yoffsets[ziffer] + hoehe) / 2550.0;
replacements[std::string(prefix) + "_ru_u"] =
(xoffsets[ziffer] + breite) / 2550.0;
replacements[std::string(prefix) + "_ru_v"] =
(yoffsets[ziffer] + hoehe) / 2550.0;
}
};
auto contents = [&]() {
#ifndef LGV
set_ziffer("hm", ziffer_unten);
#endif
set_ziffer("einer", zahl_oben % 10);
if (zahl_oben < 10) {
#ifdef LGV
return standort == Standort::kEigenerStandort ? templates::template1
: templates::template_mast1;
#else
return templates::template1;
#endif
}
set_ziffer("zehner", (zahl_oben / 10) % 10);
if (zahl_oben < 100) {
#ifdef LGV
return standort == Standort::kEigenerStandort ? templates::template2
: templates::template_mast2;
#else
return templates::template2;
#endif
}
set_ziffer("hunderter", (zahl_oben / 100) % 10);
#ifdef LGV
return standort == Standort::kEigenerStandort ? templates::template3
: templates::template_mast3;
#else
return templates::template3;
#endif
}();
for (const auto& [key, value] : replacements) {
boost::replace_all(contents, key, std::to_string(value));
}
fprintf(fd, "%s", contents.c_str());
}
} // namespace HektoBuilder