2018-06-23 14:35:43 +02:00
|
|
|
#ifndef REFLECTIVE_RAPIDJSON_BINARY_REFLECTOR_BOOST_HANA_H
|
|
|
|
#define REFLECTIVE_RAPIDJSON_BINARY_REFLECTOR_BOOST_HANA_H
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \file reflector-boosthana.h
|
|
|
|
* \brief Contains generic functions relying on Boost.Hana which can replace the code which would
|
|
|
|
* otherwise had to be generated.
|
|
|
|
* \remarks
|
|
|
|
* These functions use boost::hana::keys() and boost::hana::at_key() rather than the "plain"
|
|
|
|
* for-loop shown in the introspection examples of the Boost.Hana documentation. The reason is that
|
|
|
|
* the "plain" for-loop involves making copies. This costs performance and - more importantly - prevents
|
|
|
|
* modifying the actual object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "./reflector.h"
|
|
|
|
|
|
|
|
#include <boost/hana/adapt_struct.hpp>
|
|
|
|
#include <boost/hana/at_key.hpp>
|
|
|
|
#include <boost/hana/define_struct.hpp>
|
|
|
|
#include <boost/hana/for_each.hpp>
|
|
|
|
#include <boost/hana/intersection.hpp>
|
|
|
|
#include <boost/hana/keys.hpp>
|
|
|
|
|
2018-06-23 15:30:51 +02:00
|
|
|
namespace ReflectiveRapidJSON {
|
2018-06-23 14:35:43 +02:00
|
|
|
namespace BinaryReflector {
|
2018-06-23 15:30:51 +02:00
|
|
|
|
2021-07-04 22:17:57 +02:00
|
|
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> BinaryVersion readCustomType(BinaryDeserializer &deserializer, Type &customType)
|
2018-06-23 15:30:51 +02:00
|
|
|
{
|
2018-06-26 00:10:44 +02:00
|
|
|
boost::hana::for_each(
|
|
|
|
boost::hana::keys(customType), [&deserializer, &customType](auto key) { deserializer.read(boost::hana::at_key(customType, key)); });
|
2021-07-04 22:17:57 +02:00
|
|
|
return 0;
|
2018-06-23 15:30:51 +02:00
|
|
|
}
|
|
|
|
|
2021-06-06 19:24:40 +02:00
|
|
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> *>
|
|
|
|
void writeCustomType(BinarySerializer &serializer, const Type &customType, BinaryVersion version)
|
2018-06-23 15:30:51 +02:00
|
|
|
{
|
2021-07-04 22:17:57 +02:00
|
|
|
CPP_UTILITIES_UNUSED(version)
|
2018-06-26 00:10:44 +02:00
|
|
|
boost::hana::for_each(
|
|
|
|
boost::hana::keys(customType), [&serializer, &customType](auto key) { serializer.write(boost::hana::at_key(customType, key)); });
|
2018-06-23 15:30:51 +02:00
|
|
|
}
|
2018-06-23 14:35:43 +02:00
|
|
|
|
2018-06-26 00:10:44 +02:00
|
|
|
} // namespace BinaryReflector
|
2018-06-23 15:30:51 +02:00
|
|
|
} // namespace ReflectiveRapidJSON
|
2018-06-23 14:35:43 +02:00
|
|
|
|
|
|
|
#endif // REFLECTIVE_RAPIDJSON_BINARY_REFLECTOR_BOOST_HANA_H
|