12 template<
typename JSON>
16 Value::ConstMemberIterator member = json.FindMember(key);
17 if ((member == json.MemberEnd()) || member->value.IsNull())
21 if (!member->value.IsBool())
25 value = member->value.GetBool();
29 template<
typename JSON>
33 Value::ConstMemberIterator member = json.FindMember(key);
34 if ((member == json.MemberEnd()) || member->value.IsNull())
38 if (!member->value.IsInt())
42 value = member->value.GetInt();
46 template<
typename JSON>
50 Value::ConstMemberIterator member = json.FindMember(key);
51 if ((member == json.MemberEnd()) || member->value.IsNull())
55 if (!member->value.IsUint())
59 value = member->value.GetUint();
63 template<
typename JSON>
67 Value::ConstMemberIterator member = json.FindMember(key);
68 if ((member == json.MemberEnd()) || member->value.IsNull())
72 if (!member->value.IsInt64())
76 value = member->value.GetInt64();
80 template<
typename JSON>
84 Value::ConstMemberIterator member = json.FindMember(key);
85 if ((member == json.MemberEnd()) || member->value.IsNull())
89 if (!member->value.IsUint64())
93 value = member->value.GetUint64();
97 template<
typename JSON>
101 Value::ConstMemberIterator member = json.FindMember(key);
102 if ((member == json.MemberEnd()) || member->value.IsNull())
106 if (!member->value.IsDouble())
110 value = member->value.GetDouble();
114 template<
typename JSON>
118 Value::ConstMemberIterator member = json.FindMember(key);
119 if ((member == json.MemberEnd()) || member->value.IsNull())
123 if (!member->value.IsString())
127 size_t length = std::min((
size_t)member->value.GetStringLength(), size);
128 std::memcpy(value, member->value.GetString(), length);
131 value[length] =
'\0';
135 template<
typename JSON>
139 Value::ConstMemberIterator member = json.FindMember(key);
140 if ((member == json.MemberEnd()) || member->value.IsNull())
144 if (!member->value.IsString())
148 value.assign(member->value.GetString(), (
size_t)member->value.GetStringLength());
152 template <
typename JSON, std::
size_t N>
156 Value::ConstMemberIterator member = json.FindMember(key);
157 if ((member == json.MemberEnd()) || member->value.IsNull())
161 if (!member->value.IsString())
165 size_t length = std::min((
size_t)member->value.GetStringLength(), N);
166 std::memcpy(value, member->value.GetString(), length);
169 value[length] =
'\0';
173 template<
typename JSON>
176 return FindArray(json, key, [](
size_t){}, handler);
180 template<
typename JSON>
181 inline bool Deserializer::FindArray(
const JSON& json,
const char* key,
const std::function<
void(
size_t)>& initialize,
const std::function<
void(
const Value&)>& handler)
183 assert((initialize) &&
"JSON initialize array handler must be valid!");
184 assert((handler) &&
"JSON array handler must be valid!");
185 if (!initialize || !handler)
189 Value::ConstMemberIterator member = json.FindMember(key);
190 if ((member == json.MemberEnd()) || member->value.IsNull())
194 if (!member->value.IsArray())
198 initialize(member->value.GetArray().Size());
199 for (
const auto& item : member->value.GetArray())
204 template<
typename JSON>
205 inline bool Deserializer::FindObject(
const JSON& json,
const char* key,
const std::function<
void(
const Value::ConstObject&)>& handler)
207 assert((handler) &&
"JSON array handler must be valid!");
212 Value::ConstMemberIterator member = json.FindMember(key);
213 if ((member == json.MemberEnd()) || member->value.IsNull())
217 if (!member->value.IsObject())
221 handler(member->value.GetObj());
static bool FindArray(const JSON &json, const char *key, const std::function< void(const Value &)> &handler)
Try to get the array key/value pair.
static bool FindObject(const JSON &json, const char *key, const std::function< void(const Value::ConstObject &)> &handler)
Try to get the object key/value pair.
static bool Find(const JSON &json, const char *key, bool &value)
Try to get the boolean key/value pair.
C++ Serialization project definitions.