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 <iostream> 00009 #include <stack> 00010 00011 #include <Atlas/Codec.h> 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<std::iostream> 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(const Map&); 00047 virtual void streamEnd(); 00048 00049 virtual void mapItem(const std::string& name, const Map&); 00050 virtual void mapItem(const std::string& name, const List&); 00051 virtual void mapItem(const std::string& name, long); 00052 virtual void mapItem(const std::string& name, double); 00053 virtual void mapItem(const std::string& name, const std::string&); 00054 virtual void mapEnd(); 00055 00056 virtual void listItem(const Map&); 00057 virtual void listItem(const List&); 00058 virtual void listItem(double); 00059 virtual void listItem(long); 00060 virtual void listItem(const std::string&); 00061 virtual void listEnd(); 00062 00063 protected: 00064 00065 std::iostream& socket; 00066 Bridge* bridge; 00067 00068 enum Token 00069 { 00070 TOKEN_TAG, 00071 TOKEN_START_TAG, 00072 TOKEN_END_TAG, 00073 TOKEN_DATA 00074 }; 00075 00076 Token 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> state; 00090 std::stack<std::string> data; 00091 00092 std::string tag; 00093 std::string 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
Copyright 2000 the respective authors.
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.