Atlas 0.7.0
Networking protocol for the Worldforge system.
Bach.h
Go to the documentation of this file.
1// This file may be redistributed and modified under the terms of the
2// GNU Lesser General Public License (See COPYING for details).
3// Copyright (C) 2000-2001 Michael Day, Stefanus Du Toit
4
5// $Id$
6
7#ifndef ATLAS_CODECS_BACH_H
8#define ATLAS_CODECS_BACH_H
9
10#include <Atlas/Codec.h>
11
12#include <iosfwd>
13#include <stack>
14
15namespace Atlas {
16 namespace Codecs {
17
22 class Bach : public Codec {
23 public:
24
25 Bach(std::istream &in, std::ostream &out, Atlas::Bridge &b);
26
27 void poll() override;
28
29 void streamBegin() override;
30
31 void streamMessage() override;
32
33 void streamEnd() override;
34
35 void mapMapItem(std::string name) override;
36
37 void mapListItem(std::string name) override;
38
39 void mapIntItem(std::string name, std::int64_t) override;
40
41 void mapFloatItem(std::string name, double) override;
42
43 void mapStringItem(std::string name, std::string) override;
44
45 void mapNoneItem(std::string name) override;
46
47 void mapEnd() override;
48
49 void listMapItem() override;
50
51 void listListItem() override;
52
53 void listIntItem(std::int64_t) override;
54
55 void listFloatItem(double) override;
56
57 void listStringItem(std::string) override;
58
59 void listNoneItem() override;
60
61 void listEnd() override;
62
63 unsigned linenum() const { return m_linenum; }
64
65 protected:
66
67 std::istream &m_istream;
68 std::ostream &m_ostream;
69 Bridge &m_bridge;
70 bool m_comma;
71 unsigned m_linenum;
72
73 enum State {
74 PARSE_INIT,
75 PARSE_STREAM,
76 PARSE_MAP,
77 PARSE_LIST,
78 PARSE_NAME,
79 PARSE_DATA,
80 PARSE_INT,
81 PARSE_FLOAT,
82 PARSE_STRING,
83 PARSE_LITERAL, // for literal character escaped with backslash
84 PARSE_COMMENT // for when we're in the middle of a comment field
85 };
86
87 bool stringmode() const;
88
89 std::string m_name, m_data;
90 std::stack<State> m_state;
91
92 inline void parseInit(char);
93
94 inline void parseStream(char);
95
96 inline void parseMap(char);
97
98 inline void parseList(char);
99
100 inline void parseData(char);
101
102 inline void parseInt(char);
103
104 inline void parseFloat(char);
105
106 inline void parseString(char);
107
108 inline void parseLiteral(char);
109
110 inline void parseName(char);
111
112 inline void parseComment(char);
113
114 static inline std::string encodeString(std::string);
115
116 static inline std::string decodeString(std::string);
117
118 void writeIntItem(const std::string &, std::int64_t);
119
120 void writeFloatItem(const std::string &, double);
121
122 void writeStringItem(const std::string &, std::string);
123
124 void writeLine(const std::string &, bool= true, bool= false);
125 };
126
127 }
128} // namespace Atlas::Codecs
129
130#endif // ATLAS_CODECS_BACH_H
void listNoneItem() override
Definition: Bach.cpp:616
void streamEnd() override
Definition: Bach.cpp:545
void listListItem() override
Definition: Bach.cpp:596
void listFloatItem(double) override
Definition: Bach.cpp:606
void listEnd() override
Definition: Bach.cpp:622
void listStringItem(std::string) override
Definition: Bach.cpp:611
void mapNoneItem(std::string name) override
Definition: Bach.cpp:579
void listMapItem() override
Definition: Bach.cpp:591
void mapFloatItem(std::string name, double) override
Definition: Bach.cpp:569
void mapEnd() override
Definition: Bach.cpp:586
void mapIntItem(std::string name, std::int64_t) override
Definition: Bach.cpp:564
void listIntItem(std::int64_t) override
Definition: Bach.cpp:601
void streamBegin() override
Definition: Bach.cpp:540
void mapMapItem(std::string name) override
Definition: Bach.cpp:554
void mapListItem(std::string name) override
Definition: Bach.cpp:559
void streamMessage() override
Definition: Bach.cpp:549
void mapStringItem(std::string name, std::string) override
Definition: Bach.cpp:574
Definition: Bridge.h:20