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::iostream& s, Atlas::Bridge & b);
44 
45  virtual void poll(bool can_read = true);
46 
47  virtual void streamBegin();
48  virtual void streamMessage();
49  virtual void streamEnd();
50 
51  virtual void mapMapItem(const std::string& name);
52  virtual void mapListItem(const std::string& name);
53  virtual void mapIntItem(const std::string& name, long);
54  virtual void mapFloatItem(const std::string& name, double);
55  virtual void mapStringItem(const std::string& name, const std::string&);
56  virtual void mapEnd();
57 
58  virtual void listMapItem();
59  virtual void listListItem();
60  virtual void listIntItem(long);
61  virtual void listFloatItem(double);
62  virtual void listStringItem(const std::string&);
63  virtual void listEnd();
64 
70  static std::string escape(const std::string&);
71 
77  static std::string unescape(const std::string&);
78 
79  protected:
80 
81  std::iostream & m_socket;
82  Bridge & m_bridge;
83 
84  enum Token
85  {
86  TOKEN_TAG,
87  TOKEN_START_TAG,
88  TOKEN_END_TAG,
89  TOKEN_DATA
90  };
91 
92  Token m_token;
93 
94  enum State
95  {
96  PARSE_NOTHING,
97  PARSE_STREAM,
98  PARSE_MAP,
99  PARSE_LIST,
100  PARSE_INT,
101  PARSE_FLOAT,
102  PARSE_STRING
103  };
104 
105  std::stack<State> m_state;
106  std::stack<std::string> m_data;
107 
108  std::string m_tag;
109  std::string m_name;
110 
111  inline void tokenTag(char);
112  inline void tokenStartTag(char);
113  inline void tokenEndTag(char);
114  inline void tokenData(char);
115 
116  inline void parseStartTag();
117  inline void parseEndTag();
118 
119 };
120 
121 } } // namespace Atlas::Codecs
122 
123 #endif // ATLAS_CODECS_XML_H
virtual void streamBegin()
Begin an Atlas stream.
Definition: XML.h:39
virtual void listMapItem()
Starts a map object in the currently streamed list.
Atlas stream bridge.
Definition: Bridge.h:35
virtual void mapListItem(const std::string &name)
Starts a list object to the currently streamed map.
virtual void mapFloatItem(const std::string &name, double)
Adds a float to the currently streamed map.
The Atlas namespace.
Definition: Bridge.h:20
virtual void streamMessage()
Start a message in an Atlas stream.
Atlas stream codec.
Definition: Codec.h:27
virtual void listEnd()
Ends the currently streamed list.
static std::string escape(const std::string &)
Escapes a string for HTML.
virtual void listFloatItem(double)
Adds a float to the currently streamed list.
virtual void mapMapItem(const std::string &name)
Starts a map object to the currently streamed map.
virtual void streamEnd()
Ends the Atlas stream.
static std::string unescape(const std::string &)
Un-escapes a previously "escaped" string for HTML.
virtual void mapEnd()
Ends the currently streamed map.
virtual void listListItem()
Starts a list object in the currently streamed list.
virtual void mapIntItem(const std::string &name, long)
Adds an integer to the currently streames map.
virtual void mapStringItem(const std::string &name, const std::string &)
Adds a string to the currently streamed map.
virtual void listIntItem(long)
Adds an integer to the currently streames list.
virtual void listStringItem(const std::string &)
Adds a string 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.