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 
22 {
23  m_bridge.streamBegin();
24  m_indent = m_spacing;
25  m_stream << std::endl;
26 }
27 
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 
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 
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 
96 {
97  m_stream << std::string(m_indent, ' ');
98  m_bridge.listMapItem();
99  m_indent += m_spacing;
100  m_stream << std::endl;
101 }
102 
104 {
105  m_bridge.listListItem();
106 }
107 
108 void Formatter::listIntItem(std::int64_t l)
109 {
110  m_bridge.listIntItem(l);
111 }
112 
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 
124  m_bridge.listNoneItem();
125 }
126 
128 {
129  m_bridge.listEnd();
130  m_stream << std::endl;
131 }
132 
133 } // Atlas namespace
Atlas::Formatter::mapEnd
void mapEnd() override
Definition: Formatter.cpp:86
Atlas::Formatter::listIntItem
void listIntItem(std::int64_t) override
Definition: Formatter.cpp:108
Atlas::Bridge::listMapItem
virtual void listMapItem()=0
Atlas::Formatter::streamMessage
void streamMessage() override
Definition: Formatter.cpp:28
Atlas::Formatter::mapListItem
void mapListItem(std::string name) override
Definition: Formatter.cpp:53
Atlas::Formatter::mapNoneItem
void mapNoneItem(std::string name) override
Definition: Formatter.cpp:80
Atlas::Formatter::mapStringItem
void mapStringItem(std::string name, std::string) override
Definition: Formatter.cpp:73
Atlas::Bridge::listNoneItem
virtual void listNoneItem()=0
Atlas::Formatter::listNoneItem
void listNoneItem() override
Definition: Formatter.cpp:123
Atlas::Bridge::mapMapItem
virtual void mapMapItem(std::string name)=0
Atlas::Bridge::streamBegin
virtual void streamBegin()=0
Atlas::Formatter::listListItem
void listListItem() override
Definition: Formatter.cpp:103
Atlas::Bridge::listStringItem
virtual void listStringItem(std::string)=0
Atlas::Formatter::streamBegin
void streamBegin() override
Definition: Formatter.cpp:21
Atlas::Formatter::listFloatItem
void listFloatItem(double) override
Definition: Formatter.cpp:113
Atlas::Formatter::listEnd
void listEnd() override
Definition: Formatter.cpp:127
Atlas::Bridge::listListItem
virtual void listListItem()=0
Atlas::Bridge::mapIntItem
virtual void mapIntItem(std::string name, std::int64_t)=0
Atlas::Formatter::mapMapItem
void mapMapItem(std::string name) override
Definition: Formatter.cpp:45
Atlas::Bridge::listFloatItem
virtual void listFloatItem(double)=0
Atlas::Formatter::mapFloatItem
void mapFloatItem(std::string name, double) override
Definition: Formatter.cpp:66
Atlas::Bridge
Definition: Bridge.h:36
Atlas::Bridge::mapListItem
virtual void mapListItem(std::string name)=0
Atlas::Bridge::mapEnd
virtual void mapEnd()=0
Atlas::Formatter::streamEnd
void streamEnd() override
Definition: Formatter.cpp:37
Atlas::Bridge::streamEnd
virtual void streamEnd()=0
Atlas::Bridge::listEnd
virtual void listEnd()=0
Atlas::Formatter::mapIntItem
void mapIntItem(std::string name, std::int64_t) override
Definition: Formatter.cpp:59
Atlas::Bridge::mapStringItem
virtual void mapStringItem(std::string name, std::string)=0
Atlas::Bridge::mapFloatItem
virtual void mapFloatItem(std::string name, double)=0
Atlas::Bridge::streamMessage
virtual void streamMessage()=0
Atlas::Bridge::mapNoneItem
virtual void mapNoneItem(std::string name)=0
Atlas::Formatter::listStringItem
void listStringItem(std::string) override
Definition: Formatter.cpp:118
Atlas::Formatter::listMapItem
void listMapItem() override
Definition: Formatter.cpp:95
Atlas::Bridge::listIntItem
virtual void listIntItem(std::int64_t)=0
Atlas
Definition: Bridge.h:20