Reflection for RapidJSON  0.0.15
Reflection for serializing/deserializing with RapidJSON
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 
24 namespace ReflectiveRapidJSON {
25 namespace JsonReflector {
26 
27 // define function to "push" values to a RapidJSON array or object
28 
29 template <typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
30 void 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 
39 template <typename Type, Traits::DisableIf<IsBuiltInType<Type>> *>
40 void 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
ReflectiveRapidJSON::JsonDeserializationErrors
The JsonDeserializationErrors struct can be passed to fromJson() for error handling.
Definition: errorhandling.h:154
reflector.h
Contains BinaryReader and BinaryWriter supporting binary (de)serialization of primitive and custom ty...
ReflectiveRapidJSON::JsonReflector::pull
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.
Definition: reflector-boosthana.h:40
ReflectiveRapidJSON
Definition: traits.h:13
ReflectiveRapidJSON::JsonReflector::push
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