Bach.h

Go to the documentation of this file.
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_BACH_H
00006 #define ATLAS_CODECS_BACH_H
00007 
00008 #include <Atlas/Codec.h>
00009 
00010 #include <iosfwd>
00011 #include <stack>
00012 
00013 namespace Atlas { namespace Codecs {
00014 
00019 class Bach : public Codec
00020 {
00021   public:
00022 
00023     Bach(std::iostream& s, Atlas::Bridge & b);
00024 
00025     virtual void poll(bool can_read = true);
00026 
00027     virtual void streamBegin();
00028     virtual void streamMessage();
00029     virtual void streamEnd();
00030 
00031     virtual void mapMapItem(const std::string& name);
00032     virtual void mapListItem(const std::string& name);
00033     virtual void mapIntItem(const std::string& name, long);
00034     virtual void mapFloatItem(const std::string& name, double);
00035     virtual void mapStringItem(const std::string& name, const std::string&);
00036     virtual void mapEnd();
00037 
00038     virtual void listMapItem();
00039     virtual void listListItem();
00040     virtual void listIntItem(long);
00041     virtual void listFloatItem(double);
00042     virtual void listStringItem(const std::string&);
00043     virtual void listEnd();
00044 
00045     unsigned linenum() const {return m_linenum;}
00046 
00047   protected:
00048 
00049     std::iostream& m_socket;
00050     Bridge & m_bridge;
00051     bool m_comma;
00052     unsigned m_linenum;
00053 
00054     enum State
00055     {
00056         PARSE_INIT,
00057         PARSE_STREAM,
00058         PARSE_MAP,
00059         PARSE_LIST,
00060         PARSE_NAME,
00061         PARSE_DATA,
00062         PARSE_INT,
00063         PARSE_FLOAT,
00064         PARSE_STRING,
00065         PARSE_LITERAL, // for literal character escaped with backslash
00066         PARSE_COMMENT // for when we're in the middle of a comment field
00067     };
00068 
00069     bool stringmode() const;
00070 
00071     std::string m_name, m_data;
00072     std::stack<State> m_state;
00073 
00074     inline void parseInit(char);
00075     inline void parseStream(char);
00076     inline void parseMap(char);
00077     inline void parseList(char);
00078     inline void parseData(char);
00079     inline void parseInt(char);
00080     inline void parseFloat(char);
00081     inline void parseString(char);
00082     inline void parseLiteral(char);
00083     inline void parseName(char);
00084     inline void parseComment(char);
00085 
00086     inline const std::string encodeString(std::string);
00087     inline const std::string decodeString(std::string);
00088 
00089     void writeIntItem(std::string,long);
00090     void writeFloatItem(std::string,double);
00091     void writeStringItem(std::string,std::string);
00092     void writeLine(std::string,bool=true,bool=false);
00093 };
00094 
00095 } } // namespace Atlas::Codecs
00096 
00097 #endif // ATLAS_CODECS_BACH_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.