#ifndef REFLECTIVE_RAPIDJSON_JSON_SERIALIZABLE_H #define REFLECTIVE_RAPIDJSON_JSON_SERIALIZABLE_H /*! * \file jsonserializable.h * \brief Contains only the definiation of the JSONSerializable template class which makes the reflection * accessible. The actual implementation is found in jsonreflector.h and generated files. */ #include "./jsonreflector.h" #include #include namespace ReflectiveRapidJSON { /*! * \brief The JSONSerializable class provides the CRTP-base for (de)serializable objects. */ template struct JSONSerializable { // RapidJSON-level API void push(RAPIDJSON_NAMESPACE::Value &container); void push(RAPIDJSON_NAMESPACE::Value &container, const char *name); // high-level API RAPIDJSON_NAMESPACE::StringBuffer toJson() const; static Type fromJson(const char *json, std::size_t jsonSize); static Type fromJson(const char *json); static Type fromJson(const std::string &json); template>...> RAPIDJSON_NAMESPACE::StringBuffer toJsonAs() const; static constexpr const char *qualifiedName = "ReflectiveRapidJSON::JSONSerializable"; }; /*! * \brief Pushes the object to the specified RapidJSON array. */ template void JSONSerializable::push(RAPIDJSON_NAMESPACE::Value &container) { return Reflector::push(*this, container); } /*! * \brief Pushes the object to the specified RapidJSON object as a member with the specified \a name. */ template void JSONSerializable::push(RAPIDJSON_NAMESPACE::Value &container, const char *name) { return Reflector::push(*this, name, container); } /*! * \brief Converts the object to its JSON representation. * \remarks To obtain a string from the returned buffer, just use its GetString() method. */ template RAPIDJSON_NAMESPACE::StringBuffer JSONSerializable::toJson() const { return Reflector::toJson(static_cast(*this)); } /*! * \brief Constructs a new object from the specified JSON. */ template Type JSONSerializable::fromJson(const char *json, std::size_t jsonSize) { return Reflector::fromJson(json, jsonSize); } /*! * \brief Constructs a new object from the specified JSON. */ template Type JSONSerializable::fromJson(const char *json) { return Reflector::fromJson(json, std::strlen(json)); } /*! * \brief Constructs a new object from the specified JSON. */ template Type JSONSerializable::fromJson(const std::string &json) { return Reflector::fromJson(json.data(), json.size()); } template template>...> RAPIDJSON_NAMESPACE::StringBuffer JSONSerializable::toJsonAs() const { return static_cast(this)->toJson(); } } // namespace ReflectiveRapidJSON #endif // REFLECTIVE_RAPIDJSON_JSON_SERIALIZABLE_H