-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.hpp
54 lines (47 loc) · 924 Bytes
/
writer.hpp
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
#pragma once
#include <ostream>
#include "point.hpp"
#include "extract_centerline.hpp"
namespace writer
{
class JSON
{
public:
JSON(std::ostream &os)
: os{os} {};
template <class T>
void write(const std::vector<T> &vector)
{
os << "[";
for (auto it = vector.begin(); it != vector.end(); it++) {
if (it != vector.begin())
os << ",";
write(*it);
}
os << "]";
}
template <class T1, class T2>
void write(const std::pair<T1, T2> &pair)
{
os << "[";
write(pair.first);
os << ",";
write(pair.second);
os << "]";
}
void write(const extractCenterline::Centerline &line)
{
write<extractCenterline::Pixel>(line);
}
void write(const point::Point &p)
{
os << "{"
<< "\"x\":" << p()(0) << ","
<< "\"y\":" << p()(1) << ","
<< "\"thickness\":" << p.thickness()
<< "}";
}
private:
std::ostream &os;
};
}