libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
windowedstatsbundle.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <promeki/function.h>
14#include <promeki/namespace.h>
15#include <promeki/datastream.h>
16#include <promeki/error.h>
17#include <promeki/json.h>
18#include <promeki/list.h>
19#include <promeki/map.h>
21#include <promeki/string.h>
22#include <promeki/stringlist.h>
24
25PROMEKI_NAMESPACE_BEGIN
26
55class WindowedStatsBundle {
56 public:
58 using ID = MediaIOStats::ID;
59
61 using Map = ::promeki::Map<ID, WindowedStat>;
62
64 using List = ::promeki::List<WindowedStatsBundle>;
65
66 WindowedStatsBundle() = default;
67
68 // ------------------------------------------------------------
69 // Capacity / membership
70 // ------------------------------------------------------------
71
73 size_t size() const { return _windows.size(); }
74
76 bool isEmpty() const { return _windows.isEmpty(); }
77
79 bool contains(ID id) const { return _windows.contains(id); }
80
82 void clear() { _windows.clear(); }
83
84 // ------------------------------------------------------------
85 // Accessors
86 // ------------------------------------------------------------
87
92 WindowedStat get(ID id) const;
93
99 void set(ID id, const WindowedStat &ws) { _windows.insert(id, ws); }
100
102 void set(ID id, WindowedStat &&ws) { _windows.insert(id, std::move(ws)); }
103
105 void remove(ID id);
106
108 const Map &windows() const { return _windows; }
109
111 Map &windows() { return _windows; }
112
120 template <typename Func> void forEach(Func &&func) const {
121 for (auto it = _windows.cbegin(); it != _windows.cend(); ++it) {
122 func(it->first, it->second);
123 }
124 }
125
126 // ------------------------------------------------------------
127 // Rendering / serialization
128 // ------------------------------------------------------------
129
141 using ValueFormatter = Function<WindowedStat::ValueFormatter(ID)>;
142 StringList describe(const ValueFormatter &formatter = ValueFormatter()) const;
143
145 JsonObject toJson() const;
146
156 static WindowedStatsBundle fromJson(const JsonObject &obj, Error *err = nullptr);
157
159 bool operator==(const WindowedStatsBundle &other) const { return _windows == other._windows; }
160 bool operator!=(const WindowedStatsBundle &other) const { return !(*this == other); }
161
162 private:
163 Map _windows;
164};
165
167DataStream &operator<<(DataStream &stream, const WindowedStatsBundle &b);
168
170DataStream &operator>>(DataStream &stream, WindowedStatsBundle &b);
171
172PROMEKI_NAMESPACE_END
173
174#endif // PROMEKI_ENABLE_PROAV