Reflection for RapidJSON  0.0.15
Reflection for serializing/deserializing with RapidJSON
traits.cpp
Go to the documentation of this file.
1 #include "../traits.h"
2 
3 #include <list>
4 #include <vector>
5 
6 // treat some types differently to test Treat... traits
7 struct Foo {
8 };
9 struct Bar {
10 };
11 namespace ReflectiveRapidJSON {
16 } // namespace ReflectiveRapidJSON
17 
18 using namespace std;
19 using namespace ReflectiveRapidJSON;
20 
21 // test traits
22 static_assert(IsArray<vector<int>>::value, "vector mapped to array");
23 static_assert(IsArray<list<int>>::value, "list mapped to array");
24 static_assert(!IsArray<set<int>>::value, "set not considered an array");
25 static_assert(!IsArray<multiset<int>>::value, "multiset not considered an array");
26 static_assert(IsArrayOrSet<set<int>>::value, "set is array or set");
27 static_assert(IsArrayOrSet<multiset<int>>::value, "multiset is array or set");
28 static_assert(IsArrayOrSet<Foo>::value, "Foo is array or set via TreatAsMultiSet");
29 static_assert(IsArrayOrSet<Bar>::value, "Foo is array or set via TreatAsSet");
30 static_assert(!IsArrayOrSet<string>::value, "string not mapped to array or set though it is iteratable");
31 static_assert(IsSet<set<int>>::value, "set mapped to set");
32 static_assert(IsSet<unordered_set<int>>::value, "unordered_set mapped to set");
33 static_assert(IsSet<Bar>::value, "Bar mapped to set via TreatAsSet");
34 static_assert(!IsSet<string>::value, "string not mapped to set");
35 static_assert(IsMultiSet<unordered_multiset<int>>::value, "multiset");
36 static_assert(IsMultiSet<Foo>::value, "Foo mapped to multiset via TreatAsMultiSet");
37 static_assert(!IsMultiSet<string>::value, "string not mapped to multiset");
38 static_assert(!IsArray<string>::value, "string not mapped to array though it is iteratable");
39 static_assert(IsMapOrHash<map<string, int>>::value, "map mapped to object");
40 static_assert(IsMapOrHash<unordered_map<string, int>>::value, "hash mapped to object");
41 static_assert(!IsMapOrHash<vector<int>>::value, "vector not mapped to object");
42 static_assert(IsMapOrHash<Foo>::value, "Foo mapped to object via TreatAsMapOrHash");
43 static_assert(IsMultiMapOrHash<multimap<string, int>>::value, "multimap mapped to object");
44 static_assert(IsMultiMapOrHash<unordered_multimap<string, int>>::value, "unordered multimap mapped to object");
45 static_assert(!IsMultiMapOrHash<vector<int>>::value, "vector not mapped to object");
46 static_assert(IsMultiMapOrHash<Foo>::value, "Foo mapped to object via TreatAsMultiMapOrHash");
47 static_assert(IsIteratableExceptString<std::vector<int>>::value, "vector is iteratable");
48 static_assert(!IsIteratableExceptString<std::string>::value, "string not iteratable");
49 static_assert(!IsIteratableExceptString<std::wstring>::value, "wstring not iteratable");
50 static_assert(!IsIteratableExceptString<const std::string>::value, "string not iteratable");
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::REFLECTIVE_RAPIDJSON_TREAT_AS_SET
REFLECTIVE_RAPIDJSON_TREAT_AS_SET(Bar)
ReflectiveRapidJSON
Definition: traits.h:13
Foo
Definition: traits.cpp:7
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
Bar
Definition: traits.cpp:9
ReflectiveRapidJSON::REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH
REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_MAP_OR_HASH(Foo)
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::REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH
REFLECTIVE_RAPIDJSON_TREAT_AS_MAP_OR_HASH(Foo)
ReflectiveRapidJSON::REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET
REFLECTIVE_RAPIDJSON_TREAT_AS_MULTI_SET(Foo)
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