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 
65  protected:
66 
67  std::iostream & m_socket;
68  Bridge & m_bridge;
69 
70  enum Token
71  {
72  TOKEN_TAG,
73  TOKEN_START_TAG,
74  TOKEN_END_TAG,
75  TOKEN_DATA
76  };
77 
78  Token m_token;
79 
80  enum State
81  {
82  PARSE_NOTHING,
83  PARSE_STREAM,
84  PARSE_MAP,
85  PARSE_LIST,
86  PARSE_INT,
87  PARSE_FLOAT,
88  PARSE_STRING
89  };
90 
91  std::stack<State> m_state;
92  std::stack<std::string> m_data;
93 
94  std::string m_tag;
95  std::string m_name;
96 
97  inline void tokenTag(char);
98  inline void tokenStartTag(char);
99  inline void tokenEndTag(char);
100  inline void tokenData(char);
101 
102  inline void parseStartTag();
103  inline void parseEndTag();
104 };
105 
106 } } // namespace Atlas::Codecs
107 
108 #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.
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.
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.