Atlas  0.7.0
Networking protocol for the Worldforge system.
XML.h
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_XML_H
8 #define ATLAS_CODECS_XML_H
9 
10 #include <Atlas/Codec.h>
11 
12 #include <iosfwd>
13 #include <stack>
14 
15 namespace Atlas {
16  namespace Codecs {
17 
18 /*
19 
20 Sample output for this codec: (whitespace added for clarity)
21 
22 <atlas>
23  <map>
24  <int name="foo">13</int>
25  <float name="meep">1.5</float>
26  <string name="bar">hello</string>
27  <list name="args">
28  <int>1</int>
29  <int>2</int>
30  <float>3.0</float>
31  </list>
32  </map>
33 </atlas>
34 
35 The complete specification is located in cvs at:
36  forge/protocols/atlas/spec/xml_syntax.html
37 
38 */
39 
40  class XML : public Codec {
41  public:
42 
43  XML(std::istream &in, std::ostream &out, Atlas::Bridge &b);
44 
45  void poll() override;
46 
47  void streamBegin() override;
48 
49  void streamMessage() override;
50 
51  void streamEnd() override;
52 
53  void mapMapItem(std::string name) override;
54 
55  void mapListItem(std::string name) override;
56 
57  void mapIntItem(std::string name, std::int64_t) override;
58 
59  void mapFloatItem(std::string name, double) override;
60 
61  void mapStringItem(std::string name, std::string) override;
62 
63  void mapNoneItem(std::string name) override;
64 
65  void mapEnd() override;
66 
67  void listMapItem() override;
68 
69  void listListItem() override;
70 
71  void listIntItem(std::int64_t) override;
72 
73  void listFloatItem(double) override;
74 
75  void listStringItem(std::string) override;
76 
77  void listNoneItem() override;
78 
79  void listEnd() override;
80 
86  static std::string escape(const std::string &);
87 
93  static std::string unescape(const std::string &);
94 
95  protected:
96 
97  std::istream &m_istream;
98  std::ostream &m_ostream;
99  Bridge &m_bridge;
100 
101  enum Token {
102  TOKEN_TAG,
103  TOKEN_START_TAG,
104  TOKEN_END_TAG,
105  TOKEN_DATA
106  };
107 
108  Token m_token;
109 
110  enum State {
111  PARSE_NOTHING,
112  PARSE_STREAM,
113  PARSE_MAP,
114  PARSE_LIST,
115  PARSE_INT,
116  PARSE_FLOAT,
117  PARSE_STRING,
118  PARSE_NONE
119  };
120 
121  std::stack<State> m_state;
122  std::stack<std::string> m_data;
123 
124  std::string m_tag;
125  std::string m_name;
126 
127  inline void tokenTag(char);
128 
129  inline void tokenStartTag(char);
130 
131  inline void tokenEndTag(char);
132 
133  inline void tokenData(char);
134 
135  inline void parseStartTag();
136 
137  inline void parseEndTag();
138 
139  };
140 
141  }
142 } // namespace Atlas::Codecs
143 
144 #endif // ATLAS_CODECS_XML_H
Atlas::Codecs::XML::streamMessage
void streamMessage() override
Definition: XML.cpp:341
Atlas::Codecs::XML::mapEnd
void mapEnd() override
Definition: XML.cpp:369
Atlas::Codecs::XML
Definition: XML.h:40
Atlas::Codecs::XML::mapStringItem
void mapStringItem(std::string name, std::string) override
Definition: XML.cpp:361
Atlas::Codecs::XML::listListItem
void listListItem() override
Definition: XML.cpp:377
Atlas::Codecs::XML::listEnd
void listEnd() override
Definition: XML.cpp:397
Atlas::Codecs::XML::listStringItem
void listStringItem(std::string) override
Definition: XML.cpp:389
Atlas::Codec
Definition: Codec.h:28
Atlas::Codecs::XML::mapListItem
void mapListItem(std::string name) override
Definition: XML.cpp:349
Atlas::Codecs::XML::escape
static std::string escape(const std::string &)
Definition: XML.cpp:401
Atlas::Codecs::XML::listMapItem
void listMapItem() override
Definition: XML.cpp:373
Atlas::Codecs::XML::mapFloatItem
void mapFloatItem(std::string name, double) override
Definition: XML.cpp:357
Atlas::Codecs::XML::streamBegin
void streamBegin() override
Definition: XML.cpp:333
Atlas::Codecs::XML::unescape
static std::string unescape(const std::string &)
Definition: XML.cpp:429
Atlas::Codecs::XML::listNoneItem
void listNoneItem() override
Definition: XML.cpp:393
Atlas::Codecs::XML::mapMapItem
void mapMapItem(std::string name) override
Definition: XML.cpp:345
Atlas::Bridge
Definition: Bridge.h:36
Atlas::Codecs::XML::listIntItem
void listIntItem(std::int64_t) override
Definition: XML.cpp:381
Atlas::Codecs::XML::mapNoneItem
void mapNoneItem(std::string name) override
Definition: XML.cpp:365
Atlas::Codecs::XML::streamEnd
void streamEnd() override
Definition: XML.cpp:337
Atlas::Codecs::XML::mapIntItem
void mapIntItem(std::string name, std::int64_t) override
Definition: XML.cpp:353
Atlas
Definition: Bridge.h:20
Atlas::Codecs::XML::listFloatItem
void listFloatItem(double) override
Definition: XML.cpp:385