18 #ifndef INCLUDED_SERIALIZED_TYPES 19 #define INCLUDED_SERIALIZED_TYPES 34 #include <unordered_map> 37 template<
typename T,
size_t N>
42 for (
size_t i = 0; i < N; ++i)
48 for (
size_t i = 0; i < N; ++i)
58 size_t len = value.size();
60 for (
size_t i = 0; i < len; ++i)
70 for (
size_t i = 0; i < len; ++i)
74 value.emplace_back(el);
85 for (
const T& elem : value)
94 for (
size_t i = 0; i < size; ++i)
98 value.emplace(std::move(el));
103 template<
typename K,
typename V>
106 template<
typename... Args>
109 size_t len = value.size();
111 for (
typename std::map<K, V>::iterator it = value.begin(); it != value.end(); ++it)
113 Serializer(serialize,
"key", it->first, std::forward<Args>(args)...);
114 Serializer(serialize,
"value", it->second, std::forward<Args>(args)...);
118 template<
typename... Args>
124 for (
size_t i = 0; i < len; ++i)
128 Serializer(deserialize,
"key", k, std::forward<Args>(args)...);
129 Serializer(deserialize,
"value", v, std::forward<Args>(args)...);
130 value.emplace(std::move(k), std::move(v));
136 template<
typename K,
typename V>
141 std::map<K, V> ordered_value(value.begin(), value.end());
166 template<
typename Enum>
171 serialize.
NumberU8(name, static_cast<u8>(value), 0, static_cast<u8>(max));
177 deserialize.
NumberU8(name, val, 0, static_cast<u8>(max));
178 value =
static_cast<Enum
>(val);
200 template<
typename... Args>
206 template<
typename... Args>
232 serialize.
Bool(name, value);
237 deserialize.
Bool(name, value);
241 template<
typename StringLike>
257 #endif // INCLUDED_SERIALIZED_TYPES virtual void StringASCII(const char *name, std::string &out, uint32_t minlength, uint32_t maxlength)
Definition: IDeserializer.cpp:162
virtual void Bool(const char *name, bool &out)
Definition: IDeserializer.cpp:155
Helper templates definitions for serializing/deserializing common objects.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
void operator()(ISerializer &serialize, const char *name, std::array< T, N > &value)
Definition: SerializedTypes.h:40
void operator()(ISerializer &serialize, const char *name, bool value)
Definition: SerializedTypes.h:230
void operator()(IDeserializer &deserialize, const char *name, bool &value)
Definition: SerializedTypes.h:235
uint16_t u16
Definition: types.h:38
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
void operator()(IDeserializer &deserialize, const char *name, std::map< K, V > &value, Args &&... args)
Definition: SerializedTypes.h:119
void Serializer(S &serialize, const char *name, Args &&... args)
Definition: SerializeTemplates.h:51
void NumberU8_Unbounded(const char *name, uint8_t value)
Serialize a number.
Definition: ISerializer.h:150
virtual void NumberU32_Unbounded(const char *name, uint32_t &out)
Definition: IDeserializer.cpp:124
Definition: ShaderDefines.cpp:30
virtual void NumberU8_Unbounded(const char *name, uint8_t &out)
Definition: IDeserializer.cpp:100
uint8_t u8
Definition: types.h:37
#define UINT32_MAX
Definition: wposix_types.h:73
void operator()(IDeserializer &deserialize, const char *name, u16 &value)
Definition: SerializedTypes.h:191
void operator()(IDeserializer &deserialize, const char *name, std::vector< T > &value)
Definition: SerializedTypes.h:64
void operator()(ISerializer &serialize, const char *name, std::map< K, V > &value, Args &&... args)
Definition: SerializedTypes.h:107
uint32_t u32
Definition: types.h:39
void operator()(ISerializer &serialize, const char *name, T &&value)
Definition: SerializedTypes.h:245
void StringASCII(const char *name, const std::string &value, uint32_t minlength, uint32_t maxlength)
Serialize an ASCII string.
Definition: ISerializer.cpp:70
void operator()(ISerializer &serialize, const char *name, Enum value, Enum &&max)
Definition: SerializedTypes.h:169
void operator()(ISerializer &serialize, const char *name, u16 value)
Definition: SerializedTypes.h:186
void operator()(ISerializer &serialize, const char *name, i32 value)
Definition: SerializedTypes.h:216
void operator()(ISerializer &serialize, const char *name, u8 value)
Definition: SerializedTypes.h:154
void operator()(ISerializer &serialize, const char *name, const std::set< T > &value)
Definition: SerializedTypes.h:82
void Bool(const char *name, bool value)
Serialize a boolean.
Definition: ISerializer.h:199
void operator()(IDeserializer &deserialize, const char *name, i32 &value)
Definition: SerializedTypes.h:221
void operator()(IDeserializer &deserialize, const char *name, std::set< T > &value)
Definition: SerializedTypes.h:89
void operator()(IDeserializer &deserialize, const char *name, std::unordered_map< K, V > &value)
Definition: SerializedTypes.h:145
void operator()(ISerializer &serialize, const char *name, u32 value, Args &&...)
Definition: SerializedTypes.h:201
#define T(string_literal)
Definition: secure_crt.cpp:77
void NumberU32_Unbounded(const char *name, uint32_t value)
Serialize a number.
Definition: ISerializer.h:171
Definition: SerializeTemplates.h:41
int32_t i32
Definition: types.h:34
void operator()(IDeserializer &deserialize, const char *name, Enum &value, Enum &&max)
Definition: SerializedTypes.h:174
virtual void NumberU8(const char *name, uint8_t &out, uint8_t lower, uint8_t upper)
Definition: IDeserializer.cpp:30
void NumberI32_Unbounded(const char *name, int32_t value)
Serialize a number.
Definition: ISerializer.h:176
void operator()(ISerializer &serialize, const char *name, std::vector< T > &value)
Definition: SerializedTypes.h:56
void operator()(IDeserializer &deserialize, const char *name, u8 &value)
Definition: SerializedTypes.h:159
void NumberU16_Unbounded(const char *name, uint16_t value)
Serialize a number.
Definition: ISerializer.h:161
void operator()(ISerializer &serialize, const char *name, std::unordered_map< K, V > &value)
Definition: SerializedTypes.h:139
void NumberU8(const char *name, uint8_t value, uint8_t lower, uint8_t upper)
Serialize a number, which must be lower <= value <= upper.
Definition: ISerializer.cpp:28
void operator()(IDeserializer &deserialize, const char *name, std::array< T, N > &value)
Definition: SerializedTypes.h:46
virtual void NumberU16_Unbounded(const char *name, uint16_t &out)
Definition: IDeserializer.cpp:110
void operator()(IDeserializer &deserialize, const char *name, u32 &value, Args &&...)
Definition: SerializedTypes.h:207
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34
virtual void NumberI32_Unbounded(const char *name, int32_t &out)
Definition: IDeserializer.cpp:131
void operator()(IDeserializer &deserialize, const char *name, T &value)
Definition: SerializedTypes.h:251