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 
00065     protected:
00066 
00067     std::iostream & m_socket;
00068     Bridge & m_bridge;
00069     
00070     enum Token
00071     {
00072         TOKEN_TAG,
00073         TOKEN_START_TAG,
00074         TOKEN_END_TAG,
00075         TOKEN_DATA
00076     };
00077     
00078     Token m_token;
00079     
00080     enum State
00081     {
00082         PARSE_NOTHING,
00083         PARSE_STREAM,
00084         PARSE_MAP,
00085         PARSE_LIST,
00086         PARSE_INT,
00087         PARSE_FLOAT,
00088         PARSE_STRING
00089     };
00090     
00091     std::stack<State> m_state;
00092     std::stack<std::string> m_data;
00093 
00094     std::string m_tag;
00095     std::string m_name;
00096 
00097     inline void tokenTag(char);
00098     inline void tokenStartTag(char);
00099     inline void tokenEndTag(char);
00100     inline void tokenData(char);
00101 
00102     inline void parseStartTag();
00103     inline void parseEndTag();
00104 };
00105 
00106 } } // namespace Atlas::Codecs
00107 
00108 #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.