Atlas  0.7.0
Networking protocol for the Worldforge system.
DecoderBase.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 Stefanus Du Toit
4 
5 // $Id$
6 
7 #ifndef ATLAS_MESSAGE_DECODERBASE_H
8 #define ATLAS_MESSAGE_DECODERBASE_H
9 
10 #include <Atlas/Bridge.h>
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 #include <stack>
16 
17 namespace Atlas { namespace Message {
18 
19 class Element;
20 
21 typedef std::map<std::string, Element> MapType;
22 typedef std::vector<Element> ListType;
23 
24 
40 class DecoderBase : public Bridge
41 {
42 public:
43  DecoderBase();
44 
45  ~DecoderBase() override = default;
46 
47  // Callback functions from Bridge
48  void streamBegin() override;
49  void streamMessage() override;
50  void streamEnd() override;
51 
52  void mapMapItem(std::string name) override;
53  void mapListItem(std::string name) override;
54  void mapIntItem(std::string name, std::int64_t) override;
55  void mapFloatItem(std::string name, double) override;
56  void mapStringItem(std::string name, std::string) override;
57  void mapNoneItem(std::string name) override;
58  void mapEnd() override;
59 
60  void listMapItem() override;
61  void listListItem() override;
62  void listIntItem(std::int64_t) override;
63  void listFloatItem(double) override;
64  void listStringItem(std::string) override;
65  void listNoneItem() override;
66  void listEnd() override;
67 
68 protected:
69 
71  enum State {
72  STATE_STREAM,
73  STATE_MAP,
74  STATE_LIST
75  };
76 
78  std::stack<State> m_state;
80  std::stack<MapType> m_maps;
82  std::stack<ListType> m_lists;
84  std::stack<std::string> m_names;
85 
87  virtual void messageArrived(MapType obj) = 0;
88 };
89 
90 } } // namespace Atlas::Message
91 
92 #endif
Atlas::Message::DecoderBase::listStringItem
void listStringItem(std::string) override
Definition: DecoderBase.cpp:154
Atlas::Message::DecoderBase::mapEnd
void mapEnd() override
Definition: DecoderBase.cpp:88
Atlas::Message::DecoderBase::mapFloatItem
void mapFloatItem(std::string name, double) override
Definition: DecoderBase.cpp:68
Atlas::Message::DecoderBase::listMapItem
void listMapItem() override
Definition: DecoderBase.cpp:127
Atlas::Message::DecoderBase::State
State
Our current decoding state.
Definition: DecoderBase.h:71
Atlas::Message::DecoderBase::m_state
std::stack< State > m_state
The state stack.
Definition: DecoderBase.h:78
Atlas::Message::DecoderBase::m_lists
std::stack< ListType > m_lists
The list stack.
Definition: DecoderBase.h:82
Atlas::Message::DecoderBase::streamBegin
void streamBegin() override
Definition: DecoderBase.cpp:25
Atlas::Message::DecoderBase::listNoneItem
void listNoneItem() override
Definition: DecoderBase.cpp:161
Atlas::Message::DecoderBase::listEnd
void listEnd() override
Definition: DecoderBase.cpp:167
Atlas::Message::DecoderBase::messageArrived
virtual void messageArrived(MapType obj)=0
Override this - called when an object was received.
Atlas::Message::DecoderBase::listFloatItem
void listFloatItem(double) override
Definition: DecoderBase.cpp:148
Atlas::Bridge
Definition: Bridge.h:36
Atlas::Message::DecoderBase::listIntItem
void listIntItem(std::int64_t) override
Definition: DecoderBase.cpp:141
Atlas::Message::DecoderBase::listListItem
void listListItem() override
Definition: DecoderBase.cpp:134
Atlas::Message::DecoderBase::mapStringItem
void mapStringItem(std::string name, std::string) override
Definition: DecoderBase.cpp:75
Atlas::Message::DecoderBase::mapIntItem
void mapIntItem(std::string name, std::int64_t) override
Definition: DecoderBase.cpp:61
Atlas::Message::DecoderBase::mapNoneItem
void mapNoneItem(std::string name) override
Definition: DecoderBase.cpp:82
Atlas::Message::DecoderBase::streamEnd
void streamEnd() override
Definition: DecoderBase.cpp:38
Atlas::Message::DecoderBase::mapListItem
void mapListItem(std::string name) override
Definition: DecoderBase.cpp:53
Atlas::Message::DecoderBase
Definition: DecoderBase.h:41
Atlas::Message::DecoderBase::streamMessage
void streamMessage() override
Definition: DecoderBase.cpp:31
Atlas::Message::DecoderBase::mapMapItem
void mapMapItem(std::string name) override
Definition: DecoderBase.cpp:45
Atlas::Message::DecoderBase::m_maps
std::stack< MapType > m_maps
The map stack.
Definition: DecoderBase.h:80
Atlas::Message::DecoderBase::m_names
std::stack< std::string > m_names
Names for maps and lists.
Definition: DecoderBase.h:84
Atlas
Definition: Bridge.h:20