diff --git a/lib/jsonreflector.h b/lib/jsonreflector.h index 194a39b..dde9a77 100644 --- a/lib/jsonreflector.h +++ b/lib/jsonreflector.h @@ -1,6 +1,12 @@ #ifndef REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H #define REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_H +/*! + * \file jsonreflector.h + * \brief Contains functions to (de)serialize basic types such as int, double, bool, std::string, + * std::vector, ... with RapidJSON. + */ + #include #include diff --git a/lib/jsonserializable.h b/lib/jsonserializable.h index e692228..f20cf01 100644 --- a/lib/jsonserializable.h +++ b/lib/jsonserializable.h @@ -1,6 +1,12 @@ #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 @@ -9,6 +15,9 @@ 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); @@ -23,31 +32,50 @@ template struct JSONSerializable { 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());