Atlas-C++
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 { namespace Codecs {
16 
17 /*
18 
19 Sample output for this codec: (whitespace added for clarity)
20 
21 <atlas>
22  <map>
23  <int name="foo">13</int>
24  <float name="meep">1.5</float>
25  <string name="bar">hello</string>
26  <list name="args">
27  <int>1</int>
28  <int>2</int>
29  <float>3.0</float>
30  </list>
31  </map>
32 </atlas>
33 
34 The complete specification is located in cvs at:
35  forge/protocols/atlas/spec/xml_syntax.html
36 
37 */
38 
39 class XML : public Codec
40 {
41  public:
42 
43  XML(std::istream& in, std::ostream& out, Atlas::Bridge & b);
44 
45  void poll(bool can_read) override;
46 
47  void streamBegin() override;
48  void streamMessage() override;
49  void streamEnd() override;
50 
51  void mapMapItem(std::string name) override;
52  void mapListItem(std::string name) override;
53  void mapIntItem(std::string name, long) override;
54  void mapFloatItem(std::string name, double) override;
55  void mapStringItem(std::string name, std::string) override;
56  void mapEnd() override;
57 
58  void listMapItem() override;
59  void listListItem() override;
60  void listIntItem(long) override;
61  void listFloatItem(double) override;
62  void listStringItem(std::string) override;
63  void listEnd() override;
64 
70  static std::string escape(const std::string&);
71 
77  static std::string unescape(const std::string&);
78 
79  protected:
80 
81  std::istream& m_istream;
82  std::ostream& m_ostream;
83  Bridge & m_bridge;
84 
85  enum Token
86  {
87  TOKEN_TAG,
88  TOKEN_START_TAG,
89  TOKEN_END_TAG,
90  TOKEN_DATA
91  };
92 
93  Token m_token;
94 
95  enum State
96  {
97  PARSE_NOTHING,
98  PARSE_STREAM,
99  PARSE_MAP,
100  PARSE_LIST,
101  PARSE_INT,
102  PARSE_FLOAT,
103  PARSE_STRING
104  };
105 
106  std::stack<State> m_state;
107  std::stack<std::string> m_data;
108 
109  std::string m_tag;
110  std::string m_name;
111 
112  inline void tokenTag(char);
113  inline void tokenStartTag(char);
114  inline void tokenEndTag(char);
115  inline void tokenData(char);
116 
117  inline void parseStartTag();
118  inline void parseEndTag();
119 
120 };
121 
122 } } // namespace Atlas::Codecs
123 
124 #endif // ATLAS_CODECS_XML_H
void listStringItem(std::string) override
Adds a string to the currently streamed list.
Definition: XML.h:39
void listListItem() override
Starts a list object in the currently streamed list.
Atlas stream bridge.
Definition: Bridge.h:35
void mapFloatItem(std::string name, double) override
Adds a float to the currently streamed map.
void mapEnd() override
Ends the currently streamed map.
The Atlas namespace.
Definition: Bridge.h:20
void mapIntItem(std::string name, long) override
Adds an integer to the currently streames map.
Atlas stream codec.
Definition: Codec.h:27
void mapStringItem(std::string name, std::string) override
Adds a string to the currently streamed map.
static std::string escape(const std::string &)
Escapes a string for HTML.
void listIntItem(long) override
Adds an integer to the currently streames list.
void mapListItem(std::string name) override
Starts a list object to the currently streamed map.
void streamEnd() override
Ends the Atlas stream.
void mapMapItem(std::string name) override
Starts a map object to the currently streamed map.
static std::string unescape(const std::string &)
Un-escapes a previously "escaped" string for HTML.
void streamMessage() override
Start a message in an Atlas stream.
void listEnd() override
Ends the currently streamed list.
void streamBegin() override
Begin an Atlas stream.
void listMapItem() override
Starts a map object in the currently streamed list.
void listFloatItem(double) override
Adds a float to the currently streamed list.

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.