5 #include <rapidjson/document.h> 6 #include <pajlada/serialize.hpp> 14 void addMember(rapidjson::Value &obj,
const char *key,
15 rapidjson::Value &&value,
16 rapidjson::Document::AllocatorType &a);
17 void addMember(rapidjson::Value &obj,
const char *key,
18 rapidjson::Value &value,
19 rapidjson::Document::AllocatorType &a);
21 template <
typename Type>
22 void set(rapidjson::Value &obj,
const char *key,
const Type &value,
23 rapidjson::Document::AllocatorType &a)
25 assert(obj.IsObject());
27 addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
31 inline void set(rapidjson::Value &obj,
const char *key,
32 const rapidjson::Value &value,
33 rapidjson::Document::AllocatorType &a)
35 assert(obj.IsObject());
37 addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
40 template <
typename Type>
41 void set(rapidjson::Document &obj,
const char *key,
const Type &value)
43 assert(obj.IsObject());
45 auto &a = obj.GetAllocator();
47 addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
51 inline void set(rapidjson::Document &obj,
const char *key,
52 const rapidjson::Value &value)
54 assert(obj.IsObject());
56 auto &a = obj.GetAllocator();
58 addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
61 template <
typename Type>
62 void add(rapidjson::Value &arr,
const Type &value,
63 rapidjson::Document::AllocatorType &a)
65 assert(arr.IsArray());
67 arr.PushBack(pajlada::Serialize<Type>::get(value, a), a);
72 template <
typename Type>
73 bool getSafe(
const rapidjson::Value &obj,
const char *key, Type &out)
81 out = pajlada::Deserialize<Type>::get(obj[key], &error);
86 template <
typename Type>
87 bool getSafe(
const rapidjson::Value &value, Type &out)
90 out = pajlada::Deserialize<Type>::get(value, &error);
96 rapidjson::Value &out);
98 QString
stringify(
const rapidjson::Value &value);
bool checkJsonValue(const rapidjson::Value &obj, const char *key)
Definition: RapidjsonHelpers.cpp:43
void add(rapidjson::Value &arr, const Type &value, rapidjson::Document::AllocatorType &a)
Definition: RapidjsonHelpers.hpp:62
Definition: Application.cpp:48
bool getSafeObject(rapidjson::Value &obj, const char *key, rapidjson::Value &out)
Definition: RapidjsonHelpers.cpp:31
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value, rapidjson::Document::AllocatorType &a)
Definition: RapidjsonHelpers.cpp:8
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
Definition: RapidjsonHelpers.hpp:73
QString stringify(const rapidjson::Value &value)
Definition: RapidjsonHelpers.cpp:22