void json2tvalue(QVariant & output, const rapidjson::Value & input, int itype) { if(input.IsNull()) { output.clear(); } else if(input.IsInt64()) { output = QVariant(input.GetInt64()); } else if(input.IsInt()) { output = QVariant(input.GetInt()); } else if(input.IsDouble()) { output = QVariant(input.GetDouble()); } else if(input.IsBool()) { output = QVariant(input.GetBool()); } else if(input.IsString()) { output = QVariant(QString(input.GetString())); } else if(input.IsArray()) { switch(itype) { case QVariant::Point: { assert(input.Size() == 2); output = QPoint(input[0u].GetDouble(), input[1].GetDouble()); break; } case QVariant::PointF: { assert(input.Size() == 2); output = QPointF(input[0u].GetDouble(), input[1].GetDouble()); break; } case QVariant::Size: { assert(input.Size() == 2); output = QSize(input[0u].GetDouble(), input[1].GetDouble()); break; } case QVariant::SizeF: { assert(input.Size() == 2); output = QSizeF(input[0u].GetDouble(), input[1].GetDouble()); break; } case QVariant::Rect: { assert(input.Size() == 4); output = QRect(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble()); break; } case QVariant::RectF: { assert(input.Size() == 4); output = QRectF(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble()); break; } case QVariant::Vector2D: { assert(input.Size() == 2); output = QVector2D(input[0u].GetDouble(), input[1].GetDouble()); break; } case QVariant::Vector3D: { assert(input.Size() == 3); output = QVector3D(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble()); break; } case QVariant::Vector4D: { assert(input.Size() == 4); output = QVector4D(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble()); break; } case QVariant::Color: { assert(input.Size() == 4); output = QColor(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble()); break; } case QVariant::StringList: { QStringList list; list.reserve(input.Size()); for(rapidjson::Value::ConstValueIterator it = input.Begin(); it != input.End(); ++it) { QString tmp(it->GetString()); list.append(tmp); } output = list; break; } case QVariant::List: default: { QList<QVariant> list; list.reserve(input.Size()); for(rapidjson::SizeType i = 0; i < input.Size(); ++i) { QVariant tmp; json2tvalue(tmp, input[i], QVariant::Invalid); list.append(tmp); } output = list; break; } } } else if(input.IsObject()) { QMap<QString, QVariant> map; for(rapidjson::Value::ConstMemberIterator it= input.MemberBegin(); it != input.MemberEnd(); ++it) { QString qstring(QLatin1String(it->name.GetString(), it->name.GetStringLength())); QVariant qvalue; json2tvalue(qvalue, it->value, QVariant::Invalid); map.insert(qstring, qvalue); } output = map; } else { output.clear(); assert(false && "shouldn't execute to here."); } }
std::shared_ptr<VolumeIntegrator> VolumeIntegrator::Load(const rapidjson::Value& value) { std::shared_ptr<VolumeIntegrator> integrator; std::string type; if (value.IsString()) { type = value.GetString(); } else if (value.IsObject() && value.HasMember("type")) { type = value["type"].GetString(); } else { std::cerr << "VolumeIntegrator error: no type given" << std::endl; return integrator; } std::transform(type.begin(), type.end(), type.begin(), ::tolower); if (type == "singlescattering") { integrator = SingleScatteringIntegrator::Load(value); } else { std::cerr << "VolumeIntegrator error: unknown type \"" << type << "\"" << std::endl; return integrator; } return integrator; }
bool UITextFieldLoader::setProperty(cocos2d::Node *p, const std::string & name, const rapidjson::Value & value, rapidjson::Value & properties) { uilib::TextField *text = dynamic_cast<uilib::TextField*>(p); CCAssert(text, "UITextFieldLoader::setProperty"); if(name == "placeholderText") { if(value.IsString()) { text->setPlaceholderText(value.GetString()); } } else if(name == "placeholderColor") { cocos2d::Color3B cr; if(helper::parseValue(value, cr)) { text->setPlaceholderColor(cr); } } else { return base_class::setProperty(p, name, value, properties); } return true; }
bool MultitypeVar::readFromValue(const rapidjson::Value& obj) { if (obj.IsNull()) { mType = MultitypeNull; } else if (obj.IsBool()) { mType = MultitypeBool; mBool = obj.GetBool(); } else if (obj.IsNumber()) { mType = MultitypeNumber; mNumber = obj.GetDouble(); } else if (obj.IsString()) { mType = MultitypeNumber; mString = obj.GetString(); } else { mType = MultitypeNull; return false; } return true; }
bool fromJson(const rapidjson::Value &v, std::string &dst) { if (v.IsString()) { dst = std::move(std::string(v.GetString())); return true; } return false; }
VertexIdx InputUtils::impl::VA::getVertexIdxFromValue( const rapidjson::Value& vertexIdx) { if (vertexIdx.IsString()) { return (VertexIdx) std::atoll(vertexIdx.GetString()); } else { return vertexIdx.GetDouble(); } }
EdgeCost InputUtils::impl::VA::getEdgeCostFromValue( const rapidjson::Value& edgeCost) { if (edgeCost.IsString()) { return std::atoll(edgeCost.GetString()); } else { return edgeCost.GetDouble(); } }
void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) { ASSERT_TRUE(value.IsString()); auto string = std::string { value.GetString(),value.GetStringLength() }; if (string.compare(0, 8, "local://") == 0) { string.replace(0, 8, "http://127.0.0.1:2900/"); value.SetString(string.data(), string.size(), allocator); } }
bool CScriptBuilder::Do(ISceneImpl* const& rpScene, const rapidjson::Value& roConfig, script::ISubstance* const& rpSubstance) const { if (NULL == rpSubstance) return false; assert(roConfig.IsString()); rpSubstance->Compile(roConfig.GetString()); return true; }
bool UIFrameViewLoader::setProperty(cocos2d::Node *p, const std::string & name, const rapidjson::Value & value, rapidjson::Value & properties) { uilib::FrameView *image = dynamic_cast<uilib::FrameView*>(p); CCAssert(image, "UIFrameViewLoader::setProperty"); if (name == "image") { if(value.IsString()) { image->setImage(value.GetString()); } } else if(name == "customSizeEnable") { if(value.IsBool()) { image->setCustomSizeEnable(value.GetBool()); } } else if(name == "capInsets") { cocos2d::Rect rc; if(helper::parseValue(value, rc)) { image->setCapInsets(rc); } } else if(name == "color") { cocos2d::Color3B cr; if(helper::parseValue(value, cr)) { image->setColor(cr); } } else if(name == "opacity") { if(value.IsInt()) { image->setOpacity(value.GetInt()); } } else { return base_class::setProperty(p, name, value, properties); } return true; }
void Json_Parser::read_print_for_array(rapidjson::Value &va,int i){ if (va.IsBool()) { const bool flag=va.GetBool(); CCLOG("%d:%d",i,flag); } else if (va.IsDouble()) { const double flag=va.GetDouble(); CCLOG("%d:%f",i,flag); } else if (va.IsInt()) { const int flag=va.GetInt(); CCLOG("%d:%d",i,flag); } else if (va.IsString()) { const std::string flag=va.GetString(); CCLOG("%d:%s",i,flag.c_str()); } else if (va.IsNull()) { CCLOG("%d:null",i); } else if(va.IsObject()) { CCLOG("obj----------%d",i); auto it=va.MemberBegin(); for (;it!=va.MemberEnd();it++) { if (va.HasMember(it->name)) { read_print(va,it->name.GetString()); } } } else if(va.IsArray()) { CCLOG("array-------%d",i); for (int i=0; i<va.Size();i++) { read_print_for_array(va[i],i); } } }
void Json_Parser::read_to_map_for_array(cocos2d::ValueVector &temp,rapidjson::Value &va,int i){ CCLOG("dex:%d",i); if (va.IsBool()) { const bool flag=va.GetBool(); temp.push_back(Value(flag)); } else if (va.IsDouble()) { const double flag=va.GetDouble(); temp.push_back(Value(flag)); } else if (va.IsInt()) { const int flag=va.GetInt(); temp.push_back(Value(flag)); } else if (va.IsString()) { const std::string flag=va.GetString(); temp.push_back(Value(flag)); // CCLOG("++:%d",temp.size()); } else if (va.IsNull()) { temp.push_back(Value(nullptr)); } else if(va.IsObject()) { cocos2d::ValueMap temp2; auto it=va.MemberBegin(); for (;it!=va.MemberEnd();it++) { if (va.HasMember(it->name)) { read_to_map(temp2,va,it->name.GetString()); } } temp.push_back(Value(temp2)); // CCLOG("mapinvectro层:%lu",temp2.size()); } else if(va.IsArray()) { cocos2d::ValueVector temp2; for (int i=0; i<va.Size();i++) { read_to_map_for_array(temp2,va[i],i); } temp.push_back(Value(temp2)); // CCLOG("vectorinvectro层:%lu",temp.size()); } }
//----------------------------------------------------------------------------------- ResourceAccess::ResourceAccess HlmsJsonCompute::parseAccess( const rapidjson::Value &json ) { uint8 access = 0; if( json.IsArray() ) { for( rapidjson::SizeType i=0; i<json.Size(); ++i ) { if( json[i].IsString() ) access |= parseAccess( json[i].GetString() ); } } else if( json.IsString() ) { access = parseAccess( json.GetString() ); } return static_cast<ResourceAccess::ResourceAccess>( access ); }
std::string get_value(const rapidjson::Value& root, const char* key) { if (key != nullptr) { if (root.HasMember(key) && root[key].IsString()) { return root[key].GetString(); } else throw std::system_error(std::error_code(), "Parse error."); } else { if (root.IsString()) return root.GetString(); else throw std::system_error(std::error_code(), "Parse error."); } }
std::string SettingRegistry::toString(const rapidjson::Value& dflt, std::string setting_name) { if (dflt.IsString()) { return dflt.GetString(); } else if (dflt.IsTrue()) { return "true"; } else if (dflt.IsFalse()) { return "false"; } else if (dflt.IsNumber()) { std::ostringstream ss; ss << dflt.GetDouble(); return ss.str(); } else if (dflt.IsArray()) { std::stringstream ss; ss << "["; bool first = true; for (auto it = dflt.Begin(); it != dflt.End(); ++it) { if (!first) { ss << ","; } ss << toString(*it); first = false; } ss << "]"; return ss.str(); } else { logError("Unrecognized data type in JSON: %s has type %s\n", setting_name.c_str(), toString(dflt.GetType()).c_str()); return ""; } }
int JsonValidator::getType(rapidjson::Value& jsonValue) { if (jsonValue.IsNull()) { return kJsonTypeNull; } else if (jsonValue.IsBool()) { return kJsonTypeBoolean; } else if (jsonValue.IsObject()) { return kJsonTypeObject; } else if (jsonValue.IsArray()) { return kJsonTypeArray; } else if (jsonValue.IsString()) { return kJsonTypeString; } else if (jsonValue.IsInt() || jsonValue.IsInt64() || jsonValue.IsUint() || jsonValue.IsUint64()) { return kJsonTypeInteger; } else if (jsonValue.IsDouble()) { return kJsonTypeDouble; } else { return kJsonTypeUnknown; } }
bool MetaDataValue::set_value(const rapidjson::Value& v) { if( v.IsDouble()) { _vPtr = new double(v.GetDouble()); } else if(v.IsBool()) { _vPtr = new bool(v.GetBool()); } else if(v.IsInt()) { _vPtr = new int(v.GetInt()); } else if(v.IsString()) { _vPtr = new std::string(v.GetString()); } else return false; return true; }
static void parseValue(SettingValue &value, const rapidjson::Value &json_val) { if (json_val.IsInt()) value = json_val.GetInt(); else if (json_val.IsString()) value = std::string(json_val.GetString(), json_val.GetStringLength()); else if (json_val.IsBool()) value = json_val.GetBool(); else if (json_val.IsArray()) { SettingList value_list; for (auto it = json_val.Begin(); it != json_val.End(); ++it) { SettingValue child_val; parseValue(child_val, *it); value_list.push_back(child_val); } value = value_list; } else if (json_val.IsObject()) { SettingMap value_map; for (auto it = json_val.MemberBegin(); it != json_val.MemberEnd(); ++it) { SettingValue child_val; parseValue(child_val, it->value); value_map[it->name.GetString()] = child_val; } value = value_map; } else throw std::runtime_error("Unexpected JSON value type."); }
bool clone_value(rapidjson::Value & output, const rapidjson::Value & input, rapidjson::Value::AllocatorType & allocator) { if(&output == &input) { return false; } if(input.IsNull()) { output.SetNull(); } else if(input.IsInt64()) { output.SetInt(input.GetInt64()); } else if(input.IsInt()) { output.SetInt(input.GetInt()); } else if(input.IsDouble()) { output.SetDouble(input.GetDouble()); } else if(input.IsBool()) { output.SetBool(input.GetBool()); } else if(input.IsString()) { output.SetString(input.GetString(), input.GetStringLength(), allocator); } else if(input.IsArray()) { rapidjson::Value temp; output.SetArray(); output.Reserve(input.Size(), allocator); for(rapidjson::SizeType i = 0; i < input.Size(); ++i) { clone_value(temp, input[i], allocator); output.PushBack(temp, allocator); } } else if(input.IsObject()) { output.SetObject(); rapidjson::Value key, val; for(rapidjson::Value::ConstMemberIterator it = input.MemberBegin(); it != input.MemberEnd(); ++it) { clone_value(key, it->name, allocator); clone_value(val, it->value, allocator); output.AddMember(key, val, allocator); } } else { assert(false && "shuldn't execute to here."); return false; } return true; }
inline error_code unmarshall_json(const rapidjson::Value &doc, std::string& val) { TEST_PARAM(doc.IsString()); val = doc.GetString(); return ERR_OK; }