void RuntimeJsImpl::onReload(const rapidjson::Document &dArgParse, rapidjson::Document &dReplyParse) { if (dArgParse.HasMember("modulefiles")){ auto& allocator = dReplyParse.GetAllocator(); rapidjson::Value bodyvalue(rapidjson::kObjectType); const rapidjson::Value& objectfiles = dArgParse["modulefiles"]; for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++){ if (!reloadScript(objectfiles[i].GetString())) { bodyvalue.AddMember(rapidjson::Value(objectfiles[i].GetString(), allocator) , rapidjson::Value(1) , allocator); } } if (0 == objectfiles.Size()) { reloadScript(""); } dReplyParse.AddMember("body", bodyvalue, dReplyParse.GetAllocator()); }else { reloadScript(""); } dReplyParse.AddMember("code", 0, dReplyParse.GetAllocator()); }
void TrackBrakeSimple::Create(const rapidjson::Document& d) { // Read top-level data assert(d.HasMember("Type")); assert(d.HasMember("Template")); assert(d.HasMember("Name")); SetName(d["Name"].GetString()); // Read maximum braking torque m_maxtorque = d["Maximum Torque"].GetDouble(); }
void SprocketBand::Create(const rapidjson::Document& d) { // Invoke base class method. ChPart::Create(d); // Read inertia properties m_num_teeth = d["Number Teeth"].GetInt(); m_gear_mass = d["Gear Mass"].GetDouble(); m_gear_inertia = LoadVectorJSON(d["Gear Inertia"]); m_axle_inertia = d["Axle Inertia"].GetDouble(); m_separation = d["Gear Separation"].GetDouble(); // Read profile information assert(d.HasMember("Profile")); m_gear_outer_radius = d["Profile"]["Outer Radius"].GetDouble(); m_gear_base_width = d["Profile"]["Base Width"].GetDouble(); m_gear_tip_width = d["Profile"]["Tip Width"].GetDouble(); m_gear_tooth_depth = d["Profile"]["Tooth Depth"].GetDouble(); m_gear_arc_radius = d["Profile"]["Arc Radius"].GetDouble(); m_gear_guide_wheel_width = d["Profile"]["Guide Wheel Width"].GetDouble(); m_gear_guide_wheel_gap = d["Profile"]["Guide Wheel Gap"].GetDouble(); m_gear_RA = d["Profile"]["Assembly Radius"].GetDouble(); // Read contact material data assert(d.HasMember("Contact Material")); float mu = d["Contact Material"]["Coefficient of Friction"].GetFloat(); float cr = d["Contact Material"]["Coefficient of Restitution"].GetFloat(); SetContactFrictionCoefficient(mu); SetContactRestitutionCoefficient(cr); if (d["Contact Material"].HasMember("Properties")) { float ym = d["Contact Material"]["Properties"]["Young Modulus"].GetFloat(); float pr = d["Contact Material"]["Properties"]["Poisson Ratio"].GetFloat(); SetContactMaterialProperties(ym, pr); } if (d["Contact Material"].HasMember("Coefficients")) { float kn = d["Contact Material"]["Coefficients"]["Normal Stiffness"].GetFloat(); float gn = d["Contact Material"]["Coefficients"]["Normal Damping"].GetFloat(); float kt = d["Contact Material"]["Coefficients"]["Tangential Stiffness"].GetFloat(); float gt = d["Contact Material"]["Coefficients"]["Tangential Damping"].GetFloat(); SetContactMaterialCoefficients(kn, gn, kt, gt); } // Read sprocket visualization if (d.HasMember("Visualization")) { assert(d["Visualization"].HasMember("Mesh Filename")); assert(d["Visualization"].HasMember("Mesh Name")); m_meshFile = d["Visualization"]["Mesh Filename"].GetString(); m_meshName = d["Visualization"]["Mesh Name"].GetString(); m_has_mesh = true; } }
// ----------------------------------------------------------------------------- // Process the specified JSON document and load tire specification // ----------------------------------------------------------------------------- void FEATire::ProcessJSON(const rapidjson::Document& d) { // Read top-level data assert(d.HasMember("Type")); assert(d.HasMember("Template")); assert(d.HasMember("Name")); SetName(d["Name"].GetString()); // Read geometric dimensions m_tire_radius = d["Tire Radius"].GetDouble(); m_rim_radius = d["Rim Radius"].GetDouble(); m_rim_width = d["Rim Width"].GetDouble(); // Read contact material data assert(d.HasMember("Contact Material")); float mu = d["Contact Material"]["Coefficient of Friction"].GetFloat(); float cr = d["Contact Material"]["Coefficient of Restitution"].GetFloat(); SetContactFrictionCoefficient(mu); SetContactRestitutionCoefficient(cr); if (d["Contact Material"].HasMember("Properties")) { float ym = d["Contact Material"]["Properties"]["Young Modulus"].GetFloat(); float pr = d["Contact Material"]["Properties"]["Poisson Ratio"].GetFloat(); SetContactMaterialProperties(ym, pr); } if (d["Contact Material"].HasMember("Coefficients")) { float kn = d["Contact Material"]["Coefficients"]["Normal Stiffness"].GetFloat(); float gn = d["Contact Material"]["Coefficients"]["Normal Damping"].GetFloat(); float kt = d["Contact Material"]["Coefficients"]["Tangential Stiffness"].GetFloat(); float gt = d["Contact Material"]["Coefficients"]["Tangential Damping"].GetFloat(); SetContactMaterialCoefficients(kn, gn, kt, gt); } // Read continuum material data double E = d["Continuum Material"]["Elasticity Modulus"].GetDouble(); double nu = d["Continuum Material"]["Poisson Ratio"].GetDouble(); double rd = d["Continuum Material"]["Rayleigh Damping"].GetDouble(); double density = d["Continuum Material"]["Density"].GetDouble(); m_material = std::make_shared<ChContinuumElastic>(); m_material->Set_E(E); m_material->Set_v(nu); m_material->Set_RayleighDampingK(rd); m_material->Set_density(density); // Default tire pressure m_default_pressure = d["Default Pressure"].GetDouble(); // Name of Abaqus input file m_input_file = d["Abaqus Mesh Filename"].GetString(); }
void handle_method_token_auth(per_session_data_eqemu *session, rapidjson::Document &document, std::string &method) { CheckParams(1, "[token]"); if(!document.HasMember("params") || document.HasMember("params") && document["params"].Empty() && !document["params"].IsString()) return; session->auth = document["params"][(rapidjson::SizeType)0].GetString(); if (!CheckTokenAuthorization(session)) { WriteWebCallResponseBoolean(session, document, false, false); } else { WriteWebCallResponseBoolean(session, document, true, false); } }
void Manifest::loadVersion(const rapidjson::Document &json) { // Retrieve remote manifest url if ( json.HasMember(KEY_MANIFEST_URL) && json[KEY_MANIFEST_URL].IsString() ) { _remoteManifestUrl = json[KEY_MANIFEST_URL].GetString(); } // Retrieve remote version url if ( json.HasMember(KEY_VERSION_URL) && json[KEY_VERSION_URL].IsString() ) { _remoteVersionUrl = json[KEY_VERSION_URL].GetString(); } // Retrieve local version if ( json.HasMember(KEY_VERSION) && json[KEY_VERSION].IsString() ) { _version = json[KEY_VERSION].GetString(); } // Retrieve local group version if ( json.HasMember(KEY_GROUP_VERSIONS) ) { const rapidjson::Value& groupVers = json[KEY_GROUP_VERSIONS]; if (groupVers.IsObject()) { for (rapidjson::Value::ConstMemberIterator itr = groupVers.MemberBegin(); itr != groupVers.MemberEnd(); ++itr) { std::string group = itr->name.GetString(); std::string version = "0"; if (itr->value.IsString()) { version = itr->value.GetString(); } _groups.push_back(group); _groupVer.emplace(group, version); } } } // Retrieve local engine version if ( json.HasMember(KEY_ENGINE_VERSION) && json[KEY_ENGINE_VERSION].IsString() ) { _engineVer = json[KEY_ENGINE_VERSION].GetString(); } _versionLoaded = true; }
int SettingRegistry::loadJSONsettingsFromDoc(rapidjson::Document& json_document, SettingsBase* settings_base, bool warn_duplicates) { if (!json_document.IsObject()) { cura::logError("JSON file is not an object.\n"); return 3; } { // handle machine name std::string machine_name = "Unknown"; if (json_document.HasMember("name")) { const rapidjson::Value& machine_name_field = json_document["name"]; if (machine_name_field.IsString()) { machine_name = machine_name_field.GetString(); } } SettingConfig& machine_name_setting = addSetting("machine_name", "Machine Name"); machine_name_setting.setDefault(machine_name); machine_name_setting.setType("string"); } if (json_document.HasMember("settings")) { std::list<std::string> path; handleChildren(json_document["settings"], path, settings_base, warn_duplicates); } if (json_document.HasMember("overrides")) { const rapidjson::Value& json_object_container = json_document["overrides"]; for (rapidjson::Value::ConstMemberIterator override_iterator = json_object_container.MemberBegin(); override_iterator != json_object_container.MemberEnd(); ++override_iterator) { std::string setting = override_iterator->name.GetString(); SettingConfig* conf = getSettingConfig(setting); if (!conf) //Setting could not be found. { logWarning("Trying to override unknown setting %s.\n", setting.c_str()); continue; } _loadSettingValues(conf, override_iterator, settings_base); } } return 0; }
ValueMap Json_Parser::read_to_map(rapidjson::Document &doc,const char*keyname){ rapidjson::Value va; ValueMap jmap; if (doc.HasMember(keyname)) { va=doc[keyname]; if (va.IsBool()) { const bool flag=va.GetBool(); jmap[keyname]=flag; } else if (va.IsDouble()) { const double flag=va.GetDouble(); jmap[keyname]=flag; } else if (va.IsInt()) { const int flag=va.GetInt(); jmap[keyname]=flag; } else if (va.IsString()) { const std::string flag=va.GetString(); jmap[keyname]=Value(flag); } else if (va.IsNull()) { jmap[keyname]=nullptr; } else if(va.IsObject()) { cocos2d::ValueMap temp; auto it=va.MemberBegin(); for (;it!=va.MemberEnd();it++) { if (va.HasMember(it->name)) { read_to_map(temp,va,it->name.GetString()); } } jmap[keyname]=Value(temp); // CCLOG("map1层:%lu",temp.size()); } else if(va.IsArray()) { cocos2d::ValueVector temp; for (int i=0; i<va.Size();i++) { read_to_map_for_array(temp,va[i],i); } CCLOG("==%s,size:%lu",keyname,temp.size()); // CCLOG("ttt:%lu",ttt.size()); CCLOG("jma:%lu",jmap.size()); jmap[keyname]=Value(temp); //ttt[keyname]=Value(temp); CCLOG("=="); // CCLOG("vector1层:%lu",temp.size()); } } return jmap; }
void FCServer::jsonDeviceMessage(rapidjson::Document &message) { /* * If this message has a "device" member and doesn't match any server-global * message types, give each matching device a chance to handle it. */ const Value &device = message["device"]; bool matched = false; if (device.IsObject()) { for (unsigned i = 0; i != mUSBDevices.size(); i++) { USBDevice *usbDev = mUSBDevices[i]; if (usbDev->matchConfiguration(device)) { matched = true; usbDev->writeMessage(message); if (message.HasMember("error")) break; } } } if (!matched) { message.AddMember("error", "No matching device found", message.GetAllocator()); } }
void WriteWebCallResponseBoolean(per_session_data_eqemu *session, rapidjson::Document &doc, bool result, bool error, bool send_no_id) { if (doc.HasMember("id") || send_no_id) { rapidjson::StringBuffer s; rapidjson::Writer<rapidjson::StringBuffer> writer(s); writer.StartObject(); writer.String("id"); if (send_no_id) { writer.Null(); } else { writer.String(doc["id"].GetString()); } writer.String("result"); writer.StartObject(); writer.String("value"); writer.Bool(result); writer.EndObject(); writer.String("error"); if (error) { writer.Bool(true); } else { writer.Null(); } writer.EndObject(); session->send_queue->push_back(s.GetString()); } }
void Robot::Process_Status(rapidjson::Document& jsRequest) { if (jsRequest.HasMember("robot_info") && jsRequest["robot_info"].IsObject()) { m_sRobotStatus = JsonValueToString(jsRequest["robot_info"]); } }
void Robot::Process_RequestCustomer(rapidjson::Document& jsRequest) { if (jsRequest.HasMember("body") && jsRequest["body"].IsObject()) { rapidjson::Value& body = jsRequest["body"]; if (body.HasMember("question") && body["question"].IsObject()) { rapidjson::Value& question = body["question"]; rapidjson::Document request2Session; request2Session.SetObject(); rapidjson::Document::AllocatorType& allocator2A = request2Session.GetAllocator(); request2Session.AddMember("msgid", "request_customer", allocator2A); rapidjson::Value jstmp; jstmp.SetString(m_sID.c_str(), allocator2A); request2Session.AddMember("robot_id", jstmp, allocator2A); request2Session.AddMember("question", question, allocator2A); string sNotify = JsonDocToString(request2Session); vector<WebSocketSessionPtr> arrSession; RobotService::instance().m_SessionManager.GetAllSession(arrSession); for (vector<WebSocketSessionPtr>::iterator it = arrSession.begin(); it!=arrSession.end(); it++) { WebSocketSessionPtr spSession = *it; spSession->SendNotify(sNotify); } } else { log.debug("Process_RequestCustomer failed,no question node!"); } } }
// OPERATIONS void _CheckError() { if (document_.HasMember(kErrorCode)) { throw etcd::ReplyException(document_[kErrorCode].GetInt(), document_[kMessage].GetString(), document_[kCause].GetString()); } }
ColumnVector createColumnVectorFromJSON(const rapidjson::Document &config_doc, std::string key, unsigned int size) { ColumnVector col_vec(size); if (config_doc.HasMember(key.c_str())) { std::vector< std::vector<double> > vec; createVectorFromJSON(config_doc, key, vec); if (vec.size() != size) { throw std::runtime_error( (boost::format("Key specified by %s does not have the required %d values. %d entries were parsed.") % key % size % vec.size()).str() ); } for (int i = 0; i < size; ++i) { if (vec[i].size() != 1) { throw std::runtime_error( (boost::format("Row %d in the file specified by %s has %d values. There should only be one nodal value per line.") % i % key % size % vec[i].size()).str() ); } col_vec[i] = vec[i][0]; } } else { col_vec.setZero(); } return col_vec; }
JSON_API Vec3i read_Vec3i(rapidjson::Document const &d, char const *name, Vec3i const &def) { if(d.HasMember(name)) { if(!d[name].IsArray()) { std::stringstream str; str << "ERROR [read_Vec3i]: \"" << name << "\" should be an array"; throw std::runtime_error(str.str()); } if(d[name].Size()!=3) { std::stringstream str; str << "ERROR [read_Vec3i]: wrong array size for \"" << name <<"\"!"; throw std::runtime_error(str.str()); } for(rapidjson::SizeType i = 0; i < d[name].Size(); i++) { if(!d[name][i].IsInt()) { std::stringstream str; str << "ERROR [read_Vec3i]: array \"" << name <<"\" does not contain integers!"; throw std::runtime_error(str.str()); } } return Vec3i(d[name][0].GetInt(), d[name][1].GetInt(), d[name][2].GetInt()); } return def; }
void Manifest::loadManifest(const rapidjson::Document &json) { loadVersion(json); // Retrieve package url if ( json.HasMember(KEY_PACKAGE_URL) && json[KEY_PACKAGE_URL].IsString() ) { _packageUrl = json[KEY_PACKAGE_URL].GetString(); // Append automatically "/" if (_packageUrl.size() > 0 && _packageUrl[_packageUrl.size() - 1] != '/') { _packageUrl.append("/"); } } // Retrieve all assets if ( json.HasMember(KEY_ASSETS) ) { const rapidjson::Value& assets = json[KEY_ASSETS]; if (assets.IsObject()) { for (rapidjson::Value::ConstMemberIterator itr = assets.MemberBegin(); itr != assets.MemberEnd(); ++itr) { std::string key = itr->name.GetString(); Asset asset = parseAsset(key, itr->value); _assets.emplace(key, asset); } } } // Retrieve all search paths if ( json.HasMember(KEY_SEARCH_PATHS) ) { const rapidjson::Value& paths = json[KEY_SEARCH_PATHS]; if (paths.IsArray()) { for (rapidjson::SizeType i = 0; i < paths.Size(); ++i) { if (paths[i].IsString()) { _searchPaths.push_back(paths[i].GetString()); } } } } _loaded = true; }
void CJPsdParser::setElement(rapidjson::Document document) { if (document.HasMember("layer")) { const rapidjson::Value& layer = document["layer"]; for (int layerIdx = 0; layerIdx < layer.Size(); layerIdx++) { const rapidjson::Value& layerObj = layer[layerIdx]; CCDictionary *tempDict = CCDictionary::create(); if (layerObj.HasMember("name")) { _data->key = layerObj["name"].GetString(); _data->name = layerObj["name"].GetString(); tempDict->setObject(CCString::create(_data->name), "name"); std::string tempStr = CCString::create(_data->name)->getCString(); std::string delimiterDot = "."; std::string delimiterAt = "@"; tempStr = tempStr.substr(0, tempStr.find(delimiterDot)); tempStr = tempStr.substr(0, tempStr.find(delimiterAt)); tempDict->setObject(CCString::create(tempStr), "file"); } if(layerObj.HasMember("width")) { _data->size.width = layerObj["width"].GetDouble(); tempDict->setObject(CCFloat::create(_data->size.width), "width"); } if(layerObj.HasMember("height")) { _data->size.height = layerObj["height"].GetDouble(); tempDict->setObject(CCFloat::create(_data->size.height), "height"); } if(layerObj.HasMember("posX")) { _data->pos.x = layerObj["posX"].GetDouble(); tempDict->setObject(CCFloat::create(_data->pos.x), "posX"); } if(layerObj.HasMember("posY")) { _data->pos.y = layerObj["posY"].GetDouble(); tempDict->setObject(CCFloat::create(_data->pos.y), "posY"); } _psdDatas->setObject(tempDict, _data->key); this->_resetPsdData(); } } }
bool checkFields(rapidjson::Document& doc, std::vector<std::string> fields) { for ( auto fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) if (!doc.HasMember((*fieldIter).c_str())) return false; return true; }
bool isShaderUpToDate(uint32_t p_ShaderHash, const char* p_GpuProgramName) { if (_shaderCache.HasMember(p_GpuProgramName)) { return _shaderCache[p_GpuProgramName].GetUint() == p_ShaderHash; } return false; }
double parseDouble(rapidjson::Document &d, const char *entry) { if(d.HasMember(entry)) { if(d[entry].IsDouble()) { return d[entry].GetDouble(); } } return 0; }
void DoubleRoller::Create(const rapidjson::Document& d) { // Invoke base class method. ChPart::Create(d); // Read wheel geometry and mass properties assert(d.HasMember("Roller")); m_roller_radius = d["Roller"]["Radius"].GetDouble(); m_roller_width = d["Roller"]["Width"].GetDouble(); m_roller_gap = d["Roller"]["Gap"].GetDouble(); m_roller_mass = d["Roller"]["Mass"].GetDouble(); m_roller_inertia = LoadVectorJSON(d["Roller"]["Inertia"]); // Read contact material data assert(d.HasMember("Contact Material")); float mu = d["Contact Material"]["Coefficient of Friction"].GetFloat(); float cr = d["Contact Material"]["Coefficient of Restitution"].GetFloat(); SetContactFrictionCoefficient(mu); SetContactRestitutionCoefficient(cr); if (d["Contact Material"].HasMember("Properties")) { float ym = d["Contact Material"]["Properties"]["Young Modulus"].GetFloat(); float pr = d["Contact Material"]["Properties"]["Poisson Ratio"].GetFloat(); SetContactMaterialProperties(ym, pr); } if (d["Contact Material"].HasMember("Coefficients")) { float kn = d["Contact Material"]["Coefficients"]["Normal Stiffness"].GetFloat(); float gn = d["Contact Material"]["Coefficients"]["Normal Damping"].GetFloat(); float kt = d["Contact Material"]["Coefficients"]["Tangential Stiffness"].GetFloat(); float gt = d["Contact Material"]["Coefficients"]["Tangential Damping"].GetFloat(); SetContactMaterialCoefficients(kn, gn, kt, gt); } // Read wheel visualization if (d.HasMember("Visualization")) { assert(d["Visualization"].HasMember("Mesh Filename")); assert(d["Visualization"].HasMember("Mesh Name")); m_meshFile = d["Visualization"]["Mesh Filename"].GetString(); m_meshName = d["Visualization"]["Mesh Name"].GetString(); m_has_mesh = true; } }
void MainWindow::setLineEditTextFromConfig(QLineEdit *ledit, const std::string &variable, const rapidjson::Document &config_doc) { if (config_doc.HasMember(variable.c_str())) { if (!config_doc[variable.c_str()].IsString()){ throw std::runtime_error( (boost::format("Value associated with variable %s is not a string.") % variable).str() ); } ledit->setText(tr(config_doc[variable.c_str()].GetString())); } }
void Json_Parser::read_print(rapidjson::Document &doc,const char*keyname){ rapidjson::Value va; if (doc.HasMember(keyname)) { va=doc[keyname]; std::string name(keyname); if (va.IsBool()) { const bool flag=va.GetBool(); name+=":%d"; CCLOG(name.c_str(),flag); } else if (va.IsDouble()) { const double flag=va.GetDouble(); name+=":%f"; CCLOG(name.c_str(),flag); } else if (va.IsInt()) { const int flag=va.GetInt(); name+=":%d"; CCLOG(name.c_str(),flag); } else if (va.IsString()) { const std::string flag=va.GetString(); name+=":%s"; CCLOG(name.c_str(),flag.c_str()); } else if (va.IsNull()) { name+=":Null"; CCLOG(name.c_str()); } else if(va.IsObject()) { CCLOG("obj--------%s",keyname); 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--------%s",keyname); for (int i=0; i<va.Size();i++) { read_print_for_array(va[i],i); } } } }
void ShaftsDriveline4WD::Create(const rapidjson::Document& d) { // Read top-level data. assert(d.HasMember("Type")); assert(d.HasMember("Template")); assert(d.HasMember("Name")); SetName(d["Name"].GetString()); // Get shaft directions. assert(d.HasMember("Shaft Direction")); SetMotorBlockDirection(loadVector(d["Shaft Direction"]["Motor Block"])); SetAxleDirection(loadVector(d["Shaft Direction"]["Axle"])); // Read shaft inertias. assert(d.HasMember("Shaft Inertia")); m_driveshaft_inertia = d["Shaft Inertia"]["Driveshaft"].GetDouble(); m_frontshaft_inertia = d["Shaft Inertia"]["Front Driveshaft"].GetDouble(); m_rearshaft_inertia = d["Shaft Inertia"]["Rear Driveshaft"].GetDouble(); m_central_differentialbox_inertia = d["Shaft Inertia"]["Central Differential Box"].GetDouble(); m_front_differentialbox_inertia = d["Shaft Inertia"]["Front Differential Box"].GetDouble(); m_rear_differentialbox_inertia = d["Shaft Inertia"]["Rear Differential Box"].GetDouble(); // Read gear ratios. assert(d.HasMember("Gear Ratio")); m_front_conicalgear_ratio = d["Gear Ratio"]["Front Conical Gear"].GetDouble(); m_rear_conicalgear_ratio = d["Gear Ratio"]["Rear Conical Gear"].GetDouble(); m_central_differential_ratio = d["Gear Ratio"]["Central Differential"].GetDouble(); m_front_differential_ratio = d["Gear Ratio"]["Front Differential"].GetDouble(); m_rear_differential_ratio = d["Gear Ratio"]["Rear Differential"].GetDouble(); }
void CreatureManager::loadAnimations(rapidjson::Document& data, ResourceList& list) { namespace rj = rapidjson; if (!data.HasMember("animations")) return; CreatureResources crRes; crRes.type = CResourceType::ANIMATION; const rj::Value& animations = data["animations"]; for (rj::Value::ConstValueIterator it = animations.Begin(); it != animations.End(); ++it) { GameData::instance().resources->loadAnimation(*it); crRes.name = (*it)["name"].GetString(); list.push_back(crRes); } }
JSON_API std::string read_string(rapidjson::Document const &d, char const *name, std::string const &def) { if(d.HasMember(name)) { if(!d[name].IsString()) { std::stringstream str; str << "ERROR [read_string]: \"" << name << "\" should be a string"; throw std::runtime_error(str.str()); } return d[name].GetString(); } return def; }
JSON_API double read_double(rapidjson::Document const &d, char const *name, double def) { if(d.HasMember(name)) { if(!d[name].IsNumber()) { std::stringstream str; str << "ERROR [read_double]: \"" << name << "\" should be a number"; throw std::runtime_error(str.str()); } return d[name].GetDouble(); } return def; }
JSON_API int read_int(rapidjson::Document const &d, char const *name, int def) { if(d.HasMember(name)) { if(!d[name].IsInt()) { std::stringstream str; str << "ERROR [read_int]: \"" << name << "\" should be an integer"; throw std::runtime_error(str.str()); } return d[name].GetInt(); } return def; }
JSON_API bool read_bool(rapidjson::Document const &d, char const *name, bool def) { if(d.HasMember(name)) { if(!d[name].IsBool()) { std::stringstream str; str << "ERROR [read_bool]: \"" << name << "\" should be a bool"; throw std::runtime_error(str.str()); } return d[name].GetBool(); } return def; }
void ShaftsDriveline4WD::Create(const rapidjson::Document& d) { // Invoke base class method. ChPart::Create(d); // Get shaft directions. assert(d.HasMember("Shaft Direction")); SetMotorBlockDirection(LoadVectorJSON(d["Shaft Direction"]["Motor Block"])); SetAxleDirection(LoadVectorJSON(d["Shaft Direction"]["Axle"])); // Read shaft inertias. assert(d.HasMember("Shaft Inertia")); m_driveshaft_inertia = d["Shaft Inertia"]["Driveshaft"].GetDouble(); m_frontshaft_inertia = d["Shaft Inertia"]["Front Driveshaft"].GetDouble(); m_rearshaft_inertia = d["Shaft Inertia"]["Rear Driveshaft"].GetDouble(); m_central_differentialbox_inertia = d["Shaft Inertia"]["Central Differential Box"].GetDouble(); m_front_differentialbox_inertia = d["Shaft Inertia"]["Front Differential Box"].GetDouble(); m_rear_differentialbox_inertia = d["Shaft Inertia"]["Rear Differential Box"].GetDouble(); // Read gear ratios. assert(d.HasMember("Gear Ratio")); m_front_conicalgear_ratio = d["Gear Ratio"]["Front Conical Gear"].GetDouble(); m_rear_conicalgear_ratio = d["Gear Ratio"]["Rear Conical Gear"].GetDouble(); m_central_differential_ratio = d["Gear Ratio"]["Central Differential"].GetDouble(); m_front_differential_ratio = d["Gear Ratio"]["Front Differential"].GetDouble(); m_rear_differential_ratio = d["Gear Ratio"]["Rear Differential"].GetDouble(); m_axle_differential_locking_limit = 100; if (d.HasMember("Axle Differential Locking Limit")) { m_axle_differential_locking_limit = d["Axle Differential Locking Limit"].GetDouble(); } m_central_differential_locking_limit = 100; if (d.HasMember("Central Differential Locking Limit")) { m_central_differential_locking_limit = d["Central Differential Locking Limit"].GetDouble(); } }