Emergency 20 Dokumentation  4.2.0
MapCacheStatistics.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include "em5/Export.h"
14 
15 #include <boost/noncopyable.hpp>
16 
17 #include <vector>
18 #include <unordered_map>
19 
20 
21 //[-------------------------------------------------------]
22 //[ Namespace ]
23 //[-------------------------------------------------------]
24 namespace em5
25 {
26  namespace multiplayer
27  {
28 
29 
30  //[-------------------------------------------------------]
31  //[ Classes ]
32  //[-------------------------------------------------------]
37  class ValueHistory : public boost::noncopyable
38  {
39 
40 
41  //[-------------------------------------------------------]
42  //[ Public methods ]
43  //[-------------------------------------------------------]
44  public:
52  ValueHistory(size_t historyLimit);
53 
63  void addValue(uint64 value, uint16 timePassedInMilliseconds);
64 
69  inline const std::vector<uint64>& getValues() const;
70 
75  inline const boost::container::flat_map<uint16, uint64>& getPerSecondValues() const;
76 
81  inline uint64 getLowestValue() const;
82 
87  inline uint64 getHighestValue() const;
88 
89 
90  //[-------------------------------------------------------]
91  //[ Private data ]
92  //[-------------------------------------------------------]
93  private:
94  std::vector<uint64> mValues;
95  size_t mHistoryLimit;
96  uint64 mLowestValue;
97  uint64 mHighestValue;
98  boost::container::flat_map<uint16, uint64> mPerSecondData;
99  uint16 mCurrentValueCount;
100  uint16 mCurrentSecond;
101 
102  };
103 
104 
109  class ComponentValueHistory : public boost::noncopyable
110  {
111 
112 
113  //[-------------------------------------------------------]
114  //[ Public methods ]
115  //[-------------------------------------------------------]
116  public:
124  ComponentValueHistory(const size_t historyLimit = 40);
125 
137  void addValue(uint8 componentId, uint64 value, uint16 timePassedInMilliseconds);
138 
143  void saveToFile() const;
144 
149  inline const std::unordered_map<uint8, ValueHistory>& getList() const;
150 
155  inline size_t getValueCount() const;
156 
157 
158  //[-------------------------------------------------------]
159  //[ Private data ]
160  //[-------------------------------------------------------]
161  private:
162  std::unordered_map<uint8, ValueHistory> mComponentValueHistory;
163  size_t mValueCount;
164  size_t mHistoryLimit;
165 
166 
167  };
168 
169 
174  class MultiValueHistory : public boost::noncopyable
175  {
176 
177 
178  //[-------------------------------------------------------]
179  //[ Public methods ]
180  //[-------------------------------------------------------]
181  public:
189  MultiValueHistory(const size_t historyLimit = 40);
190 
191  void addEntryType(const std::string& name);
192 
204  void addValue(uint8 componentId, uint64 value, uint16 timePassedInMilliseconds);
205 
210  void saveToFile() const;
211 
216  inline const std::unordered_map<uint8, ValueHistory>& getList() const;
217 
222  inline size_t getValueCount() const;
223 
224 
225  //[-------------------------------------------------------]
226  //[ Private data ]
227  //[-------------------------------------------------------]
228  private:
229  std::unordered_map<uint8, ValueHistory> mMultiValueHistory;
230  std::vector<std::string> mEntryNameList;
231  size_t mValueCount;
232  size_t mHistoryLimit; //< Holds the history limit
233 
234 
235  };
236 
237 
238 //[-------------------------------------------------------]
239 //[ Namespace ]
240 //[-------------------------------------------------------]
241  } // multiplayer
242 } // em5
243 
244 
245 //[-------------------------------------------------------]
246 //[ Implementation ]
247 //[-------------------------------------------------------]
Definition: ActionPriority.h:13
void addValue(uint8 componentId, uint64 value, uint16 timePassedInMilliseconds)
Adds a value to the history of the given component. Nothing is added when the component id is unknown...
EMERGENCY 5 multiplayer per component value history.
Definition: MapCacheStatistics.h:109
void saveToFile() const
Saves the per component history as csv to a file named "mapcache_values.csv". The location is the app...
EMERGENCY 5 multiplayer per component value history.
Definition: MapCacheStatistics.h:174
void addValue(uint8 componentId, uint64 value, uint16 timePassedInMilliseconds)
Adds a value to the history of the given component. Nothing is added when the component id is unknown...
uint64 getLowestValue() const
Returns the lowest value which was added to the history.
Definition: MapCacheStatistics-inl.h:26
MultiValueHistory(const size_t historyLimit=40)
Constructor.
void saveToFile() const
Saves the per component history as csv to a file named "mapcache_values.csv". The location is the app...
size_t getValueCount() const
Returns how many entries each value history entry has (This value is only correct for all entries...
Definition: MapCacheStatistics-inl.h:51
EMERGENCY 5 multiplayer value history.
Definition: MapCacheStatistics.h:37
ValueHistory(size_t historyLimit)
Constructor.
uint64_t uint64
Definition: PlatformTypes.h:184
const std::vector< uint64 > & getValues() const
Returns the stored values.
Definition: MapCacheStatistics-inl.h:16
const std::unordered_map< uint8, ValueHistory > & getList() const
Returns the list of the stored per component value history.
Definition: MapCacheStatistics-inl.h:46
uint64 getHighestValue() const
Returns the highest value which was added to the history.
Definition: MapCacheStatistics-inl.h:31
ComponentValueHistory(const size_t historyLimit=40)
Constructor.
const std::unordered_map< uint8, ValueHistory > & getList() const
Returns the list of the stored per component value history.
Definition: MapCacheStatistics-inl.h:36
unsigned short uint16
Definition: PlatformTypes.h:178
void addEntryType(const std::string &name)
const boost::container::flat_map< uint16, uint64 > & getPerSecondValues() const
Returns the stored per second values.
Definition: MapCacheStatistics-inl.h:21
void addValue(uint64 value, uint16 timePassedInMilliseconds)
Adds a value to the history. When the maximum limit is reached the "oldest" value (first element in t...
size_t getValueCount() const
Returns how many entries each value history entry has (This value is only correct for all entries...
Definition: MapCacheStatistics-inl.h:41
unsigned char uint8
Definition: PlatformTypes.h:175