Restore GCC compatibility

This commit is contained in:
Martchus 2017-11-16 01:46:20 +01:00
parent a159bdbdb0
commit d5144d8e75
3 changed files with 17 additions and 14 deletions

View File

@ -1,12 +1,12 @@
#ifndef REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
#define REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
#include "../../lib/json/reflector-chronoutilities.h"
#include "../../lib/json/serializable.h"
#include <c++utilities/chrono/datetime.h>
#include <c++utilities/chrono/timespan.h>
#include "../../lib/json/reflector-chronoutilities.h"
#include "../../lib/json/serializable.h"
#include <deque>
#include <list>
#include <string>
@ -38,6 +38,7 @@ class JsonGeneratorTests;
*/
struct NestedTestStruct : public JsonSerializable<NestedTestStruct> {
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(NestedTestStruct);
friend class JsonGeneratorTests;
list<vector<TestStruct>> nested;

View File

@ -27,7 +27,14 @@
namespace ReflectiveRapidJSON {
template <typename Type> struct JsonSerializable;
template <typename Type> struct AdaptedJsonSerializable;
/*!
* \brief The AdaptedJsonSerializable class allows considering 3rd party classes as serializable.
*/
template <typename T> struct AdaptedJsonSerializable : public Traits::Bool<false> {
static constexpr const char *name = "AdaptedJsonSerializable";
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::AdaptedJsonSerializable";
};
/*!
* \brief The JsonReflector namespace contains helper functions to ease the use of RapidJSON for automatic (de)serialization.
@ -75,7 +82,8 @@ using IsBuiltInType = Traits::Any<std::is_integral<Type>, std::is_floating_point
template <typename Type> using IsCustomType = Traits::Not<IsBuiltInType<Type>>;
// define trait to check for custom structs/classes which are JSON serializable
template <typename Type> using IsJsonSerializable = Traits::Any<std::is_base_of<JsonSerializable<Type>, Type>, AdaptedJsonSerializable<Type>>;
// NOTE: the check for Traits::IsComplete is required because std::is_base_of fails for incomplete types when using GCC
template <typename Type> using IsJsonSerializable = Traits::Any<Traits::Not<Traits::IsComplete<Type>>, std::is_base_of<JsonSerializable<Type>, Type>, AdaptedJsonSerializable<Type>>;
// define trait to check for map or hash
template <typename Type>

View File

@ -98,21 +98,15 @@ const JsonSerializable<Type> &as(const Type &serializable)
return static_cast<const JsonSerializable<Type> &>(serializable);
}
/*!
* \brief The AdaptedJsonSerializable class allows considering 3rd party classes as serializable.
*/
template <typename T> struct AdaptedJsonSerializable : Traits::Bool<false> {
static constexpr const char *name = "AdaptedJsonSerializable";
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::AdaptedJsonSerializable";
};
/*!
* \def The REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE macro allows to adapt (de)serialization for types defined in 3rd party header files.
* \remarks The struct will not have the toJson() and fromJson() methods available. Use the corresponding functions in the namespace
* ReflectiveRapidJSON::JsonReflector instead.
* \todo GCC complains when putting :: before "ReflectiveRapidJSON" namespace: "global qualification of class name is invalid before ':' token"
* Find out whether this is a compiler bug or a correct error message.
*/
#define REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(T) \
template <> struct ::ReflectiveRapidJSON::AdaptedJsonSerializable<T> : Traits::Bool<true> { \
template <> struct ReflectiveRapidJSON::AdaptedJsonSerializable<T> : Traits::Bool<true> { \
}
/*!