OpenEnroth 73e68f7
|
#include <cassert>
#include <string>
#include <type_traits>
#include <functional>
#include <magic_enum.hpp>
#include "Utility/Preprocessor.h"
#include "Serialization.h"
#include "SerializationExceptions.h"
#include "EnumSerializer.h"
Macros | |
#define | MAGIC_ENUM_RANGE_MIN (-256) |
#define | MAGIC_ENUM_RANGE_MAX (255) |
#define | MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS(ENUM, CASE_SENSITIVITY, ...) MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS_I(ENUM, CASE_SENSITIVITY, MM_PP_CAT(globalEnumSerializer, __LINE__), __VA_ARGS__) |
#define | MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS_I(ENUM, CASE_SENSITIVITY, SERIALIZER, ...) |
#define | MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS_VIA_TRY_FUNCTIONS_I(TYPE) |
#define | MM_DEFINE_FLAGS_SERIALIZATION_FUNCTIONS(FLAGS) |
#define | MM_DEFINE_ENUM_MAGIC_SERIALIZATION_FUNCTIONS(ENUM) |
#define MAGIC_ENUM_RANGE_MAX (255) |
#define MAGIC_ENUM_RANGE_MIN (-256) |
#define MM_DEFINE_ENUM_MAGIC_SERIALIZATION_FUNCTIONS | ( | ENUM | ) |
Same as MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS
, but using magic_enum
.
Note that MM_DEFINE_FLAGS_SERIALIZATION_FUNCTIONS
currently cannot be used with enums serialized with this macro.
ENUM | Enum type to generate lexical serialization functions for. |
#define MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS | ( | ENUM, | |
CASE_SENSITIVITY, | |||
... | |||
) | MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS_I(ENUM, CASE_SENSITIVITY, MM_PP_CAT(globalEnumSerializer, __LINE__), __VA_ARGS__) |
This macro generates lexical serialization functions for the provided enumeration type.. The typical use case is to use it in the cpp
file, and use MM_DECLARE_SERIALIZATION_FUNCTIONS
in the header file.
Note that it should be invoked from the namespace of the target enumeration type, otherwise argument-dependent lookup won't find it, and unqualified calls to serialize
/ trySerialize
/ deserialize
/ tryDeserialize
won't work. ToString
and FromString
function objects also won't work.
However, it might make sense to invoke this macro from several different namespaces to generate several sets of serialization functions for the same type. In this case the serialization functions won't be discovered by ADL, so you'll have to use qualified calls, but this is likely exactly what you'd want. The only downside is that ToString
/ FromString
global function objects won't work.
Usage example:
ENUM | Enum type to generate lexical serialization functions for. |
CASE_SENSITIVITY | Whether the mapping is case sensitive, either CASE_SENSITIVE or CASE_INSENSITIVE . |
... | Initializer list of enum-string pairs. Can contain repeated values, in which case the 1st match will be used during serialization / deserialization. |
#define MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS_I | ( | ENUM, | |
CASE_SENSITIVITY, | |||
SERIALIZER, | |||
... | |||
) |
#define MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS_VIA_TRY_FUNCTIONS_I | ( | TYPE | ) |
#define MM_DEFINE_FLAGS_SERIALIZATION_FUNCTIONS | ( | FLAGS | ) |
This macro provides a limited support for lexical serialization of Flags<T>
. It can only be used after an invocation of MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS
for the underlying enum type.
FLAGS | Flags type to generate lexical serialization functions for. |