Atlas  0.7.0
Networking protocol for the Worldforge system.
Formatter.cpp
1 // This file may be redistributed and modified only under the terms of
2 // the GNU Lesser General Public License (See COPYING for details).
3 // Copyright (C) 2005 Alistair Riddoch
4 
5 // $Id$
6 
7 #include <Atlas/Formatter.h>
8 
9 #include <iostream>
10 
11 namespace Atlas {
12 
13 
14 Formatter::Formatter(std::ostream & s, Atlas::Bridge & b) : m_stream(s),
15  m_bridge(b),
16  m_indent(0),
17  m_spacing(2)
18 {
19 }
20 
21 void Formatter::streamBegin()
22 {
23  m_bridge.streamBegin();
24  m_indent = m_spacing;
25  m_stream << std::endl;
26 }
27 
28 void Formatter::streamMessage()
29 {
30  m_stream << std::endl;
31  m_stream << std::string(m_indent, ' ');
32  m_bridge.streamMessage();
33  m_indent += m_spacing;
34  m_stream << std::endl;
35 }
36 
37 void Formatter::streamEnd()
38 {
39  m_stream << std::endl;
40  m_bridge.streamEnd();
41  m_stream << std::endl;
42 }
43 
44 
45 void Formatter::mapMapItem(std::string name)
46 {
47  m_stream << std::string(m_indent, ' ');
48  m_bridge.mapMapItem(std::move(name));
49  m_indent += m_spacing;
50  m_stream << std::endl;
51 }
52 
53 void Formatter::mapListItem(std::string name)
54 {
55  m_stream << std::string(m_indent, ' ');
56  m_bridge.mapListItem(std::move(name));
57 }
58 
59 void Formatter::mapIntItem(std::string name, std::int64_t l)
60 {
61  m_stream << std::string(m_indent, ' ');
62  m_bridge.mapIntItem(std::move(name), l);
63  m_stream << std::endl;
64 }
65 
66 void Formatter::mapFloatItem(std::string name, double d)
67 {
68  m_stream << std::string(m_indent, ' ');
69  m_bridge.mapFloatItem(std::move(name), d);
70  m_stream << std::endl;
71 }
72 
73 void Formatter::mapStringItem(std::string name, std::string s)
74 {
75  m_stream << std::string(m_indent, ' ');
76  m_bridge.mapStringItem(std::move(name), std::move(s));
77  m_stream << std::endl;
78 }
79 
80 void Formatter::mapNoneItem(std::string name) {
81  m_stream << std::string(m_indent, ' ');
82  m_bridge.mapNoneItem(std::move(name));
83  m_stream << std::endl;
84 }
85 
86 void Formatter::mapEnd()
87 {
88  m_indent -= m_spacing;
89  m_stream << std::string(m_indent, ' ');
90  m_bridge.mapEnd();
91  m_stream << std::endl;
92 }
93 
94 
95 void Formatter::listMapItem()
96 {
97  m_stream << std::string(m_indent, ' ');
98  m_bridge.listMapItem();
99  m_indent += m_spacing;
100  m_stream << std::endl;
101 }
102 
103 void Formatter::listListItem()
104 {
105  m_bridge.listListItem();
106 }
107 
108 void Formatter::listIntItem(std::int64_t l)
109 {
110  m_bridge.listIntItem(l);
111 }
112 
113 void Formatter::listFloatItem(double d)
114 {
115  m_bridge.listFloatItem(d);
116 }
117 
118 void Formatter::listStringItem(std::string s)
119 {
120  m_bridge.listStringItem(std::move(s));
121 }
122 
123 void Formatter::listNoneItem() {
124  m_bridge.listNoneItem();
125 }
126 
127 void Formatter::listEnd()
128 {
129  m_bridge.listEnd();
130  m_stream << std::endl;
131 }
132 
133 } // Atlas namespace
Definition: Bridge.h:20