JSON JSON::operator[] (const std::string & name) const { Pos pos = searchField(name); if (!pos) throw JSONException("JSON: there is no element '" + std::string(name) + "' in object."); return JSON(pos, ptr_end, level + 1).getValue(); }
void FieldAstDeserializer::operator ()(float& v, const char* name, u32 name_hash) { const AstField* field = searchField(fields, name, name_hash); if (field == nullptr) return; const AstExpression& number = field->expression; assert(number.type == AstExpression::NUMBER); v = numberAsFloat(*number.number); }
AstFlagSetter<T> FieldAstDeserializer::flags(T& v, const char* name, u32 name_hash) { const AstField* field = searchField(fields, name, name_hash); if (field == nullptr) return AstFlagSetter<T>(nullptr, nullptr); const AstExpression& sequence = field->expression; assert(sequence.type == AstExpression::LIST); return AstFlagSetter<T>(sequence.sequence, &v); }
void FieldAstDeserializer::operator ()(std::string& v, const char* name, u32 name_hash) { const AstField* field = searchField(fields, name, name_hash); if (field == nullptr) return; const AstExpression& str = field->expression; assert(str.type == AstExpression::STRING); v.assign(str.string->begin, str.string->end); }
void FieldAstDeserializer::operator ()(Quaternion& v, const char* name, u32 name_hash) { const AstField* field = searchField(fields, name, name_hash); if (field == nullptr) return; const AstExpression& tuple = field->expression; assert(tuple.type == AstExpression::TUPLE); const AstSequence* e = tuple.sequence; for (size_t i = 0; i < 4; ++i) { assert(e != nullptr); assert(e->type == AstExpression::NUMBER); (i == 3 ? v.w : v.v[i]) = numberAsFloat(*e->number); e = e->next; } assert(e == nullptr); }
void FieldAstDeserializer::operator ()(Handle& v, const char* name, u32 name_hash) { const AstField* field = searchField(fields, name, name_hash); if (field == nullptr) return; const AstExpression& expr = field->expression; if (expr.type == AstExpression::INSTANCE) { v = scene_reader->deserializeObject(*expr.instance); } else if (expr.type == AstExpression::HANDLE_NAME) { const AstHandleName& hname = *expr.handle_name; if (hname.begin == nullptr) { v = Handle(); } else { v = scene_reader->handle_map.at(std::string(hname.begin, hname.end)); } } else { assert(false); } }
bool JSON::has(const char * data, size_t size) const { return nullptr != searchField(data, size); }