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
17namespace Atlas { namespace Message {
18
19class Element;
20
21typedef std::map<std::string, Element> MapType;
22typedef std::vector<Element> ListType;
23
24
40class DecoderBase : public Bridge
41{
42public:
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
68protected:
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
void streamMessage() override
Definition: DecoderBase.cpp:31
void mapIntItem(std::string name, std::int64_t) override
Definition: DecoderBase.cpp:61
void listNoneItem() override
State
Our current decoding state.
Definition: DecoderBase.h:71
void listStringItem(std::string) override
void mapMapItem(std::string name) override
Definition: DecoderBase.cpp:45
void mapStringItem(std::string name, std::string) override
Definition: DecoderBase.cpp:75
std::stack< std::string > m_names
Names for maps and lists.
Definition: DecoderBase.h:84
void mapNoneItem(std::string name) override
Definition: DecoderBase.cpp:82
void mapFloatItem(std::string name, double) override
Definition: DecoderBase.cpp:68
std::stack< ListType > m_lists
The list stack.
Definition: DecoderBase.h:82
void streamBegin() override
Definition: DecoderBase.cpp:25
std::stack< State > m_state
The state stack.
Definition: DecoderBase.h:78
void listListItem() override
void listFloatItem(double) override
virtual void messageArrived(MapType obj)=0
Override this - called when an object was received.
void listIntItem(std::int64_t) override
void mapListItem(std::string name) override
Definition: DecoderBase.cpp:53
std::stack< MapType > m_maps
The map stack.
Definition: DecoderBase.h:80
Definition: Bridge.h:20