Reflection for RapidJSON 0.0.16
Reflection for serializing/deserializing with RapidJSON
Loading...
Searching...
No Matches
reflector-boosthana.h
Go to the documentation of this file.
1#ifndef REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_BOOST_HANA_H
2#define REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_BOOST_HANA_H
3
15#include "./reflector.h"
16
17#include <boost/hana/adapt_struct.hpp>
18#include <boost/hana/at_key.hpp>
19#include <boost/hana/define_struct.hpp>
20#include <boost/hana/for_each.hpp>
21#include <boost/hana/intersection.hpp>
22#include <boost/hana/keys.hpp>
23
24namespace ReflectiveRapidJSON {
25namespace JsonReflector {
26
27// define function to "push" values to a RapidJSON array or object
28
29template <typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
30void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value::Object &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
31{
32 boost::hana::for_each(boost::hana::keys(reflectable), [&reflectable, &value, &allocator](auto key) {
33 push(boost::hana::at_key(reflectable, key), boost::hana::to<char const *>(key), value, allocator);
34 });
35}
36
37// define function to "pull" values from a RapidJSON array or object
38
39template <typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
40void pull(Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>>::ConstObject &value,
42{
43 boost::hana::for_each(boost::hana::keys(reflectable), [&reflectable, &value, &errors](auto key) {
44 pull(boost::hana::at_key(reflectable, key), boost::hana::to<char const *>(key), value, errors);
45 });
46}
47
48} // namespace JsonReflector
49} // namespace ReflectiveRapidJSON
50
51#endif // REFLECTIVE_RAPIDJSON_JSON_REFLECTOR_BOOST_HANA_H
Contains functions to (de)serialize basic types such as int, double, bool, std::string,...
void 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.
void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
Pushes the specified reflectable to the specified value.
Definition reflector.h:140
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.