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
virtual void listIntItem(long)
Adds an integer to the currently streames list.
Definition: Packed.h:39
virtual void streamBegin()
Begin an Atlas stream.
Atlas stream bridge.
Definition: Bridge.h:35
Various utility functions for codec implementation.
virtual void listFloatItem(double)
Adds a float to the currently streamed list.
virtual void mapListItem(const std::string &name)
Starts a list object to the currently streamed map.
The Atlas namespace.
Definition: Bridge.h:20
Atlas stream codec.
Definition: Codec.h:27
virtual void mapFloatItem(const std::string &name, double)
Adds a float to the currently streamed map.
virtual void listListItem()
Starts a list object in the currently streamed list.
virtual void mapStringItem(const std::string &name, const std::string &)
Adds a string to the currently streamed map.
virtual void streamMessage()
Start a message in an Atlas stream.
virtual void mapEnd()
Ends the currently streamed map.
virtual void listStringItem(const std::string &)
Adds a string to the currently streamed list.
virtual void listMapItem()
Starts a map object in the currently streamed list.
virtual void mapIntItem(const std::string &name, long)
Adds an integer to the currently streames map.
virtual void listEnd()
Ends the currently streamed list.
virtual void mapMapItem(const std::string &name)
Starts a map object to the currently streamed map.
virtual void streamEnd()
Ends the Atlas stream.

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.