00001 // This file may be redistributed and modified only under the terms of 00002 // the GNU Lesser General Public License (See COPYING for details). 00003 // Copyright (C) 2000-2001 Stefanus Du Toit, Michael Day 00004 00005 #ifndef ATLAS_CODECS_PACKED_H 00006 #define ATLAS_CODECS_PACKED_H 00007 00008 #include <Atlas/Codecs/Utility.h> 00009 #include <Atlas/Codec.h> 00010 00011 #include <iosfwd> 00012 #include <stack> 00013 00014 namespace Atlas { namespace Codecs { 00015 00016 /* 00017 00018 The form for each element of this codec is as follows: 00019 00020 [type][name=][data][|endtype] 00021 00022 ( ) for lists 00023 [ ] for maps 00024 $ for string 00025 @ for int 00026 # for float 00027 00028 Sample output for this codec: (whitespace added for clarity) 00029 00030 [@id=17$name=Fred +28the +2b great+29#weight=1.5(args=@1@2@3)] 00031 00032 The complete specification is located in cvs at: 00033 forge/protocols/atlas/spec/packed_syntax.html 00034 00035 */ 00036 00037 class Packed : public Codec 00038 { 00039 public: 00040 00041 Packed(std::iostream& s, Atlas::Bridge & b); 00042 00043 virtual void poll(bool can_read = true); 00044 00045 virtual void streamBegin(); 00046 virtual void streamMessage(); 00047 virtual void streamEnd(); 00048 00049 virtual void mapMapItem(const std::string& name); 00050 virtual void mapListItem(const std::string& name); 00051 virtual void mapIntItem(const std::string& name, long); 00052 virtual void mapFloatItem(const std::string& name, double); 00053 virtual void mapStringItem(const std::string& name, const std::string&); 00054 virtual void mapEnd(); 00055 00056 virtual void listMapItem(); 00057 virtual void listListItem(); 00058 virtual void listIntItem(long); 00059 virtual void listFloatItem(double); 00060 virtual void listStringItem(const std::string&); 00061 virtual void listEnd(); 00062 00063 protected: 00064 00065 std::iostream& m_socket; 00066 Bridge & m_bridge; 00067 00068 enum State 00069 { 00070 PARSE_STREAM, 00071 PARSE_MAP, 00072 PARSE_LIST, 00073 PARSE_MAP_BEGIN, 00074 PARSE_LIST_BEGIN, 00075 PARSE_INT, 00076 PARSE_FLOAT, 00077 PARSE_STRING, 00078 PARSE_NAME 00079 }; 00080 00081 std::stack<State> m_state; 00082 00083 std::string m_name; 00084 std::string m_data; 00085 00086 inline void parseStream(char); 00087 inline void parseMap(char); 00088 inline void parseList(char); 00089 inline void parseMapBegin(char); 00090 inline void parseListBegin(char); 00091 inline void parseInt(char); 00092 inline void parseFloat(char); 00093 inline void parseString(char); 00094 inline void parseName(char); 00095 00096 inline const std::string hexEncode(const std::string& data) 00097 { 00098 return hexEncodeWithPrefix("+", "+[]()@#$=", data); 00099 } 00100 00101 inline const std::string hexDecode(const std::string& data) 00102 { 00103 return hexDecodeWithPrefix("+", data); 00104 } 00105 }; 00106 00107 } } // namespace Atlas::Codecs 00108 00109 #endif
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.