1#ifndef REFLECTIVE_RAPIDJSON_VERSIONING
2#define REFLECTIVE_RAPIDJSON_VERSIONING
4#include <c++utilities/misc/traits.h>
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; \
14#define REFLECTIVE_RAPIDJSON_UNTIL_VERSION(version) \
15 static constexpr std::size_t REFLECTIVE_RAPIDJSON_CAT_2(rrjUntilVersion, __COUNTER__) = version; \
18#define REFLECTIVE_RAPIDJSON_AS_OF_VERSION(version) public
19#define REFLECTIVE_RAPIDJSON_UNTIL_VERSION(version) public
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)
34template <typename Type, bool Condition = IsVersioned<Type>::value>
struct Versioning {
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)
45 version = serializationDefault;
49 static constexpr auto applyDefaultValue(std::remove_const_t<
decltype(serializationDefault)> version)
51 return applyDefault(version);
53 static constexpr auto isSupported(
decltype(maxSupported) version)
55 return version <= maxSupported;
57 static constexpr auto assertVersion(
decltype(maxSupported) version,
const char *record =
nullptr)
59 if (!isSupported(version)) {
60 throw typename Type::VersionNotSupported({ .presentVersion = version, .maxVersion = maxSupported, .record = record });
CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK(IsVersioned, T::version)
VersionType presentVersion
static constexpr auto isSupported(decltype(maxSupported) version)
static constexpr auto & applyDefault(std::remove_const_t< decltype(serializationDefault)> &version)
static constexpr auto applyDefaultValue(std::remove_const_t< decltype(serializationDefault)> version)
static constexpr auto assertVersion(decltype(maxSupported) version, const char *record=nullptr)
static constexpr auto enabled