Reflection for RapidJSON  0.0.15
Reflection for serializing/deserializing with RapidJSON
traits.h
Go to the documentation of this file.
1 #ifndef REFLECTIVE_RAPIDJSON_TRAITS
2 #define REFLECTIVE_RAPIDJSON_TRAITS
3 
4 #include <c++utilities/misc/traits.h>
5 
6 #include <map>
7 #include <set>
8 #include <string>
9 #include <unordered_map>
10 #include <unordered_set>
11 #include <variant>
12 
14 
15 namespace Traits = ::CppUtilities::Traits;
16 
17 // define structs and macros to allow treating custom data types as std::map, std::set, ...
19 template <typename T> struct TreatAsMapOrHash : public Traits::Bool<false> {
20 };
22 template <typename T> struct TreatAsMultiMapOrHash : public Traits::Bool<false> {
23 };
25 template <typename T> struct TreatAsSet : public Traits::Bool<false> {
26 };
28 template <typename T> struct TreatAsMultiSet : public Traits::Bool<false> {
29 };
30 
31 #define REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH(T) \
32  template <> struct TreatAsMapOrHash<T> : public Traits::Bool<true> { \
33  }
34 #define REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH(T) \
35  template <> struct TreatAsMultiMapOrHash<T> : public Traits::Bool<true> { \
36  }
37 #define REFLECTIVE_RAPIDJSON_TREAT_AS_SET(T) \
38  template <> struct TreatAsSet<T> : public Traits::Bool<true> { \
39  }
40 #define REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET(T) \
41  template <> struct TreatAsMultiSet<T> : public Traits::Bool<true> { \
42  }
43 
44 // define traits to check for arrays, sets and maps
45 template <typename Type>
47  = Traits::Any<Traits::IsSpecializationOf<Type, std::map>, Traits::IsSpecializationOf<Type, std::unordered_map>, TreatAsMapOrHash<Type>>;
48 template <typename Type>
49 using IsMultiMapOrHash = Traits::Any<Traits::IsSpecializationOf<Type, std::multimap>, Traits::IsSpecializationOf<Type, std::unordered_multimap>,
51 template <typename Type>
52 using IsSet = Traits::Any<Traits::IsSpecializationOf<Type, std::set>, Traits::IsSpecializationOf<Type, std::unordered_set>, TreatAsSet<Type>>;
53 template <typename Type>
55  = Traits::Any<Traits::IsSpecializationOf<Type, std::multiset>, Traits::IsSpecializationOf<Type, std::unordered_multiset>, TreatAsMultiSet<Type>>;
56 template <typename Type>
57 using IsArrayOrSet = Traits::Any<
58  Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>,
59  Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string_view>>, Traits::Not<IsMapOrHash<Type>>, Traits::Not<IsMultiMapOrHash<Type>>>,
61 template <typename Type>
62 using IsArray = Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>,
63  Traits::Not<IsMapOrHash<Type>>, Traits::Not<IsMultiMapOrHash<Type>>, Traits::Not<IsSet<Type>>, Traits::Not<IsMultiSet<Type>>>;
64 template <typename Type>
65 using IsIteratableExceptString = Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>,
66  Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>>;
67 template <typename Type> using IsVariant = Traits::All<Traits::IsSpecializationOf<Type, std::variant>>;
68 
69 } // namespace ReflectiveRapidJSON
70 
71 #endif // REFLECTIVE_RAPIDJSON_TRAITS
ReflectiveRapidJSON::TreatAsMultiMapOrHash
The TreatAsMultiMapOrHash class allows treating custom classes as std::multimap or std::unordered_mul...
Definition: traits.h:22
ReflectiveRapidJSON::IsMapOrHash
Traits::Any< Traits::IsSpecializationOf< Type, std::map >, Traits::IsSpecializationOf< Type, std::unordered_map >, TreatAsMapOrHash< Type > > IsMapOrHash
Definition: traits.h:47
ReflectiveRapidJSON::IsSet
Traits::Any< Traits::IsSpecializationOf< Type, std::set >, Traits::IsSpecializationOf< Type, std::unordered_set >, TreatAsSet< Type > > IsSet
Definition: traits.h:52
ReflectiveRapidJSON
Definition: traits.h:13
ReflectiveRapidJSON::IsMultiMapOrHash
Traits::Any< Traits::IsSpecializationOf< Type, std::multimap >, Traits::IsSpecializationOf< Type, std::unordered_multimap >, TreatAsMultiMapOrHash< Type > > IsMultiMapOrHash
Definition: traits.h:50
ReflectiveRapidJSON::IsMultiSet
Traits::Any< Traits::IsSpecializationOf< Type, std::multiset >, Traits::IsSpecializationOf< Type, std::unordered_multiset >, TreatAsMultiSet< Type > > IsMultiSet
Definition: traits.h:55
ReflectiveRapidJSON::TreatAsSet
The TreatAsSet class allows treating custom classes as std::set or std::unordered_set.
Definition: traits.h:25
ReflectiveRapidJSON::IsVariant
Traits::All< Traits::IsSpecializationOf< Type, std::variant > > IsVariant
Definition: traits.h:67
ReflectiveRapidJSON::TreatAsMultiSet
The TreatAsMultiSet class allows treating custom classes as std::multiset or std::unordered_multiset.
Definition: traits.h:28
ReflectiveRapidJSON::IsArray
Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< IsMapOrHash< Type > >, Traits::Not< IsMultiMapOrHash< Type > >, Traits::Not< IsSet< Type > >, Traits::Not< IsMultiSet< Type > >> IsArray
Definition: traits.h:63
ReflectiveRapidJSON::IsIteratableExceptString
Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >> IsIteratableExceptString
Definition: traits.h:66
ReflectiveRapidJSON::TreatAsMapOrHash
The TreatAsMapOrHash class allows treating custom classes as std::map or std::unordered_map.
Definition: traits.h:19
ReflectiveRapidJSON::IsArrayOrSet
Traits::Any< Traits::All< Traits::IsIteratable< Type >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string > >, Traits::Not< Traits::IsSpecializationOf< Type, std::basic_string_view > >, Traits::Not< IsMapOrHash< Type > >, Traits::Not< IsMultiMapOrHash< Type > >>, TreatAsSet< Type >, TreatAsMultiSet< Type > > IsArrayOrSet
Definition: traits.h:60