Atlas-C++
Packed.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU Lesser General Public License (See COPYING for details).
3 // Copyright (C) 2000-2001 Stefanus Du Toit, Michael Day
4 
5 // $Id$
6 
7 #ifndef ATLAS_CODECS_PACKED_H
8 #define ATLAS_CODECS_PACKED_H
9 
10 #include <Atlas/Codecs/Utility.h>
11 #include <Atlas/Codec.h>
12 
13 #include <iosfwd>
14 #include <stack>
15 
16 namespace Atlas { namespace Codecs {
17 
18 /*
19 
20 The form for each element of this codec is as follows:
21 
22 [type][name=][data][|endtype]
23 
24 ( ) for lists
25 [ ] for maps
26 $ for string
27 @ for int
28 # for float
29 
30 Sample output for this codec: (whitespace added for clarity)
31 
32 [@id=17$name=Fred +28the +2b great+29#weight=1.5(args=@1@2@3)]
33 
34 The complete specification is located in cvs at:
35  forge/protocols/atlas/spec/packed_syntax.html
36 
37 */
38 
39 class Packed : public Codec
40 {
41 public:
42 
43  Packed(std::iostream& s, Atlas::Bridge & b);
44 
45  virtual void poll(bool can_read = true);
46 
47  virtual void streamBegin();
48  virtual void streamMessage();
49  virtual void streamEnd();
50 
51  virtual void mapMapItem(const std::string& name);
52  virtual void mapListItem(const std::string& name);
53  virtual void mapIntItem(const std::string& name, long);
54  virtual void mapFloatItem(const std::string& name, double);
55  virtual void mapStringItem(const std::string& name, const std::string&);
56  virtual void mapEnd();
57 
58  virtual void listMapItem();
59  virtual void listListItem();
60  virtual void listIntItem(long);
61  virtual void listFloatItem(double);
62  virtual void listStringItem(const std::string&);
63  virtual void listEnd();
64 
65 protected:
66 
67  std::iostream& m_socket;
68  Bridge & m_bridge;
69 
70  enum State
71  {
72  PARSE_STREAM,
73  PARSE_MAP,
74  PARSE_LIST,
75  PARSE_MAP_BEGIN,
76  PARSE_LIST_BEGIN,
77  PARSE_INT,
78  PARSE_FLOAT,
79  PARSE_STRING,
80  PARSE_NAME
81  };
82 
83  std::stack<State> m_state;
84 
85  std::string m_name;
86  std::string m_data;
87 
88  inline void parseStream(char);
89  inline void parseMap(char);
90  inline void parseList(char);
91  inline void parseMapBegin(char);
92  inline void parseListBegin(char);
93  inline void parseInt(char);
94  inline void parseFloat(char);
95  inline void parseString(char);
96  inline void parseName(char);
97 
98  inline const std::string hexEncode(const std::string& data)
99  {
100  return hexEncodeWithPrefix("+", "+[]()@#$=", data);
101  }
102 
103  inline const std::string hexDecode(const std::string& data)
104  {
105  return hexDecodeWithPrefix("+", data);
106  }
107 };
108 
109 } } // namespace Atlas::Codecs
110 
111 #endif
Atlas::Bridge
Atlas stream bridge.
Definition: Bridge.h:35
Atlas::Codecs::Packed::listStringItem
virtual void listStringItem(const std::string &)
Adds a string to the currently streamed list.
Atlas::Codecs::Packed::listListItem
virtual void listListItem()
Starts a list object in the currently streamed list.
Atlas::Codecs::Packed::listEnd
virtual void listEnd()
Ends the currently streamed list.
Atlas::Codecs::Packed::streamEnd
virtual void streamEnd()
Ends the Atlas stream.
Atlas::Codecs::Packed::mapStringItem
virtual void mapStringItem(const std::string &name, const std::string &)
Adds a string to the currently streamed map.
Atlas::Codecs::Packed::streamMessage
virtual void streamMessage()
Start a message in an Atlas stream.
Atlas::Codecs::Packed::mapMapItem
virtual void mapMapItem(const std::string &name)
Starts a map object to the currently streamed map.
Atlas::Codecs::Packed::listMapItem
virtual void listMapItem()
Starts a map object in the currently streamed list.
Atlas::Codecs::Packed::mapIntItem
virtual void mapIntItem(const std::string &name, long)
Adds an integer to the currently streames map.
Atlas::Codecs::Packed::streamBegin
virtual void streamBegin()
Begin an Atlas stream.
Atlas::Codec
Atlas stream codec.
Definition: Codec.h:27
Atlas::Codecs::Packed::mapListItem
virtual void mapListItem(const std::string &name)
Starts a list object to the currently streamed map.
Atlas::Codecs::Packed::listIntItem
virtual void listIntItem(long)
Adds an integer to the currently streames list.
Atlas
The Atlas namespace.
Definition: Bridge.h:20
Atlas::Codecs::Packed::mapFloatItem
virtual void mapFloatItem(const std::string &name, double)
Adds a float to the currently streamed map.
Atlas::Codecs::Packed::listFloatItem
virtual void listFloatItem(double)
Adds a float to the currently streamed list.
Utility.h
Atlas::Codecs::Packed
Definition: Packed.h:39
Atlas::Codecs::Packed::mapEnd
virtual void mapEnd()
Ends the currently streamed map.

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.