void TopwoData::analyzeDataMission(rapidjson::Document& doc) { DataMission* mission_data = NULL; for (int i = 0; i < (int)doc.Size(); i++) { mission_data = DataMission::create(); if (doc[i].HasMember("ID") && doc[i]["ID"].IsDouble()) mission_data->setId((int)doc[i]["ID"].GetDouble()); if (doc[i].HasMember("TY") && doc[i]["TY"].IsDouble()) mission_data->setType((int)doc[i]["TY"].GetDouble()); if (doc[i].HasMember("RE") && doc[i]["RE"].IsDouble()) mission_data->setReward((int)doc[i]["RE"].GetDouble()); if (doc[i].HasMember("TI") && doc[i]["TI"].IsString()) mission_data->setTitle(CCString::create(doc[i]["TI"].GetString())); if (doc[i].HasMember("CO") && doc[i]["CO"].IsString()) mission_data->setContent(CCString::create(doc[i]["CO"].GetString())); if (doc[i].HasMember("MI") && doc[i]["MI"].IsString()) mission_data->setMission(CCString::create(doc[i]["MI"].GetString())); if (doc[i].HasMember("TA") && doc[i]["TA"].IsDouble()) mission_data->setTarget(doc[i]["TA"].GetDouble()); if (doc[i].HasMember("WO") && doc[i]["WO"].IsDouble()) mission_data->setWooer((int)doc[i]["WO"].GetDouble()); addDataMissionToArray(mission_data); } }
void BlackCity::initIdTable(rapidjson::Document &_doc){ if (_doc.IsArray()){ int size = _doc.Size(); int objId; for (int i = 0; i<size; i++) { objId =DICTOOL->getIntValue_json(_doc[i], "ID"); idTable.insert(std::make_pair(objId, i)); } } }
void TopwoData::analyzeDataSection(rapidjson::Document& doc) { DataSection* chapter_data = NULL; for (int i = 0; i < (int)doc.Size(); i++) { chapter_data = DataSection::create(); if (doc[i].HasMember("ID") && doc[i]["ID"].IsDouble()) chapter_data->setId((int)doc[i]["ID"].GetDouble()); if (doc[i].HasMember("BE") && doc[i]["BE"].IsDouble()) chapter_data->setBeginId((int)doc[i]["BE"].GetDouble()); if (doc[i].HasMember("EN") && doc[i]["EN"].IsDouble()) chapter_data->setEndId((int)doc[i]["EN"].GetDouble()); addDataSectionToArray(chapter_data); } }
bool LevelConfig::parseJsonDoc(rapidjson::Document &doc) { for (int i = 0; i < doc.Size(); ++i) { rapidjson::Value &item = doc[(unsigned int) i]; if (!item.HasMember("ID") || !item.HasMember("Exp") ||!item.HasMember("ChipMax")||!item.HasMember("Reward")) { CLOG(ERROR) << "Lack required key."; return false; } int32_t level = item["ID"].GetInt(); config[level].level = level; config[level].expNeed = item["Exp"].GetInt64(); config[level].maxBet = item["ChipMax"].GetInt64(); config[level].fortuneReward = item["Reward"].GetInt(); } return true; }
void TopwoData::analyzeDataNpc(rapidjson::Document& doc) { DataNpc* npc_data = NULL; for (int i = 0; i < (int)doc.Size(); i++) { npc_data = DataNpc::create(); if (doc[i].HasMember("ID") && doc[i]["ID"].IsDouble()) npc_data->setId((int)doc[i]["ID"].GetDouble()); if (doc[i].HasMember("NA") && doc[i]["NA"].IsString()) npc_data->setName(CCString::create(doc[i]["NA"].GetString())); if (doc[i].HasMember("MF") && doc[i]["MF"].IsDouble()) npc_data->setFavorMax((int)doc[i]["MF"].GetDouble()); if (doc[i].HasMember("IN") && doc[i]["IN"].IsString()) npc_data->setDes(CCString::create(doc[i]["IN"].GetString())); if (doc[i].HasMember("EM") && doc[i]["EM"].IsDouble()) npc_data->setExpressMissionId((int)doc[i]["EM"].GetDouble()); addDataNpcToArray(npc_data); } }
EReturn AICOProblem::reinitialise(rapidjson::Document& document, boost::shared_ptr<PlanningProblem> problem) { clear(); if (document.IsArray()) { for (rapidjson::SizeType i = 0; i < document.Size(); i++) { rapidjson::Value& obj = document[i]; if (obj.IsObject()) { std::string constraintClass; if (ok(getJSON(obj["class"], constraintClass))) { if (knownMaps_.find(constraintClass) != knownMaps_.end()) { TaskMap_ptr taskmap; if (ok( TaskMap_fac::Instance().createObject( knownMaps_[constraintClass], taskmap))) { EReturn ret = taskmap->initialise(obj, server_, scenes_, problem); if (ok(ret)) { if (ret != CANCELLED) { std::string name = taskmap->getObjectName(); task_maps_[name] = taskmap; TaskDefinition_ptr task; if (ok( TaskDefinition_fac::Instance().createObject( "TaskSqrError", task))) { TaskSqrError_ptr sqr = boost::static_pointer_cast< TaskSqrError>(task); sqr->setTaskMap(taskmap); int dim; taskmap->taskSpaceDim(dim); sqr->y_star0_.resize(dim); sqr->rho0_(0) = 0.0; sqr->rho1_(0) = 1e4; sqr->object_name_ = name + std::to_string((unsigned long) sqr.get()); // TODO: Better implementation of stting goals from JSON sqr->y_star0_.setZero(); sqr->setTimeSteps(T + 2); Eigen::VectorXd tspan(2); Eigen::VectorXi tspani(2); if (obj["tspan"]["__ndarray__"].IsArray()) { getJSON(obj["tspan"]["__ndarray__"], tspan); } else { getJSON(obj["tspan"], tspan); } if (tspan(0) <= 0.0) tspan(0) = 0.0; if (tspan(1) >= 1.0) tspan(1) = 1.0; tspani(0) = (int) (T * tspan(0)); tspani(1) = (int) (T * tspan(1)); for (int t = tspani(0); t <= tspani(1); t++) { sqr->registerRho( Eigen::VectorXdRef_ptr(sqr->rho1_.segment(0, 1)), t); } sqr->wasFullyInitialised_ = true; task_defs_[name] = task; } else { INDICATE_FAILURE ; return FAILURE; } } else { ROS_WARN_STREAM( "Creation of '"<<constraintClass<<"' cancelled!"); } } else { INDICATE_FAILURE ; return FAILURE; } } else { INDICATE_FAILURE ; return FAILURE; } } else { WARNING("Ignoring unknown constraint '"<<constraintClass<<"'"); } } else { INDICATE_FAILURE ; return FAILURE; } } else { INDICATE_FAILURE ; return FAILURE; } } } else { INDICATE_FAILURE ; return FAILURE; } return SUCCESS; }
void IKProblem::reinitialise(rapidjson::Document& document, boost::shared_ptr<PlanningProblem> problem) { clear(); if (document.IsArray()) { for (rapidjson::SizeType i = 0; i < document.Size(); i++) { rapidjson::Value& obj = document[i]; if (obj.IsObject()) { std::string constraintClass; getJSON(obj["class"], constraintClass); if (knownMaps_.find(constraintClass) != knownMaps_.end()) { TaskMap_ptr taskmap = Initialiser::createMap(knownMaps_[constraintClass]); taskmap->initialise(obj, server_, scene_,problem); std::string name = taskmap->getObjectName(); task_maps_[name] = taskmap; TaskDefinition_ptr task = Initialiser::createDefinition("TaskSqrError"); TaskSqrError_ptr sqr = boost::static_pointer_cast<TaskSqrError>(task); sqr->setTaskMap(taskmap); int dim; taskmap->taskSpaceDim(dim); sqr->y_star0_.resize(dim); sqr->rho0_(0) = 0.0; sqr->rho1_(0) = 1.0; sqr->object_name_ = name+ std::to_string((unsigned long) sqr.get()); // TODO: Better implementation of stting goals from JSON sqr->y_star0_.setZero(); sqr->setTimeSteps(T_); Eigen::VectorXd tspan(2); Eigen::VectorXi tspani(2); // TODO fix ndarray problem getJSON(obj["tspan"], tspan); if (tspan(0) <= 0.0) tspan(0) = 0.0; if (tspan(1) >= 1.0) tspan(1) = 1.0; tspani(0) = (int) ((T_ - 1) * tspan(0)); tspani(1) = (int) ((T_ - 1) * tspan(1)); for (int t = tspani(0); t <= tspani(1); t++) { sqr->registerRho(Eigen::VectorXdRef_ptr(sqr->rho1_.segment(0, 1)),t); } sqr->wasFullyInitialised_ = true; task_defs_[name] = task; } else { // WARNING("Ignoring unknown constraint '"<<constraintClass<<"'"); } } { throw_named("Invalid JSON document object!"); } } } else { throw_named("Invalid JSON array!"); } }