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