Reflection for RapidJSON  0.0.15
Reflection for serializing/deserializing with RapidJSON
Classes | Namespaces | Typedefs | Functions
reflector.h File Reference

Contains functions to (de)serialize basic types such as int, double, bool, std::string, std::vector, ... with RapidJSON. More...

#include "../traits.h"
#include <c++utilities/application/global.h>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <limits>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include "./errorhandling.h"
Include dependency graph for reflector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ReflectiveRapidJSON::JsonSerializable< Type >
 The JsonSerializable class provides the CRTP-base for (de)serializable objects. More...
 
struct  ReflectiveRapidJSON::AdaptedJsonSerializable< T >
 The AdaptedJsonSerializable class allows considering 3rd party classes as serializable. More...
 
struct  ReflectiveRapidJSON::JsonReflector::Detail::TuplePushHelper< Tuple, N >
 The TuplePushHelper class helps serializing tuples to JSON arrays. More...
 
struct  ReflectiveRapidJSON::JsonReflector::Detail::TuplePushHelper< Tuple, 1 >
 
struct  ReflectiveRapidJSON::JsonReflector::Detail::TuplePullHelper< Tuple, N >
 The TuplePullHelper class helps deserializing tuples from JSON arrays. More...
 
struct  ReflectiveRapidJSON::JsonReflector::Detail::TuplePullHelper< Tuple, 1 >
 

Namespaces

 ReflectiveRapidJSON
 
 ReflectiveRapidJSON::JsonReflector
 The JsonReflector namespace contains helper functions to ease the use of RapidJSON for automatic (de)serialization.
 
 ReflectiveRapidJSON::JsonReflector::Detail
 

Typedefs

template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsBuiltInType = Traits::Any< std::is_integral< Type >, std::is_floating_point< Type >, std::is_pointer< Type >, std::is_enum< Type >, Traits::IsSpecializationOf< Type, std::tuple >, Traits::IsSpecializationOf< Type, std::pair >, Traits::IsIteratable< Type >, Traits::IsSpecializationOf< Type, std::unique_ptr >, Traits::IsSpecializationOf< Type, std::shared_ptr >, Traits::IsSpecializationOf< Type, std::weak_ptr >, IsVariant< Type > >
 
template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsCustomType = Traits::Not< IsBuiltInType< Type > >
 
template<typename Type >
using ReflectiveRapidJSON::JsonReflector::IsJsonSerializable = Traits::Any< Traits::Not< Traits::IsComplete< Type > >, std::is_base_of< JsonSerializable< Type >, Type >, AdaptedJsonSerializable< Type > >
 

Functions

constexpr RAPIDJSON_NAMESPACE::SizeType ReflectiveRapidJSON::JsonReflector::rapidJsonSize (std::size_t size)
 Casts the specified size to the size type used by RapidJSON ensuring no overflow happens. More...
 
RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::serializeJsonDocToString (RAPIDJSON_NAMESPACE::Document &document)
 Serializes the specified JSON document. More...
 
RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::parseJsonDocFromString (const char *json, std::size_t jsonSize)
 Parses the specified JSON string. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::push (const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified reflectable to the specified value. More...
 
template<typename Type , Traits::DisableIf< IsJsonSerializable< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::push (const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Array &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the reflectable to the specified array. More...
 
template<typename Type , Traits::EnableIf< IsJsonSerializable< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::push (const Type &reflectable, const char *name, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified reflectable which has custom type as a member to the specified object. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::push (const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the reflectable which has a custom type to the specified object. More...
 
template<typename Type , Traits::EnableIfAny< std::is_integral< Type >, std::is_floating_point< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::push (Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
 Pushes the specified integer/float/boolean to the specified value. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::pull (Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstObject &value, JsonDeserializationErrors *errors)
 Pulls the reflectable which has a custom type from the specified object. More...
 
template<typename Type , Traits::DisableIf< IsBuiltInType< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::pull (Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &value, JsonDeserializationErrors *errors)
 Pulls the reflectable which has a custom type from the specified value which is supposed and checked to contain an object. More...
 
template<typename Type , Traits::EnableIf< IsArrayOrSet< Type >, Traits::Not< Traits::IsReservable< Type >>> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::pull (Type &reflectable, const rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >> &value, JsonDeserializationErrors *errors)
 Pulls the specified reflectable which is an iteratable without reserve() method from the specified value which is checked to contain an array. More...
 
template<typename Type , Traits::EnableIf< IsArray< Type >> * = nullptr>
void ReflectiveRapidJSON::JsonReflector::pull (Type &reflectable, rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstArray array, JsonDeserializationErrors *errors)
 Pulls the specified reflectable which is an array/vector/list from the specified array. More...
 
template<typename Type >
void ReflectiveRapidJSON::JsonReflector::pull (Type &reflectable, rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ValueIterator &value, JsonDeserializationErrors *errors)
 Pulls the specified reflectable from the specified value iterator which is checked to contain the right type. More...
 
template<typename Type >
void ReflectiveRapidJSON::JsonReflector::pull (Type &reflectable, const char *name, const rapidjson::GenericValue< RAPIDJSON_NAMESPACE::UTF8< char >>::ConstObject &value, JsonDeserializationErrors *errors)
 Pulls the specified member of reflectable which has a custom type from the specified object. More...
 
template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >, IsMultiMapOrHash< Type >> * = nullptr>
RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::toJsonDocument (const Type &reflectable)
 Serializes the specified reflectable which has a custom type or can be mapped to and object. More...
 
template<typename Type , Traits::EnableIfAny< std::is_integral< Type >, std::is_floating_point< Type >> * = nullptr>
RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::toJsonDocument (Type reflectable)
 Serializes the specified reflectable which is an integer, float or boolean. More...
 
template<typename Type , Traits::EnableIf< std::is_same< Type, std::string >> * = nullptr>
RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::toJsonDocument (const std::string &reflectable)
 Serializes the specified reflectable which is an std::string. More...
 
template<typename Type , Traits::EnableIf< std::is_same< Type, const char * >> * = nullptr>
RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::toJsonDocument (const char *reflectable)
 Serializes the specified reflectable which is a C-string. More...
 
template<typename Type , Traits::EnableIf< std::is_same< Type, std::string_view >> * = nullptr>
RAPIDJSON_NAMESPACE::Document ReflectiveRapidJSON::JsonReflector::toJsonDocument (std::string_view reflectable)
 Serializes the specified reflectable which is a C-string. More...
 
template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >, IsMultiMapOrHash< Type >, std::is_integral< Type >, std::is_floating_point< Type >, Traits::IsString< Type >, IsArray< Type >> * = nullptr>
RAPIDJSON_NAMESPACE::StringBuffer ReflectiveRapidJSON::JsonReflector::toJson (const Type &reflectable)
 Serializes the specified reflectable. More...
 
template<typename Type , Traits::EnableIfAny< IsJsonSerializable< Type >, IsMapOrHash< Type >, IsMultiMapOrHash< Type >> * = nullptr>
Type ReflectiveRapidJSON::JsonReflector::fromJson (const char *json, std::size_t jsonSize, JsonDeserializationErrors *errors=nullptr)
 Deserializes the specified JSON to. More...
 
template<typename Type >
Type ReflectiveRapidJSON::JsonReflector::fromJson (const char *json, JsonDeserializationErrors *errors=nullptr)
 Deserializes the specified JSON from an null-terminated C-string to. More...
 
template<typename Type >
Type ReflectiveRapidJSON::JsonReflector::fromJson (const std::string &json, JsonDeserializationErrors *errors=nullptr)
 Deserializes the specified JSON from an std::string to. More...
 

Detailed Description

Contains functions to (de)serialize basic types such as int, double, bool, std::string, std::vector, ... with RapidJSON.

Definition in file reflector.h.