-
Notifications
You must be signed in to change notification settings - Fork 2
/
yamlgen.cpp
55 lines (50 loc) · 1.64 KB
/
yamlgen.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
#include "yamlgen.hpp"
std::string YamlGen::to_string_with_precision(const double value) {
std::ostringstream out;
out.precision(PRECISION);
out<<std::fixed<<value;
return out.str();
}
void YamlGen::addvlr(double v, double l, double r, bool last) {
vlrrows+=2;
kainjow::mustache::data pair;
pair.set("x", to_string_with_precision(l));
pair.set("y", to_string_with_precision(v));
pair.set("last", false);
coorduv<<kainjow::mustache::data{pair};
pair.set("x", to_string_with_precision(r));
pair.set("y", to_string_with_precision(v));
pair.set("last", last);
coorduv<<kainjow::mustache::data{pair};
}
void YamlGen::addylr(double y1, double x1, double y2, double x2, bool last) {
ylrrows+=2;
kainjow::mustache::data pair;
pair.set("x", to_string_with_precision(x1));
pair.set("y", to_string_with_precision(y1));
pair.set("last", false);
coordxy<<kainjow::mustache::data{pair};
pair.set("x", to_string_with_precision(x2));
pair.set("y", to_string_with_precision(y2));
pair.set("last", last);
coordxy<<kainjow::mustache::data{pair};
}
std::string YamlGen::readFile(std::string name){
std::ifstream ifs(name, std::ios::binary);
std::stringstream buffer;
buffer<<ifs.rdbuf();
ifs.close();
return buffer.str();
}
void YamlGen::generate(){
data.set("rows", std::to_string(vlrrows));
data.set("coorduv", coorduv);
data.set("rows", std::to_string(ylrrows));
data.set("coordxy", coordxy);
kainjow::mustache::mustache tpl{readFile("points-matrix.tpl")};
// Generate yaml file
std::ofstream yaml;
yaml.open ("points_matrix.yaml");
yaml<<tpl.render(data);
yaml.close();
}