1 // This file may be redistributed and modified under the terms of the 2 // GNU Lesser General Public License (See COPYING for details). 3 // Copyright (C) 2000-2001 Michael Day, Stefanus Du Toit 4 5 // $Id$ 6 7 #ifndef ATLAS_CODECS_BACH_H 8 #define ATLAS_CODECS_BACH_H 9 10 #include <Atlas/Codec.h> 11 12 #include <iosfwd> 13 #include <stack> 14 15 namespace Atlas { namespace Codecs { 16 17 /** @file Codecs/Bach.h 18 * This class implements Bach Codec 19 */ 20 21 class Bach : public Codec 22 { 23 public: 24 25 Bach(std::iostream& s, Atlas::Bridge & b); 26 27 virtual void poll(bool can_read = true); 28 29 virtual void streamBegin(); 30 virtual void streamMessage(); 31 virtual void streamEnd(); 32 33 virtual void mapMapItem(const std::string& name); 34 virtual void mapListItem(const std::string& name); 35 virtual void mapIntItem(const std::string& name, long); 36 virtual void mapFloatItem(const std::string& name, double); 37 virtual void mapStringItem(const std::string& name, const std::string&); 38 virtual void mapEnd(); 39 40 virtual void listMapItem(); 41 virtual void listListItem(); 42 virtual void listIntItem(long); 43 virtual void listFloatItem(double); 44 virtual void listStringItem(const std::string&); 45 virtual void listEnd(); 46 linenum()47 unsigned linenum() const {return m_linenum;} 48 49 protected: 50 51 std::iostream& m_socket; 52 Bridge & m_bridge; 53 bool m_comma; 54 unsigned m_linenum; 55 56 enum State 57 { 58 PARSE_INIT, 59 PARSE_STREAM, 60 PARSE_MAP, 61 PARSE_LIST, 62 PARSE_NAME, 63 PARSE_DATA, 64 PARSE_INT, 65 PARSE_FLOAT, 66 PARSE_STRING, 67 PARSE_LITERAL, // for literal character escaped with backslash 68 PARSE_COMMENT // for when we're in the middle of a comment field 69 }; 70 71 bool stringmode() const; 72 73 std::string m_name, m_data; 74 std::stack<State> m_state; 75 76 inline void parseInit(char); 77 inline void parseStream(char); 78 inline void parseMap(char); 79 inline void parseList(char); 80 inline void parseData(char); 81 inline void parseInt(char); 82 inline void parseFloat(char); 83 inline void parseString(char); 84 inline void parseLiteral(char); 85 inline void parseName(char); 86 inline void parseComment(char); 87 88 inline const std::string encodeString(const std::string &); 89 inline const std::string decodeString(const std::string &); 90 91 void writeIntItem(const std::string &,long); 92 void writeFloatItem(const std::string &,double); 93 void writeStringItem(const std::string &,const std::string &); 94 void writeLine(const std::string &,bool=true,bool=false); 95 }; 96 97 } } // namespace Atlas::Codecs 98 99 #endif // ATLAS_CODECS_BACH_H 100