Reflection for RapidJSON  0.0.15
Reflection for serializing/deserializing with RapidJSON
serializable.h
Go to the documentation of this file.
1 #ifndef REFLECTIVE_RAPIDJSON_BINARY_SERIALIZABLE_H
2 #define REFLECTIVE_RAPIDJSON_BINARY_SERIALIZABLE_H
3 
10 #include "./reflector.h"
11 
12 #include <iosfwd>
13 #include <string>
14 
15 namespace ReflectiveRapidJSON {
16 
20 template <typename Type> struct BinarySerializable {
21  void toBinary(std::ostream &outputStream) const;
22  void restoreFromBinary(std::istream &inputStream);
23  static Type fromBinary(std::istream &inputStream);
24 
25  static constexpr const char *qualifiedName = "ReflectiveRapidJSON::BinarySerializable";
26 };
27 
28 template <typename Type> inline void BinarySerializable<Type>::toBinary(std::ostream &outputStream) const
29 {
30  BinaryReflector::BinarySerializer(&outputStream).write(static_cast<const Type &>(*this));
31 }
32 
33 template <typename Type> inline void BinarySerializable<Type>::restoreFromBinary(std::istream &inputStream)
34 {
35  BinaryReflector::BinaryDeserializer(&inputStream).read(static_cast<Type &>(*this));
36 }
37 
38 template <typename Type> Type BinarySerializable<Type>::fromBinary(std::istream &inputStream)
39 {
40  Type object;
41  static_cast<BinarySerializable<Type> &>(object).restoreFromBinary(inputStream);
42  return object;
43 }
44 
52 #define REFLECTIVE_RAPIDJSON_MAKE_BINARY_SERIALIZABLE(T) \
53  template <> struct ReflectiveRapidJSON::AdaptedBinarySerializable<T> : Traits::Bool<true> { \
54  }
55 
56 } // namespace ReflectiveRapidJSON
57 
58 #endif // REFLECTIVE_RAPIDJSON_BINARY_SERIALIZABLE_H
reflector.h
Contains BinaryReader and BinaryWriter supporting binary (de)serialization of primitive and custom ty...
ReflectiveRapidJSON::BinaryReflector::BinarySerializer
Definition: reflector.h:80
ReflectiveRapidJSON::BinaryReflector::BinarySerializer::write
void write(const Type &pair)
Definition: reflector.h:220
ReflectiveRapidJSON::BinaryReflector::BinaryDeserializer::read
void read(Type &pair)
Definition: reflector.h:104
ReflectiveRapidJSON
Definition: traits.h:13
ReflectiveRapidJSON::BinarySerializable::restoreFromBinary
void restoreFromBinary(std::istream &inputStream)
Definition: serializable.h:33
ReflectiveRapidJSON::BinarySerializable::qualifiedName
static constexpr const char * qualifiedName
Definition: serializable.h:25
ReflectiveRapidJSON::BinarySerializable
The BinarySerializable class provides the CRTP-base for (de)serializable objects.
Definition: reflector.h:36
ReflectiveRapidJSON::BinaryReflector::BinaryDeserializer
Definition: reflector.h:56
ReflectiveRapidJSON::BinarySerializable::toBinary
void toBinary(std::ostream &outputStream) const
Definition: serializable.h:28
ReflectiveRapidJSON::BinarySerializable::fromBinary
static Type fromBinary(std::istream &inputStream)
Definition: serializable.h:38