//------------------------------------------------------------------------------ void Image::set(ptree pt) { if(pt.get_child_optional("UV")) this->setUV(Box(pt.get_child("UV")), getBoolFromPT(pt, "UV.normalized", false)); if(pt.get_child_optional("NinePatch")) this->setNinePatchData(NinePatchData(pt.get_child("NinePatch"))); if(pt.get_child_optional("color")) this->color = Color(pt.get("color", "#FFF")); };
void AVRRobot::Config::readTree(const ptree &pt) { compass.readTree(pt.get_child("compass")); sonar1.readTree(pt.get_child("sonar1")); sonar2.readTree(pt.get_child("sonar2")); wheels.readTree(pt.get_child("wheels")); stepper.readTree(pt.get_child("stepper")); }
bool AnimaMaterial::ReadObject(const ptree& objectTree, AnimaScene* scene, bool readName) { try { if(readName) SetName(objectTree.get<AnimaString>("AnimaMaterial.Name")); for(auto& shadersName : objectTree.get_child("AnimaMaterial.ShaderNames")) { if(shadersName.first == "ShaderName") { AnimaString shaderName = shadersName.second.get_value<AnimaString>(""); _shadersNames.push_back(shaderName); } } ptree mappedValuesTree = objectTree.get_child("AnimaMaterial.MappedValues"); return AnimaMappedValues::ReadObject(mappedValuesTree, scene, false); } catch (boost::property_tree::ptree_bad_path& exception) { AnimaLogger::LogMessageFormat("ERROR - Error parsing material: %s", exception.what()); return false; } catch (boost::property_tree::ptree_bad_data& exception) { AnimaLogger::LogMessageFormat("ERROR - Error parsing material: %s", exception.what()); return false; } }
void WheelsControl::Config::readTree(const ptree &pt) { left.readTree(pt.get_child("left")); right.readTree(pt.get_child("right")); back.readTree(pt.get_child("back")); turnhysteresis = (int16_t)pt.get<int>("turnhysteresis"); }
void DriveEquation::Config::readTree(const ptree &pt) { left.readTree(pt.get_child("left")); right.readTree(pt.get_child("right")); back.readTree(pt.get_child("back")); wheelangleoffset = Angle::fromDegrees(pt.get<float>("wheelangleoffset_deg")); minspeed = pt.get<float>("minspeed"); }
void AttackCommand::deserialize(ptree serial) { assertCompatibility(serial.get<std::string>("type"), "AttackCommand"); queued = serial.get<bool>("queued"); time = _atoi64(serial.get<string>("time").c_str()); unit.deserialize(serial.get_child("unit")); target.deserialize(serial.get_child("target")); }
/// Parses relation as simple relation with non-relation children. If child is single, then /// calls visitor with this child instead of relation. void processSimpleRelation(Visitor &visitor, std::uint32_t featureId, const ptree &feature) const { auto relation = parseRelation(featureId, feature.get_child("geometry.coordinates")); if (relation.elements.size()==1) { parseProperties(*relation.elements[0], featureId, feature.get_child("properties")); visitor.add(*relation.elements[0]); } else { parseProperties(relation, featureId, feature.get_child("properties")); visitor.add(relation); } }
//------------------------------------------------------------------------------ void WTextInput::_set(ptree n) { WText::_set(n); if(n.get_child_optional("border_normal")) this->setBorderNormal (kernel->graphicsMgr->loadImage(n.get_child("border_normal"))); if(n.get_child_optional("border_focused")) this->setBorderFocused(kernel->graphicsMgr->loadImage(n.get_child("border_focused"))); };
Department parseDepartment(const ptree& tree) { std::vector<Employee> empls; for (const auto& child : tree.get_child("employees", {})) empls.push_back(parseEmployee(child.second)); std::vector<Department> depts; for (const auto& child : tree.get_child("departments", {})) depts.push_back(parseDepartment(child.second)); return {tree.get<std::string>("name"), empls, depts}; }
/// Parses relation with relations from multipolygon and notifies visitor. void parseMultiPolygon(Visitor &visitor, std::uint32_t featureId, const ptree &feature) const { utymap::entities::Relation relation; parseProperties(relation, featureId, feature.get_child("properties")); for (const ptree::value_type &geometry : feature.get_child("geometry.coordinates")) { auto child = parseRelation(featureId, geometry.second); if (child.elements.size()==1) { FoldRelation fold; child.elements[0]->accept(fold); relation.elements.push_back(fold.element); } else { relation.elements.push_back(std::make_shared<utymap::entities::Relation>(child)); } } visitor.add(relation); }
void BasicTest::CheckProperty(int type, const std::string &name) { ptree element_pt = pt_.get_child("property." + name); const teamstyle16::Property &element_info = teamstyle16::kProperty[type]; EXPECT_EQ(element_pt.get("level", -1), element_info.level) << "Element type: " << name; EXPECT_EQ(element_pt.get("health_max", -1), element_info.health_max) << "Element type: " << name; EXPECT_EQ(element_pt.get("fuel_max", -1), element_info.fuel_max) << "Element type: " << name; EXPECT_EQ(element_pt.get("ammo_max", -1), element_info.ammo_max) << "Element type: " << name; EXPECT_EQ(element_pt.get("ammo_once", -1), element_info.ammo_once) << "Element type: " << name; EXPECT_EQ(element_pt.get("metal_max", -1), element_info.metal_max) << "Element type: " << name; EXPECT_EQ(element_pt.get("speed", -1), element_info.speed) << "Element type: " << name; EXPECT_EQ(element_pt.get("cost", -1), element_info.cost) << "Element type: " << name; EXPECT_EQ(element_pt.get("build_round", -1), element_info.build_round) << "Element type: " << name; EXPECT_EQ(element_pt.get("population", -1), element_info.population) << "Element type: " << name; }
// load void configuration::load(const ptree& in_conf) { try { settings_ = in_conf.get_child(settings_path_); LOG_INFO(settings_path_, "Loading settings"); auto model = settings_.get_optional<std::string>(model_key_); if (!model) { throw configuration_error("model descriptor '" + model_key_ + "' has to be set in " + settings_path_); } defaults_path_ += "." + *model; auto def = in_conf.get_child_optional(defaults_path_); if (def) { LOG_INFO(settings_path_, *model + " defaults found."); defaults_ = *def; } else { LOG_INFO(settings_path_, "No default settings provided for this board."); } } catch (ptree_bad_path& e) { throw path_error(e.path<std::string>()); } catch (ptree_error& e) { // shouldn't happen throw configuration_error("Processing error", e.what()); } }
boost::shared_ptr<scxml_parser::transition> scxml_parser::parse_transition(const ptree &pt) { const ptree &xmlattr = pt.get_child("<xmlattr>"); boost::shared_ptr<transition> tr = boost::make_shared<transition>(); try { using namespace boost::algorithm; boost::optional<string> target(xmlattr.get_optional<string>("target")); if(target) split(tr->target, *target, is_any_of(" "), token_compress_on); if(tr->target.size() > 1) parallel_target_sizes.insert(tr->target.size()); tr->event = xmlattr.get_optional<string>("event"); for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) { if (it->first == "<xmlcomment>") ; // ignore comments else if (it->first == "<xmlattr>") ; // ignore, parsed above else if (it->first == "script") tr->actions.push_back(parse_script(it->second)); else if (it->first == "log") tr->actions.push_back(parse_log(it->second)); else if (it->first == "raise") tr->actions.push_back(parse_raise(it->second)); else cerr << "warning: unknown item '" << it->first << "' in <transition>" << endl; } } catch (ptree_error e) { cerr << "error: transition: " << e.what() << endl; exit(1); } return tr; }
bool get_child(ptree& ptin, const std::string& path, ptree& ptout) { static boost::mutex io_mutex; boost::mutex::scoped_lock lock(io_mutex); //if(&ptin)return false; try { ptout = ptin.get_child(path); return true; } catch(std::exception& err) { LOG_BASELINE_ERROR<< "json get_child(): has error, " << err.what(); //return (ptree&)NULL; return false; } catch(...) { LOG_BASELINE_ERROR << "json get_child(): has unknown error!\n"; //return (ptree&)NULL; return false; } //return (ptree&)NULL; return false; }
boost::shared_ptr<scxml_parser::action> scxml_parser::parse_log(const ptree &pt) { boost::shared_ptr<action> ac = boost::make_shared<action>(); try { const ptree &xmlattr = pt.get_child("<xmlattr>"); boost::optional<string> label(xmlattr.get_optional<string>("label")); const string expr = xmlattr.get<string>("expr"); ac->type = "log"; if(label) ac->attr["label"] = *label; ac->attr["expr"] = expr; for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) { if (it->first == "<xmlcomment>") ; // ignore comments else if (it->first == "<xmlattr>") ; // ignore, parsed above else cerr << "warning: unknown item '" << it->first << "' in <log>" << endl; } } catch (ptree_error e) { cerr << "error: log: " << e.what() << endl; exit(1); } using_log = true; return ac; }
boost::shared_ptr<scxml_parser::action> scxml_parser::parse_raise(const ptree &pt) { boost::shared_ptr<action> ac = boost::make_shared<action>(); try { const ptree &xmlattr = pt.get_child("<xmlattr>"); const string event = xmlattr.get<string>("event"); ac->type = "raise"; ac->attr["event"] = event; for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) { if (it->first == "<xmlcomment>") ; // ignore comments else if (it->first == "<xmlattr>") ; // ignore, parsed above else cerr << "warning: unknown item '" << it->first << "' in <raise>" << endl; } } catch (ptree_error e) { cerr << "error: raise: " << e.what() << endl; exit(1); } using_event_queue = true; return ac; }
void LisLinearSolver::setOption(const ptree &option) { boost::optional<ptree> ptSolver = option.get_child("LinearSolver"); if (!ptSolver) return; boost::optional<std::string> solver_type = ptSolver->get_optional<std::string>("solver_type"); if (solver_type) { _option.solver_type = _option.getSolverType(*solver_type); } boost::optional<std::string> precon_type = ptSolver->get_optional<std::string>("precon_type"); if (precon_type) { _option.precon_type = _option.getPreconType(*precon_type); } boost::optional<std::string> matrix_type = ptSolver->get_optional<std::string>("matrix_type"); if (matrix_type) { _option.matrix_type = _option.getMatrixType(*matrix_type); } boost::optional<double> error_tolerance = ptSolver->get_optional<double>("error_tolerance"); if (error_tolerance) { _option.error_tolerance = *error_tolerance; } boost::optional<int> max_iteration_step = ptSolver->get_optional<int>("max_iteration_step"); if (max_iteration_step) { _option.max_iterations = *max_iteration_step; } }
//! Store results of the given json string in the row'th of the given // matrix v. void Vec(const ptree& pt, const ptree::key_type& key, arma::mat& v, int row) { int col = 0; for (auto& item : pt.get_child(key)) { v(row, col++) = item.second.get_value<int>(); } }
void PipelineReaderXML::collect_attributes(map_t& attrs, const ptree& tree) { if (tree.count("<xmlattr>")) { const ptree& subtree = tree.get_child("<xmlattr>"); parse_attributes(attrs, subtree); } }
/** * Constructor loads config stuff from boost::program_options ptree (json initialized), i.e. * ROOT data config (number of events to load, file name, tree name, branch name), multiplexed data file name * (location of the existing or a path to write a new one from ROOT tree. */ HistogramConfig::HistogramConfig(ptree pt){ ptree histos=pt.get_child("histos"); ptree options=pt.get_child("options"); numOfEvents = options.get<int>("numOfEvents"); treeName = options.get<string>("treeName"); branchName = options.get<string>("branchName"); rootDataFile = options.get<string>("rootDataFile"); myDataFile = options.get<string>("myDataFile"); multiplexedByteLenOfEvent=0; for(auto h:histos){ int bins = h.second.get<int>("bins"); int bytes = noOfBytes(bins); multiplexedByteLenOfEvent +=bytes; vec.push_back({h.second.get<string>("name"), bins,bytes,h.second.get<float>("min"),h.second.get<float>("max")}); } numOfHistos = vec.size(); }
shared_ptr<FeatureExtractor> TrackingBenchmark::createFeatureExtractor( shared_ptr<ImagePyramid> pyramid, ptree& config) { float scaleFactor = config.get<float>("scale", 1.f); if (config.get_value<string>() == "histeq") { pyramidExtractor = createPyramidExtractor(config.get_child("pyramid"), pyramid, false); pyramidExtractor->addPatchFilter(make_shared<HistogramEqualizationFilter>()); return wrapFeatureExtractor(pyramidExtractor, scaleFactor); } else if (config.get_value<string>() == "whi") { pyramidExtractor = createPyramidExtractor(config.get_child("pyramid"), pyramid, true); pyramidExtractor->addPatchFilter(make_shared<WhiteningFilter>()); pyramidExtractor->addPatchFilter(make_shared<HistogramEqualizationFilter>()); pyramidExtractor->addPatchFilter(make_shared<ConversionFilter>(CV_32F, 1.0 / 127.5, -1.0)); pyramidExtractor->addPatchFilter(make_shared<UnitNormFilter>(cv::NORM_L2)); return wrapFeatureExtractor(pyramidExtractor, scaleFactor); } else if (config.get_value<string>() == "haar") { vector<float> sizes; float size; istringstream sizesStream(config.get<string>("sizes")); while (sizesStream.good() && !sizesStream.fail()) { sizesStream >> size; sizes.push_back(size); } float gridRows = config.get<float>("gridRows"); float gridCols = config.get<float>("gridCols"); int types = 0; string type; istringstream typesStream(config.get<string>("types")); while (typesStream.good() && !typesStream.fail()) { typesStream >> type; if (type == "2rect") types |= HaarFeatureFilter::TYPE_2RECTANGLE; else if (type == "3rect") types |= HaarFeatureFilter::TYPE_3RECTANGLE; else if (type == "4rect") types |= HaarFeatureFilter::TYPE_4RECTANGLE; else if (type == "center-surround") types |= HaarFeatureFilter::TYPE_CENTER_SURROUND; else if (type == "all") types |= HaarFeatureFilter::TYPES_ALL; } shared_ptr<DirectImageFeatureExtractor> featureExtractor = make_shared<DirectImageFeatureExtractor>(); featureExtractor->addImageFilter(make_shared<GrayscaleFilter>()); featureExtractor->addImageFilter(make_shared<IntegralImageFilter>()); featureExtractor->addPatchFilter(make_shared<HaarFeatureFilter>(sizes, gridRows, gridCols, types)); return wrapFeatureExtractor(featureExtractor, scaleFactor); } else if (config.get_value<string>() == "hog") {
Company parseCompany(const ptree& tree) { std::vector<Department> depts; for (const auto& child : tree.get_child("departments", {})) depts.push_back(parseDepartment(child.second)); return {tree.get<std::string>("name"), depts}; }
FilterData MakeFilterData(const ptree& pt) { FilterData data; data.name = pt.get<std::string>("Filter.Name"); data.filter.messageFilters = MakeFilters(pt.get_child("Filter.MessageFilters")); data.filter.processFilters = MakeFilters(pt.get_child("Filter.ProcessFilters")); return data; }
static std::vector<T> as_vector(ptree const& pt, ptree::key_type const& key) { std::vector<T> r; for (auto& item : pt.get_child(key)) { assert(item.first.empty()); // array elements have no names r.push_back(item.second.get_value<T>()); } return r; }
/////////////////////////////////////////////////////////////////////////////// /// @fn CMessage::CMessage /// @description From a ptree, creates a CMessage /// @pre None /// @post The CMessage has been initalized from a ptree. /////////////////////////////////////////////////////////////////////////////// CMessage::CMessage( const ptree &pt ) { Logger.Trace << __PRETTY_FUNCTION__ << std::endl; try { std::string time_tmp; // Get the source host's ID and store it in the m_src variable. // An exception is thrown if "message.source" does not exist. m_srcUUID = pt.get< std::string >("message.source"); m_remotehost.hostname = pt.get< std::string >("message.hostname"); m_remotehost.port = pt.get< std::string >("message.port"); m_sequenceno = pt.get< unsigned int >("message.sequenceno"); m_protocol = pt.get< std::string >("message.protocol"); m_sendtime = pt.get< boost::posix_time::ptime >("message.sendtime"); m_handler = pt.get< std::string >("message.handler"); try { m_expiretime = pt.get< boost::posix_time::ptime >("message.expiretime"); } catch( boost::property_tree::ptree_error &e ) { m_expiretime = boost::posix_time::ptime(); } if(HasExpireTime()) { m_never_expires = true; } m_status = static_cast< StatusType > (pt.get< unsigned int >("message.status")); // Iterate over the "message.modules" section and store all found // in the m_modules set. These indicate sub-ptrees that algorithm // modules have added. m_submessages = pt.get_child("message.submessages"); m_properties = pt.get_child("message.properties"); } catch( boost::property_tree::ptree_error &e ) { Logger.Error << "Invalid CMessage ptree format:" << e.what() << std::endl; throw; } }
void CompShapePolygon::loadFromPropertyTree(const ptree& propTree) { foreach(const ptree::value_type &v, propTree.get_child("polygon")) { const ptree& vertex = v.second; float x = vertex.get<float>("x"); float y = vertex.get<float>("y"); m_vertices.push_back( Vector2D(x, y) ); } }
void add_to_data(ptree& pt, const ptree& record) { if(!pt.get_child_optional("data")) { ptree arrayPt; arrayPt.push_back(make_pair("", record)); pt.push_back(make_pair("data", arrayPt)); } else { auto& dataPt = pt.get_child("data"); dataPt.push_back(make_pair("", record)); } }
void ProjectConfiguration::ReadPtree(const ptree& pt, const wxString& proj_path) { project_title = pt.get("project.title", ""); const ptree& subtree = pt.get_child("project.layers.layer"); LayerConfiguration* layer_conf = new LayerConfiguration(subtree, proj_path); layer_confs.push_back(layer_conf); }
Filter MakeFilter(const ptree& pt) { Filter filter; filter.enable = pt.get<bool>("Enable"); filter.text = pt.get<std::string>("Text"); filter.matchType = StringToMatchType(pt.get<std::string>("MatchType")); filter.filterType = StringToFilterType(pt.get<std::string>("FilterType")); filter.bgColor = MakeColor(pt.get_child("BackColor")); filter.fgColor = MakeColor(pt.get_child("TextColor")); return filter; }
void parser::read_game(const ptree &pt, game_t &game) { game.title = pt.get<string>("title"); game.copyright = pt.get<string>("copyright", string()); game.license = pt.get<string>("license", string("unspecified")); game.homepage = pt.get<string>("homepage", string()); if (pt.count("authors")) { BOOST_FOREACH(const ptree::value_type & v, pt.get_child("authors")) { game.authors.push_back(v.second.data()); } }