00001 // This file may be redistributed and modified under the terms of the 00002 // GNU Lesser General Public License (See COPYING for details). 00003 // Copyright (C) 2000-2001 Michael Day, Stefanus Du Toit 00004 00005 #ifndef ATLAS_CODECS_XML_H 00006 #define ATLAS_CODECS_XML_H 00007 00008 #include <Atlas/Codec.h> 00009 00010 #include <iosfwd> 00011 #include <stack> 00012 00013 namespace Atlas { namespace Codecs { 00014 00015 /* 00016 00017 Sample output for this codec: (whitespace added for clarity) 00018 00019 <atlas> 00020 <map> 00021 <int name="foo">13</int> 00022 <float name="meep">1.5</float> 00023 <string name="bar">hello</string> 00024 <list name="args"> 00025 <int>1</int> 00026 <int>2</int> 00027 <float>3.0</float> 00028 </list> 00029 </map> 00030 </atlas> 00031 00032 The complete specification is located in cvs at: 00033 forge/protocols/atlas/spec/xml_syntax.html 00034 00035 */ 00036 00037 class XML : public Codec 00038 { 00039 public: 00040 00041 XML(std::iostream& s, Atlas::Bridge & b); 00042 00043 virtual void poll(bool can_read = true); 00044 00045 virtual void streamBegin(); 00046 virtual void streamMessage(); 00047 virtual void streamEnd(); 00048 00049 virtual void mapMapItem(const std::string& name); 00050 virtual void mapListItem(const std::string& name); 00051 virtual void mapIntItem(const std::string& name, long); 00052 virtual void mapFloatItem(const std::string& name, double); 00053 virtual void mapStringItem(const std::string& name, const std::string&); 00054 virtual void mapEnd(); 00055 00056 virtual void listMapItem(); 00057 virtual void listListItem(); 00058 virtual void listIntItem(long); 00059 virtual void listFloatItem(double); 00060 virtual void listStringItem(const std::string&); 00061 virtual void listEnd(); 00062 00063 protected: 00064 00065 std::iostream & m_socket; 00066 Bridge & m_bridge; 00067 00068 enum Token 00069 { 00070 TOKEN_TAG, 00071 TOKEN_START_TAG, 00072 TOKEN_END_TAG, 00073 TOKEN_DATA 00074 }; 00075 00076 Token m_token; 00077 00078 enum State 00079 { 00080 PARSE_NOTHING, 00081 PARSE_STREAM, 00082 PARSE_MAP, 00083 PARSE_LIST, 00084 PARSE_INT, 00085 PARSE_FLOAT, 00086 PARSE_STRING 00087 }; 00088 00089 std::stack<State> m_state; 00090 std::stack<std::string> m_data; 00091 00092 std::string m_tag; 00093 std::string m_name; 00094 00095 inline void tokenTag(char); 00096 inline void tokenStartTag(char); 00097 inline void tokenEndTag(char); 00098 inline void tokenData(char); 00099 00100 inline void parseStartTag(); 00101 inline void parseEndTag(); 00102 }; 00103 00104 } } // namespace Atlas::Codecs 00105 00106 #endif // ATLAS_CODECS_XML_H
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.