Reflection for RapidJSON 0.0.16
Reflection for serializing/deserializing with RapidJSON
Loading...
Searching...
No Matches
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
15namespace Traits = ::CppUtilities::Traits;
16
17// define structs and macros to allow treating custom data types as std::map, std::set, ...
19template <typename T> struct TreatAsMapOrHash : public Traits::Bool<false> {};
21template <typename T> struct TreatAsMultiMapOrHash : public Traits::Bool<false> {};
23template <typename T> struct TreatAsSet : public Traits::Bool<false> {};
25template <typename T> struct TreatAsMultiSet : public Traits::Bool<false> {};
26
27#define REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH(T) \
28 template <> struct TreatAsMapOrHash<T> : public Traits::Bool<true> {}
29#define REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH(T) \
30 template <> struct TreatAsMultiMapOrHash<T> : public Traits::Bool<true> {}
31#define REFLECTIVE_RAPIDJSON_TREAT_AS_SET(T) \
32 template <> struct TreatAsSet<T> : public Traits::Bool<true> {}
33#define REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET(T) \
34 template <> struct TreatAsMultiSet<T> : public Traits::Bool<true> {}
35
36// define traits to check for arrays, sets and maps
37template <typename Type>
39 = Traits::Any<Traits::IsSpecializationOf<Type, std::map>, Traits::IsSpecializationOf<Type, std::unordered_map>, TreatAsMapOrHash<Type>>;
40template <typename Type>
41using IsMultiMapOrHash = Traits::Any<Traits::IsSpecializationOf<Type, std::multimap>, Traits::IsSpecializationOf<Type, std::unordered_multimap>,
43template <typename Type>
44using IsSet = Traits::Any<Traits::IsSpecializationOf<Type, std::set>, Traits::IsSpecializationOf<Type, std::unordered_set>, TreatAsSet<Type>>;
45template <typename Type>
46using IsMultiSet
47 = Traits::Any<Traits::IsSpecializationOf<Type, std::multiset>, Traits::IsSpecializationOf<Type, std::unordered_multiset>, TreatAsMultiSet<Type>>;
48template <typename Type>
49using IsArrayOrSet = Traits::Any<
50 Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>,
51 Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string_view>>, Traits::Not<IsMapOrHash<Type>>, Traits::Not<IsMultiMapOrHash<Type>>>,
53template <typename Type>
54using IsArray = Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>,
55 Traits::Not<IsMapOrHash<Type>>, Traits::Not<IsMultiMapOrHash<Type>>, Traits::Not<IsSet<Type>>, Traits::Not<IsMultiSet<Type>>>;
56template <typename Type>
57using IsIteratableExceptString = Traits::All<Traits::IsIteratable<Type>, Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>,
58 Traits::Not<Traits::IsSpecializationOf<Type, std::basic_string>>>;
59template <typename Type> using IsVariant = Traits::All<Traits::IsSpecializationOf<Type, std::variant>>;
60
61} // namespace ReflectiveRapidJSON
62
63#endif // REFLECTIVE_RAPIDJSON_TRAITS
Traits::All< Traits::IsSpecializationOf< Type, std::variant > > IsVariant
Definition traits.h:57
Traits::Any< Traits::IsSpecializationOf< Type, std::set >, Traits::IsSpecializationOf< Type, std::unordered_set >, TreatAsSet< Type > > IsSet
Definition traits.h:43
Traits::Any< Traits::IsSpecializationOf< Type, std::multiset >, Traits::IsSpecializationOf< Type, std::unordered_multiset >, TreatAsMultiSet< Type > > IsMultiSet
Definition traits.h:45
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:47
Traits::Any< Traits::IsSpecializationOf< Type, std::multimap >, Traits::IsSpecializationOf< Type, std::unordered_multimap >, TreatAsMultiMapOrHash< Type > > IsMultiMapOrHash
Definition traits.h:40
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:55
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:52
Traits::Any< Traits::IsSpecializationOf< Type, std::map >, Traits::IsSpecializationOf< Type, std::unordered_map >, TreatAsMapOrHash< Type > > IsMapOrHash
Definition traits.h:38
The TreatAsMapOrHash class allows treating custom classes as std::map or std::unordered_map.
Definition traits.h:19
The TreatAsMultiMapOrHash class allows treating custom classes as std::multimap or std::unordered_mul...
Definition traits.h:21
The TreatAsMultiSet class allows treating custom classes as std::multiset or std::unordered_multiset.
Definition traits.h:25
The TreatAsSet class allows treating custom classes as std::set or std::unordered_set.
Definition traits.h:23