libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
enumlist.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <promeki/namespace.h>
14#include <promeki/enum.h>
15#include <promeki/error.h>
16#include <promeki/list.h>
17#include <promeki/string.h>
18#include <promeki/stringlist.h>
19#include <promeki/datatype.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
23class DataStream;
24
65class EnumList {
66 public:
67 PROMEKI_DATATYPE(EnumList, DataTypeEnumList, 1)
68
69
78 Error writeToStream(DataStream &s) const;
80 template <uint32_t V> static Result<EnumList> readFromStream(DataStream &s);
81
83 EnumList() = default;
84
89 explicit EnumList(Enum::Type type) : _type(type) {}
90
103 template <typename T> static EnumList forType() { return EnumList(T::Type); }
104
105 // --------------------------------------------------------------
106 // State
107 // --------------------------------------------------------------
108
110 Enum::Type elementType() const { return _type; }
111
113 bool isValid() const { return _type.isValid(); }
114
116 size_t size() const { return _values.size(); }
117
119 bool isEmpty() const { return _values.isEmpty(); }
120
122 void clear() { _values.clear(); }
123
124 // --------------------------------------------------------------
125 // Append
126 // --------------------------------------------------------------
127
138 bool append(const Enum &e, Error *err = nullptr);
139
147 bool append(int value, Error *err = nullptr);
148
156 bool append(const String &name, Error *err = nullptr);
157
158 // --------------------------------------------------------------
159 // Access
160 // --------------------------------------------------------------
161
166 Enum at(size_t i) const { return Enum(_type, _values[i]); }
167
169 Enum operator[](size_t i) const { return at(i); }
170
172 const List<int> &values() const { return _values; }
173
174 // --------------------------------------------------------------
175 // Transformations
176 // --------------------------------------------------------------
177
187 EnumList uniqueSorted() const;
188
189 // --------------------------------------------------------------
190 // String
191 // --------------------------------------------------------------
192
213 String toString() const;
214
236 static Result<EnumList> fromString(const String &text);
237
238 // --------------------------------------------------------------
239 // Equality
240 // --------------------------------------------------------------
241
245 bool operator==(const EnumList &o) const { return _type == o._type && _values == o._values; }
246 bool operator!=(const EnumList &o) const { return !(*this == o); }
247
248 private:
249 Enum::Type _type;
250 List<int> _values;
251};
252
253PROMEKI_NAMESPACE_END
254
255PROMEKI_FORMAT_VIA_TOSTRING(promeki::EnumList);
256
257#endif // PROMEKI_ENABLE_CORE