Atlas-C++
XML.h
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 // $Id$
00006 
00007 #ifndef ATLAS_CODECS_XML_H
00008 #define ATLAS_CODECS_XML_H
00009 
00010 #include <Atlas/Codec.h>
00011 
00012 #include <iosfwd>
00013 #include <stack>
00014 
00015 namespace Atlas { namespace Codecs {
00016 
00017 /*
00018 
00019 Sample output for this codec: (whitespace added for clarity)
00020 
00021 <atlas>
00022     <map>
00023         <int name="foo">13</int>
00024         <float name="meep">1.5</float>
00025         <string name="bar">hello</string>
00026         <list name="args">
00027             <int>1</int>
00028             <int>2</int>
00029             <float>3.0</float>
00030         </list>
00031     </map>
00032 </atlas>
00033 
00034 The complete specification is located in cvs at:
00035     forge/protocols/atlas/spec/xml_syntax.html
00036 
00037 */
00038 
00039 class XML : public Codec
00040 {
00041     public:
00042 
00043     XML(std::iostream& s, Atlas::Bridge & b);
00044 
00045     virtual void poll(bool can_read = true);
00046 
00047     virtual void streamBegin();
00048     virtual void streamMessage();
00049     virtual void streamEnd();
00050     
00051     virtual void mapMapItem(const std::string& name);
00052     virtual void mapListItem(const std::string& name);
00053     virtual void mapIntItem(const std::string& name, long);
00054     virtual void mapFloatItem(const std::string& name, double);
00055     virtual void mapStringItem(const std::string& name, const std::string&);
00056     virtual void mapEnd();
00057     
00058     virtual void listMapItem();
00059     virtual void listListItem();
00060     virtual void listIntItem(long);
00061     virtual void listFloatItem(double);
00062     virtual void listStringItem(const std::string&);
00063     virtual void listEnd();
00064 
00070     static std::string escape(const std::string&);
00071 
00077     static std::string unescape(const std::string&);
00078 
00079     protected:
00080 
00081     std::iostream & m_socket;
00082     Bridge & m_bridge;
00083     
00084     enum Token
00085     {
00086         TOKEN_TAG,
00087         TOKEN_START_TAG,
00088         TOKEN_END_TAG,
00089         TOKEN_DATA
00090     };
00091     
00092     Token m_token;
00093     
00094     enum State
00095     {
00096         PARSE_NOTHING,
00097         PARSE_STREAM,
00098         PARSE_MAP,
00099         PARSE_LIST,
00100         PARSE_INT,
00101         PARSE_FLOAT,
00102         PARSE_STRING
00103     };
00104     
00105     std::stack<State> m_state;
00106     std::stack<std::string> m_data;
00107 
00108     std::string m_tag;
00109     std::string m_name;
00110 
00111     inline void tokenTag(char);
00112     inline void tokenStartTag(char);
00113     inline void tokenEndTag(char);
00114     inline void tokenData(char);
00115 
00116     inline void parseStartTag();
00117     inline void parseEndTag();
00118 
00119 };
00120 
00121 } } // namespace Atlas::Codecs
00122 
00123 #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.