From d5144d8e7519d75b0bed6b70660b95eea18aed2a Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 16 Nov 2017 01:46:20 +0100 Subject: [PATCH] Restore GCC compatibility --- generator/tests/structs.h | 7 ++++--- lib/json/reflector.h | 12 ++++++++++-- lib/json/serializable.h | 12 +++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/generator/tests/structs.h b/generator/tests/structs.h index 259c532..3fce9b4 100644 --- a/generator/tests/structs.h +++ b/generator/tests/structs.h @@ -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 #include +#include "../../lib/json/reflector-chronoutilities.h" +#include "../../lib/json/serializable.h" + #include #include #include @@ -38,6 +38,7 @@ class JsonGeneratorTests; */ struct NestedTestStruct : public JsonSerializable { REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(NestedTestStruct); + friend class JsonGeneratorTests; list> nested; diff --git a/lib/json/reflector.h b/lib/json/reflector.h index 938a91a..18ad0a7 100644 --- a/lib/json/reflector.h +++ b/lib/json/reflector.h @@ -27,7 +27,14 @@ namespace ReflectiveRapidJSON { template struct JsonSerializable; -template struct AdaptedJsonSerializable; + +/*! + * \brief The AdaptedJsonSerializable class allows considering 3rd party classes as serializable. + */ +template struct AdaptedJsonSerializable : public Traits::Bool { + 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_floating_point template using IsCustomType = Traits::Not>; // define trait to check for custom structs/classes which are JSON serializable -template using IsJsonSerializable = Traits::Any, Type>, AdaptedJsonSerializable>; +// NOTE: the check for Traits::IsComplete is required because std::is_base_of fails for incomplete types when using GCC +template using IsJsonSerializable = Traits::Any>, std::is_base_of, Type>, AdaptedJsonSerializable>; // define trait to check for map or hash template diff --git a/lib/json/serializable.h b/lib/json/serializable.h index 71a7468..1820f05 100644 --- a/lib/json/serializable.h +++ b/lib/json/serializable.h @@ -98,21 +98,15 @@ const JsonSerializable &as(const Type &serializable) return static_cast &>(serializable); } -/*! - * \brief The AdaptedJsonSerializable class allows considering 3rd party classes as serializable. - */ -template struct AdaptedJsonSerializable : Traits::Bool { - 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 : Traits::Bool { \ + template <> struct ReflectiveRapidJSON::AdaptedJsonSerializable : Traits::Bool { \ } /*!