Atlas  0.7.0
Networking protocol for the Worldforge system.
PresentationBridge.h
1 /*
2  Copyright (C) 2013 Erik Ogenvik
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software Foundation,
16  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef PRESENTATIONBRIDGE_H_
20 #define PRESENTATIONBRIDGE_H_
21 
22 #include <sstream>
23 #include <string>
24 #include <stack>
25 #include <deque>
26 #include "Bridge.h"
27 
28 namespace Atlas
29 {
30 
36 {
37 public:
38  explicit PresentationBridge(std::ostream& stream);
39  ~PresentationBridge() override = default;
40 
41  void streamBegin() override;
42  void streamMessage() override;
43  void streamEnd() override;
44 
45  void mapMapItem(std::string name) override;
46  void mapListItem(std::string name) override;
47  void mapIntItem(std::string name, std::int64_t) override;
48  void mapFloatItem(std::string name, double) override;
49  void mapStringItem(std::string name, std::string) override;
50  void mapNoneItem(std::string name) override;
51  void mapEnd() override;
52 
53  void listMapItem() override;
54  void listListItem() override;
55  void listIntItem(std::int64_t) override;
56  void listFloatItem(double) override;
57  void listStringItem(std::string) override;
58  void listNoneItem() override;
59  void listEnd() override;
60 
68  void setMaxItemsPerLevel(size_t maxItems);
69 
75  void setStartFilteringLevel(size_t startFilteringLevel);
76 
77 private:
78 
79  void addPadding();
80 
81  void removePadding();
82 
87  bool checkAndUpdateMaxItemCounter();
88 
89  std::string mPadding;
90 
91  std::ostream& mStream;
92 
98  std::stack<int> mMapsInList;
99 
103  size_t mMaxItemsPerLevel;
104 
108  bool mIsSkipEntry;
109 
114  size_t mStartFilterLevel;
115 
119  std::deque<size_t> mEntriesPerLevelCounter;
120 };
121 
122 }
123 #endif /* PRESENTATIONBRIDGE_H_ */
Atlas::PresentationBridge::setMaxItemsPerLevel
void setMaxItemsPerLevel(size_t maxItems)
Definition: PresentationBridge.cpp:160
Atlas::PresentationBridge::mapStringItem
void mapStringItem(std::string name, std::string) override
Definition: PresentationBridge.cpp:70
Atlas::PresentationBridge::mapListItem
void mapListItem(std::string name) override
Definition: PresentationBridge.cpp:50
Atlas::PresentationBridge::listEnd
void listEnd() override
Definition: PresentationBridge.cpp:129
Atlas::PresentationBridge::streamBegin
void streamBegin() override
Definition: PresentationBridge.cpp:30
Atlas::PresentationBridge::listFloatItem
void listFloatItem(double) override
Definition: PresentationBridge.cpp:112
Atlas::PresentationBridge::setStartFilteringLevel
void setStartFilteringLevel(size_t startFilteringLevel)
Definition: PresentationBridge.cpp:165
Atlas::PresentationBridge::streamMessage
void streamMessage() override
Definition: PresentationBridge.cpp:34
Atlas::PresentationBridge::mapNoneItem
void mapNoneItem(std::string name) override
Definition: PresentationBridge.cpp:76
Atlas::PresentationBridge::listMapItem
void listMapItem() override
Definition: PresentationBridge.cpp:87
Atlas::PresentationBridge::listNoneItem
void listNoneItem() override
Definition: PresentationBridge.cpp:124
Atlas::PresentationBridge::listListItem
void listListItem() override
Definition: PresentationBridge.cpp:101
Atlas::PresentationBridge::listStringItem
void listStringItem(std::string) override
Definition: PresentationBridge.cpp:118
Atlas::PresentationBridge::mapMapItem
void mapMapItem(std::string name) override
Definition: PresentationBridge.cpp:43
Atlas::PresentationBridge::streamEnd
void streamEnd() override
Definition: PresentationBridge.cpp:38
Atlas::PresentationBridge
A bridge which is meant to be used solely for presenting Element data.
Definition: PresentationBridge.h:35
Atlas::Bridge
Definition: Bridge.h:35
Atlas::PresentationBridge::mapIntItem
void mapIntItem(std::string name, std::int64_t) override
Definition: PresentationBridge.cpp:58
Atlas::PresentationBridge::mapFloatItem
void mapFloatItem(std::string name, double) override
Definition: PresentationBridge.cpp:64
Atlas::PresentationBridge::listIntItem
void listIntItem(std::int64_t) override
Definition: PresentationBridge.cpp:106
Atlas::PresentationBridge::mapEnd
void mapEnd() override
Definition: PresentationBridge.cpp:82
Atlas
Definition: Bridge.h:20