Add some documentation

This commit is contained in:
Martchus 2017-10-25 19:18:13 +02:00
parent 0d17d5f20b
commit 8922c26c3d
2 changed files with 34 additions and 0 deletions

View File

@ -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 <c++utilities/conversion/types.h>
#include <c++utilities/misc/traits.h>

View File

@ -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 <rapidjson/document.h>
@ -9,6 +15,9 @@
namespace ReflectiveRapidJSON {
/*!
* \brief The JSONSerializable class provides the CRTP-base for (de)serializable objects.
*/
template <typename Type> struct JSONSerializable {
// RapidJSON-level API
void push(RAPIDJSON_NAMESPACE::Value &container);
@ -23,31 +32,50 @@ template <typename Type> struct JSONSerializable {
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::JSONSerializable";
};
/*!
* \brief Pushes the object to the specified RapidJSON array.
*/
template <typename Type> void JSONSerializable<Type>::push(RAPIDJSON_NAMESPACE::Value &container)
{
return Reflector::push<Type>(*this, container);
}
/*!
* \brief Pushes the object to the specified RapidJSON object as a member with the specified \a name.
*/
template <typename Type> void JSONSerializable<Type>::push(RAPIDJSON_NAMESPACE::Value &container, const char *name)
{
return Reflector::push<Type>(*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 <typename Type> RAPIDJSON_NAMESPACE::StringBuffer JSONSerializable<Type>::toJson() const
{
return Reflector::toJson<Type>(static_cast<const Type &>(*this));
}
/*!
* \brief Constructs a new object from the specified JSON.
*/
template <typename Type> Type JSONSerializable<Type>::fromJson(const char *json, std::size_t jsonSize)
{
return Reflector::fromJson<Type>(json, jsonSize);
}
/*!
* \brief Constructs a new object from the specified JSON.
*/
template <typename Type> Type JSONSerializable<Type>::fromJson(const char *json)
{
return Reflector::fromJson<Type>(json, std::strlen(json));
}
/*!
* \brief Constructs a new object from the specified JSON.
*/
template <typename Type> Type JSONSerializable<Type>::fromJson(const std::string &json)
{
return Reflector::fromJson<Type>(json.data(), json.size());