Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
versioning.h
Go to the documentation of this file.
1
#ifndef REFLECTIVE_RAPIDJSON_VERSIONING
2
#define REFLECTIVE_RAPIDJSON_VERSIONING
3
4
#include <c++utilities/misc/traits.h>
5
6
namespace
ReflectiveRapidJSON
{
7
8
#ifdef REFLECTIVE_RAPIDJSON_GENERATOR
9
#define REFLECTIVE_RAPIDJSON_CAT_1(a, b) a##b
10
#define REFLECTIVE_RAPIDJSON_CAT_2(a, b) REFLECTIVE_RAPIDJSON_CAT_1(a, b)
11
#define REFLECTIVE_RAPIDJSON_AS_OF_VERSION(version) \
12
static constexpr std::size_t REFLECTIVE_RAPIDJSON_CAT_2(rrjAsOfVersion, __COUNTER__) = version; \
13
public
14
#define REFLECTIVE_RAPIDJSON_UNTIL_VERSION(version) \
15
static constexpr std::size_t REFLECTIVE_RAPIDJSON_CAT_2(rrjUntilVersion, __COUNTER__) = version; \
16
public
17
#else
18
#define REFLECTIVE_RAPIDJSON_AS_OF_VERSION(version) public
19
#define REFLECTIVE_RAPIDJSON_UNTIL_VERSION(version) public
20
#endif
21
22
#ifdef REFLECTIVE_RAPIDJSON_SHORT_MACROS
23
#define as_of_version(version) REFLECTIVE_RAPIDJSON_AS_OF_VERSION(version)
24
#define until_version(version) REFLECTIVE_RAPIDJSON_UNTIL_VERSION(version)
25
#endif
26
27
CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK
(IsVersioned, T::version);
28
29
template
<
typename
VersionType>
struct
VersionNotSupported
{
30
VersionType
presentVersion
= 0,
maxVersion
= 0;
31
const
char
*
record
=
nullptr
;
32
};
33
34
template <typename Type, bool Condition = IsVersioned<Type>::value>
struct
Versioning
{
35
static
constexpr
auto
enabled
=
false
;
36
};
37
38
template
<
typename
Type>
struct
Versioning
<Type, true> {
39
static
constexpr
auto
enabled
= Type::version != 0;
40
static
constexpr
auto
serializationDefault
= Type::version;
41
static
constexpr
auto
maxSupported
= Type::version;
42
static
constexpr
auto
&
applyDefault
(std::remove_const_t<
decltype
(
serializationDefault
)> &version)
43
{
44
if
(!version) {
45
version =
serializationDefault
;
46
}
47
return
version;
48
}
49
static
constexpr
auto
applyDefaultValue
(std::remove_const_t<
decltype
(
serializationDefault
)> version)
50
{
51
return
applyDefault
(version);
52
}
53
static
constexpr
auto
isSupported
(
decltype
(
maxSupported
) version)
54
{
55
return
version <=
maxSupported
;
56
}
57
static
constexpr
auto
assertVersion
(
decltype
(
maxSupported
) version,
const
char
*record =
nullptr
)
58
{
59
if
(!
isSupported
(version)) {
60
throw
typename
Type::VersionNotSupported({ .presentVersion = version, .maxVersion =
maxSupported
, .record = record });
61
}
62
}
63
};
64
65
}
// namespace ReflectiveRapidJSON
66
67
#endif
// REFLECTIVE_RAPIDJSON_TRAITS
ReflectiveRapidJSON
Definition
traits.h:13
ReflectiveRapidJSON::CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK
CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK(IsVersioned, T::version)
ReflectiveRapidJSON::VersionNotSupported
Definition
versioning.h:29
ReflectiveRapidJSON::VersionNotSupported< BinaryVersion >::maxVersion
BinaryVersion maxVersion
Definition
versioning.h:30
ReflectiveRapidJSON::VersionNotSupported< BinaryVersion >::presentVersion
BinaryVersion presentVersion
Definition
versioning.h:30
ReflectiveRapidJSON::VersionNotSupported< BinaryVersion >::record
const char * record
Definition
versioning.h:31
ReflectiveRapidJSON::Versioning< Type, true >::isSupported
static constexpr auto isSupported(decltype(maxSupported) version)
Definition
versioning.h:53
ReflectiveRapidJSON::Versioning< Type, true >::maxSupported
static constexpr auto maxSupported
Definition
versioning.h:41
ReflectiveRapidJSON::Versioning< Type, true >::enabled
static constexpr auto enabled
Definition
versioning.h:39
ReflectiveRapidJSON::Versioning< Type, true >::applyDefault
static constexpr auto & applyDefault(std::remove_const_t< decltype(serializationDefault)> &version)
Definition
versioning.h:42
ReflectiveRapidJSON::Versioning< Type, true >::serializationDefault
static constexpr auto serializationDefault
Definition
versioning.h:40
ReflectiveRapidJSON::Versioning< Type, true >::applyDefaultValue
static constexpr auto applyDefaultValue(std::remove_const_t< decltype(serializationDefault)> version)
Definition
versioning.h:49
ReflectiveRapidJSON::Versioning< Type, true >::assertVersion
static constexpr auto assertVersion(decltype(maxSupported) version, const char *record=nullptr)
Definition
versioning.h:57
ReflectiveRapidJSON::Versioning
Definition
versioning.h:34
ReflectiveRapidJSON::Versioning::enabled
static constexpr auto enabled
Definition
versioning.h:35
Generated on
for Reflection for RapidJSON by
1.18.0