blob: e482532766008fb606f3440baa658fa4fd797eb6 (
plain)
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
|
/*
*/
#include <serialise.hpp>
#include <serialiser_texttree.hpp>
Serialiser& Serialiser::operator<<(const Serialisable& subobj)
{
start_object(subobj.serialise_tag());
subobj.serialise(*this);
end_object(subobj.serialise_tag());
return *this;
}
Serialiser_TextTree::Serialiser_TextTree(::std::ostream& os):
m_os(os)
{
}
void Serialiser_TextTree::start_object(const char *tag) {
print_indent();
m_os << tag << "{\n";
indent();
}
void Serialiser_TextTree::end_object(const char *_tag) {
unindent();
print_indent();
m_os << "}\n";
}
void Serialiser_TextTree::start_array(unsigned int size) {
print_indent();
if( size == 0 )
m_os << "[";
else
m_os << "[\n";
indent();
}
void Serialiser_TextTree::end_array() {
unindent();
print_indent();
m_os << "]\n";
}
Serialiser& Serialiser_TextTree::operator<<(bool val)
{
print_indent();
m_os << (val ? "true" : "false") << "\n";
return *this;
}
Serialiser& Serialiser_TextTree::operator<<(unsigned int val)
{
print_indent();
m_os << val << "\n";
return *this;
}
Serialiser& Serialiser_TextTree::operator<<(const ::std::string& s)
{
print_indent();
m_os << "\"" << s << "\"\n";
return *this;
}
void Serialiser_TextTree::indent()
{
m_indent_level ++;
}
void Serialiser_TextTree::unindent()
{
m_indent_level --;
}
void Serialiser_TextTree::print_indent()
{
for(int i = 0; i < m_indent_level; i ++)
m_os << " ";
}
|