本文整理汇总了C++中boost::property_tree::ptree::get_child方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::get_child方法的具体用法?C++ ptree::get_child怎么用?C++ ptree::get_child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::property_tree::ptree
的用法示例。
在下文中一共展示了ptree::get_child方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
mergePropertyTrees (boost::property_tree::ptree &ptMerged,
const boost::property_tree::ptree &ptSecond, int level )
{
// Value or object or array
if (level > 0 && ptSecond.empty() ) {
// Copy value
ptMerged = ptSecond;
} else if (level > 0 && ptSecond.count (std::string() ) == ptSecond.size() ) {
// Copy array
ptMerged = ptSecond;
} else {
auto it = ptSecond.begin();
for (; it != ptSecond.end(); ++it) {
boost::property_tree::ptree child = ptMerged.get_child (it->first.data(),
boost::property_tree::ptree() );
mergePropertyTrees (child, it->second, level + 1);
ptMerged.erase (it->first.data() );
ptMerged.add_child (it->first.data(), child);
}
}
}
示例2: parse_configuration
void parse_configuration( boost::property_tree::ptree & config ) {
boost::property_tree::ptree lconfig;
if( config.get_child_optional( "mutation" ) != boost::none ) {
lconfig = config.get_child( "mutation" );
}
if( lconfig.get_child_optional( "mutation_per_sequence" ) == boost::none ) {
lconfig.put("mutation_per_sequence", m_mutation_rate );
} else {
m_mutation_rate = lconfig.get< real_type >( "mutation_per_sequence", m_mutation_rate );
}
if( lconfig.get_child_optional( "rng.seed" ) != boost::none ) {
m_seed = lconfig.get< seed_type >( "rng.seed", m_seed );
}
if( m_seed == 0 ) {
m_seed = clotho::utility::clock_type::now().time_since_epoch().count();
lconfig.put("rng.seed", m_seed );
}
config.put_child( "mutation", lconfig );
}
示例3:
tsun::tsun(const boost::property_tree::ptree& sun)
: tsun{sun.get<std::string>("id"),
geometry::tcartesian::load(sun.get_child("position"))}
{
TRACE;
}
示例4: ReadPtree
void VarOrderPtree::ReadPtree(const boost::property_tree::ptree& pt,
const wxString& proj_path)
{
LOG_MSG("Entering VarOrderPtree::ReadPtree");
using boost::property_tree::ptree;
using namespace std;
set<wxString> grp_set;
try {
try {
pt.get_child("variable_order");
}
catch (boost::property_tree::ptree_bad_path& e) {
// variable_order is optional
return;
}
// iterate over each child of variable_order
time_ids.clear();
BOOST_FOREACH(const ptree::value_type &v,
pt.get_child("variable_order")) {
wxString key = v.first.data();
LOG_MSG(key);
if (key == "var") {
VarGroup ent;
ent.name = v.second.data();
LOG_MSG("found var: ");
LOG_MSG(v.second.data());
//var_order.push_back(v.second.data());
var_grps.push_back(ent);
} else if (key == "time_ids") {
BOOST_FOREACH(const ptree::value_type &v, v.second) {
wxString key = v.first.data();
LOG_MSG(key);
LOG_MSG(v.second.data());
time_ids.push_back(v.second.data());
}
} else if (key == "group") {
VarGroup ent;
BOOST_FOREACH(const ptree::value_type &v, v.second) {
wxString key = v.first.data();
if (key == "name") {
LOG_MSG("found name: ");
LOG_MSG(v.second.data());
ent.name = v.second.data();
} else if (key == "var") {
LOG_MSG("found var: ");
LOG_MSG(v.second.data());
ent.vars.push_back(v.second.data());
} else if (key == "placeholder") {
LOG_MSG("placeholder found");
ent.vars.push_back("");
} else if (key == "displayed_decimals") {
wxString vs(v.second.data());
LOG_MSG("found displayed_decimals: ");
LOG_MSG(vs);
long dd;
if (!vs.ToLong(&dd)) dd = -1;
ent.displayed_decimals = dd;
}
}
if (ent.name.empty()) {
wxString msg = "space-time variable found with no name";
throw GdaException(msg.mb_str());
}
if (grp_set.find(ent.name) != grp_set.end()) {
wxString ss;
ss << "Space-time variables with duplicate name \"";
ss << ent.name << "\" found.";
throw GdaException(ss.mb_str());
}
var_grps.push_back(ent);
grp_set.insert(ent.name);
}
示例5: ReadPtree
void WeightsManPtree::ReadPtree(const boost::property_tree::ptree& pt,
const wxString& proj_path)
{
LOG_MSG("Entering WeightsManPtree::ReadPtree");
using boost::property_tree::ptree;
using namespace std;
weights_list.clear();
try {
try {
pt.get_child("weights_entries");
}
catch (boost::property_tree::ptree_bad_path& e) {
// weights_entries is optional
return;
}
// iterate over each child of weights_entries
BOOST_FOREACH(const ptree::value_type &v,
pt.get_child("weights_entries")) {
wxString key = v.first.data();
LOG_MSG(key);
if (key == "weights") {
WeightsPtreeEntry e;
BOOST_FOREACH(const ptree::value_type &v, v.second) {
wxString key = v.first.data();
LOG_MSG(key);
if (key == "title") {
wxString s = v.second.data();
e.title = s;
} else if (key == "default") {
e.is_default = true;
} else if (key == "meta_info") {
BOOST_FOREACH(const ptree::value_type &v, v.second) {
wxString key = v.first.data();
LOG_MSG(key);
if (key == "weights_type") {
wxString s = v.second.data();
if (s == "rook") {
e.wmi.weights_type = WeightsMetaInfo::WT_rook;
} else if (s == "queen") {
e.wmi.weights_type = WeightsMetaInfo::WT_queen;
} else if (s == "threshold") {
e.wmi.weights_type = WeightsMetaInfo::WT_threshold;
} else if (s == "knn") {
e.wmi.weights_type = WeightsMetaInfo::WT_knn;
} else { // s == "custom"
e.wmi.weights_type = WeightsMetaInfo::WT_custom;
}
} else if (key == "path") {
wxString s = v.second.data();
e.wmi.filename = GenUtils::RestorePath(proj_path, s);
if (!wxFileExists(e.wmi.filename)) {
wxString msg;
msg << "The GeoDa project file cannot find one or more associated data sources.\n\n";
msg << "Details: Weights file (" << e.wmi.filename << ") is missing";
msg << "\n\nTip: You can open the .gda project file in a text editor to modify the path(s) of the weights file(s) (.gwt or .gal extension) associated with your project.";
throw GdaException(msg.mb_str());
}
} else if (key == "id_variable") {
wxString s = v.second.data();
e.wmi.id_var = s;
} else if (key == "symmetry") {
wxString s = v.second.data();
if (s == "symmetric") {
e.wmi.sym_type = WeightsMetaInfo::SYM_symmetric;
} else if (s == "asymmetric") {
e.wmi.sym_type = WeightsMetaInfo::SYM_asymmetric;
} else if (s == "unknown" || s.IsEmpty()) {
e.wmi.sym_type = WeightsMetaInfo::SYM_unknown;
} else {
wxString msg("unrecognized value: ");
msg << s << " for key: " << key;
throw GdaException(msg.mb_str());
}
} else if (key == "order") {
long l;
wxString(v.second.data()).ToLong(&l);
e.wmi.order = l;
} else if (key == "inc_lower_orders") {
wxString s = v.second.data();
if (s.CmpNoCase("false") == 0) {
e.wmi.inc_lower_orders = false;
} else if (s.CmpNoCase("true") == 0) {
e.wmi.inc_lower_orders = true;
} else {
wxString msg("unrecognized value: ");
msg << s << " for key: " << key;
throw GdaException(msg.mb_str());
}
} else if (key == "dist_metric") {
wxString s = v.second.data();
if (s == "euclidean") {
e.wmi.dist_metric = WeightsMetaInfo::DM_euclidean;
} else if (s == "arc") {
e.wmi.dist_metric = WeightsMetaInfo::DM_arc;
} else if (s == "unspecified" || s.IsEmpty()) {
e.wmi.dist_metric = WeightsMetaInfo::DM_unspecified;
//.........这里部分代码省略.........
示例6: parse_ptree
void parse_ptree(boost::property_tree::ptree& pt,
std::shared_ptr<dabEnsemble> ensemble,
std::shared_ptr<BaseRemoteController> rc
)
{
using boost::property_tree::ptree;
using boost::property_tree::ptree_error;
/******************** READ GENERAL OPTIONS *****************/
ptree pt_general = pt.get_child("general");
/* Dab mode logic */
ensemble->mode = pt_general.get("dabmode", 2);
if ((ensemble->mode < 1) || (ensemble->mode > 4)) {
throw runtime_error("Mode must be between 1-4");
}
if (ensemble->mode == 4) {
ensemble->mode = 0;
}
/* Enable Logging to syslog conditionally */
if (pt_general.get<bool>("syslog", false)) {
etiLog.register_backend(new LogToSyslog()); // TODO don't leak the LogToSyslog backend
}
/******************** READ ENSEMBLE PARAMETERS *************/
ptree pt_ensemble = pt.get_child("ensemble");
/* Ensemble ID */
ensemble->id = hexparse(pt_ensemble.get("id", "0"));
/* Extended Country Code */
ensemble->ecc = hexparse(pt_ensemble.get("ecc", "0"));
ensemble->international_table = pt_ensemble.get("international-table", 0);
string lto_auto = pt_ensemble.get("local-time-offset", "");
if (lto_auto == "auto") {
ensemble->lto_auto = true;
ensemble->lto = 0;
}
else {
double lto_hours = pt_ensemble.get("local-time-offset", 0.0);
if (round(lto_hours * 2) != lto_hours * 2) {
etiLog.level(error) << "Ensemble local time offset " <<
lto_hours << "h cannot be expressed in half-hour blocks.";
throw runtime_error("ensemble local-time-offset definition error");
}
if (lto_hours > 12 || lto_hours < -12) {
etiLog.level(error) << "Ensemble local time offset " <<
lto_hours << "h out of bounds [-12, +12].";
throw runtime_error("ensemble local-time-offset definition error");
}
ensemble->lto_auto = false;
ensemble->lto = abs(rint(lto_hours * 2));
}
int success = -5;
string ensemble_label = pt_ensemble.get<string>("label");
string ensemble_short_label(ensemble_label);
try {
ensemble_short_label = pt_ensemble.get<string>("shortlabel");
success = ensemble->label.setLabel(ensemble_label, ensemble_short_label);
}
catch (ptree_error &e) {
etiLog.level(warn) << "Ensemble short label undefined, "
"truncating label " << ensemble_label;
success = ensemble->label.setLabel(ensemble_label);
}
switch (success)
{
case 0:
break;
case -1:
etiLog.level(error) << "Ensemble short label " <<
ensemble_short_label << " is not subset of label '" <<
ensemble_label << "'";
throw runtime_error("ensemble label definition error");
case -2:
etiLog.level(error) << "Ensemble short label " <<
ensemble_short_label << " is too long (max 8 characters)";
throw runtime_error("ensemble label definition error");
case -3:
etiLog.level(error) << "Ensemble label " <<
ensemble_label << " is too long (max 16 characters)";
throw runtime_error("ensemble label definition error");
default:
etiLog.level(error) <<
"Ensemble short label definition: program error !";
abort();
}
try {
ptree pt_announcements = pt_ensemble.get_child("announcements");
for (auto announcement : pt_announcements) {
string name = announcement.first;
ptree pt_announcement = announcement.second;
auto cl = make_shared<AnnouncementCluster>(name);
//.........这里部分代码省略.........
示例7: initialize
void Pack::initialize(const std::string& name,
const std::string& source,
const pt::ptree& tree) {
name_ = name;
source_ = source;
discovery_queries_.clear();
if (tree.count("discovery") > 0) {
for (const auto& item : tree.get_child("discovery")) {
discovery_queries_.push_back(item.second.get_value<std::string>());
}
}
discovery_cache_ = std::make_pair<int, bool>(0, false);
stats_ = {0, 0, 0};
platform_.clear();
if (tree.count("platform") > 0) {
platform_ = tree.get<std::string>("platform", "");
}
version_.clear();
if (tree.count("version") > 0) {
version_ = tree.get<std::string>("version", "");
}
schedule_.clear();
if (tree.count("queries") == 0) {
// This pack contained no queries.
return;
}
// If the splay percent is less than 1 reset to a sane estimate.
if (FLAGS_schedule_splay_percent <= 1) {
FLAGS_schedule_splay_percent = 10;
}
// Iterate the queries (or schedule) and check platform/version/sanity.
for (const auto& q : tree.get_child("queries")) {
if (q.second.count("platform")) {
if (!checkPlatform(q.second.get<std::string>("platform", ""))) {
continue;
}
}
if (q.second.count("version")) {
if (!checkVersion(q.second.get<std::string>("version", ""))) {
continue;
}
}
ScheduledQuery query;
query.query = q.second.get<std::string>("query", "");
query.interval = q.second.get("interval", FLAGS_schedule_default_interval);
if (query.interval <= 0 || query.query.empty()) {
// Invalid pack query.
continue;
}
query.splayed_interval = restoreSplayedValue(q.first, query.interval);
query.options["snapshot"] = q.second.get<bool>("snapshot", false);
query.options["removed"] = q.second.get<bool>("removed", true);
schedule_[q.first] = query;
}
}
示例8: unSerialize
void DESFireKey::unSerialize(boost::property_tree::ptree& node)
{
Key::unSerialize(node);
d_keyType = static_cast<DESFireKeyType>(node.get_child("KeyType").get_value<unsigned int>());
d_key_version = node.get_child("KeyVersion").get_value<unsigned char>();
}
示例9: unSerialize
void UdpDataTransport::unSerialize(boost::property_tree::ptree& node)
{
d_ipAddress = node.get_child("IpAddress").get_value<std::string>();
d_port = node.get_child("Port").get_value<int>();
}
示例10: initialize
void Pack::initialize(const std::string& name,
const std::string& source,
const pt::ptree& tree) {
name_ = name;
source_ = source;
// Check the shard limitation, shards falling below this value are included.
if (tree.count("shard") > 0) {
shard_ = tree.get<size_t>("shard", 0);
}
// Check for a platform restriction.
platform_.clear();
if (tree.count("platform") > 0) {
platform_ = tree.get<std::string>("platform", "");
}
// Check for a version restriction.
version_.clear();
if (tree.count("version") > 0) {
version_ = tree.get<std::string>("version", "");
}
// Apply the shard, platform, and version checking.
// It is important to set each value such that the packs meta-table can report
// each of the restrictions.
if ((shard_ > 0 && shard_ < getMachineShard()) || !checkPlatform() ||
!checkVersion()) {
return;
}
discovery_queries_.clear();
if (tree.count("discovery") > 0) {
for (const auto& item : tree.get_child("discovery")) {
discovery_queries_.push_back(item.second.get_value<std::string>());
}
}
// Initialize a discovery cache at time 0.
discovery_cache_ = std::make_pair<size_t, bool>(0, false);
valid_ = true;
// If the splay percent is less than 1 reset to a sane estimate.
if (FLAGS_schedule_splay_percent <= 1) {
FLAGS_schedule_splay_percent = 10;
}
schedule_.clear();
if (tree.count("queries") == 0) {
// This pack contained no queries.
return;
}
// Iterate the queries (or schedule) and check platform/version/sanity.
for (const auto& q : tree.get_child("queries")) {
if (q.second.count("shard") > 0) {
auto shard = q.second.get<size_t>("shard", 0);
if (shard > 0 && shard < getMachineShard()) {
continue;
}
}
if (q.second.count("platform")) {
if (!checkPlatform(q.second.get<std::string>("platform", ""))) {
continue;
}
}
if (q.second.count("version")) {
if (!checkVersion(q.second.get<std::string>("version", ""))) {
continue;
}
}
ScheduledQuery query;
query.query = q.second.get<std::string>("query", "");
query.interval = q.second.get("interval", FLAGS_schedule_default_interval);
if (query.interval <= 0 || query.query.empty() || query.interval > 592200) {
// Invalid pack query.
VLOG(1) << "Query has invalid interval: " << q.first << ": "
<< query.interval;
continue;
}
query.splayed_interval = restoreSplayedValue(q.first, query.interval);
query.options["snapshot"] = q.second.get<bool>("snapshot", false);
query.options["removed"] = q.second.get<bool>("removed", true);
schedule_[q.first] = query;
}
}
示例11: read
void SceneObject::read(boost::property_tree::ptree pt){
using boost::property_tree::ptree;
if(pt.find("body") != pt.not_found())
body.read(pt.get_child("body"));
}
示例12: parseElement
void XSDSchemaParser::parseElement(const pt::ptree &elemTree)
{
std::string elementName = elemTree.get("<xmlattr>.name", "");
std::string className = elemTree.get("<xmlattr>.hpcc:class", "");
std::string category = elemTree.get("<xmlattr>.hpcc:category", "");
std::string displayName = elemTree.get("<xmlattr>.hpcc:displayName", "");
std::string typeName = elemTree.get("<xmlattr>.type", "");
unsigned minOccurs = elemTree.get("<xmlattr>.minOccurs", 1);
std::string maxOccursStr = elemTree.get("<xmlattr>.maxOccurs", "1");
unsigned maxOccurs = (maxOccursStr != "unbounded") ? stoi(maxOccursStr) : UINTMAX_MAX;
std::shared_ptr<SchemaItem> pConfigElement = std::make_shared<SchemaItem>(elementName, className, m_pSchemaItem);
pConfigElement->setProperty("displayName", displayName);
pConfigElement->setMinInstances(minOccurs);
pConfigElement->setMaxInstances(maxOccurs);
pConfigElement->setProperty("category", category);
pt::ptree childTree = elemTree.get_child("", pt::ptree());
// special case to set the root since the top level schema can't specify it
if (category == "root") // special case to set the root since the top level schema can't specify it
{
m_pSchemaItem->setProperty("name", elementName);
parseXSD(childTree);
}
else
{
//
// If a type is specified, then either it's a simple value type (which could be previously defined) for this element, or a named complex type.
if (!typeName.empty())
{
const std::shared_ptr<SchemaType> pSimpleType = m_pSchemaItem->getSchemaValueType(typeName, false);
if (pSimpleType != nullptr)
{
std::shared_ptr<SchemaValue> pCfgValue = std::make_shared<SchemaValue>(""); // no name value since it's the element's value
pCfgValue->setType(pSimpleType); // will throw if type is not defined
pConfigElement->setItemSchemaValue(pCfgValue);
}
else
{
std::shared_ptr<SchemaItem> pConfigType = m_pSchemaItem->getSchemaType(typeName, false);
if (pConfigType != nullptr)
{
//
// Insert into this config element the component defined data (attributes, references, etc.)
pConfigElement->insertSchemaType(pConfigType);
//
// Set element min/max instances to that defined by the component type def (ignore values parsed above)
pConfigElement->setMinInstances(pConfigType->getMinInstances());
pConfigElement->setMaxInstances(pConfigType->getMaxInstances());
//
// If a component, then set element data (allow overriding with locally parsed values)
if (pConfigType->getProperty("className") == "component")
{
pConfigElement->setProperty("name", (!elementName.empty()) ? elementName : pConfigType->getProperty("name"));
pConfigElement->setProperty("className", (!className.empty()) ? className : pConfigType->getProperty("className"));
pConfigElement->setProperty("category", (!category.empty()) ? category : pConfigType->getProperty("category"));
pConfigElement->setProperty("displayName", (!displayName.empty()) ? displayName : pConfigType->getProperty("displayName"));
pConfigElement->setProperty("componentName", pConfigType->getProperty("componentName"));
}
}
else
{
std::string msg = "Unable to find type " + typeName + " when parsing element " + elementName;
throw(ParseException(msg));
}
}
}
//
// Now, if there are children, create a parser and have at it
if (!childTree.empty())
{
std::shared_ptr<XSDSchemaParser> pXSDParaser = std::make_shared<XSDSchemaParser>(pConfigElement);
pXSDParaser->parseXSD(childTree);
}
//
// Add the element
m_pSchemaItem->addChild(pConfigElement);
}
}
示例13: parseComplexType
void XSDSchemaParser::parseComplexType(const pt::ptree &typeTree)
{
std::string complexTypeName = getXSDAttributeValue(typeTree, "<xmlattr>.name", false, "");
std::string className = typeTree.get("<xmlattr>.hpcc:class", "");
std::string catName = typeTree.get("<xmlattr>.hpcc:category", "");
std::string componentName = typeTree.get("<xmlattr>.hpcc:componentName", "");
std::string displayName = typeTree.get("<xmlattr>.hpcc:displayName", "");
if (!complexTypeName.empty())
{
if (!className.empty())
{
if (className == "component")
{
std::shared_ptr<SchemaItem> pComponent = std::make_shared<SchemaItem>(complexTypeName, "component", m_pSchemaItem);
pComponent->setProperty("category", catName);
pComponent->setProperty("componentName", componentName);
pComponent->setProperty("displayName", displayName);
pt::ptree componentTree = typeTree.get_child("", pt::ptree());
if (!componentTree.empty())
{
std::shared_ptr<XSDComponentParser> pComponentXSDParaser = std::make_shared<XSDComponentParser>(std::dynamic_pointer_cast<SchemaItem>(pComponent));
pComponentXSDParaser->parseXSD(typeTree);
m_pSchemaItem->addSchemaType(pComponent, complexTypeName);
}
else
{
throw(ParseException("Component definition empty: " + displayName));
}
}
else
{
throw(ParseException("Unrecognized class name for complex type: " + className));
}
}
//
// This is a complex type definition of just regular XSD statements, no special format. Create a parser and parse it
// and add it to the
else
{
std::shared_ptr<SchemaItem> pTypeItem = std::make_shared<SchemaItem>(complexTypeName, "", m_pSchemaItem);
pt::ptree childTree = typeTree.get_child("", pt::ptree());
if (!childTree.empty())
{
std::shared_ptr<XSDSchemaParser> pXSDParaser = std::make_shared<XSDSchemaParser>(pTypeItem);
pXSDParaser->parseXSD(childTree);
m_pSchemaItem->addSchemaType(pTypeItem, complexTypeName);
}
else
{
throw(ParseException("Complex type definition empty: " + displayName));
}
}
}
//
// Just a complexType delimiter, ignore and parse the children
else
{
parseXSD(typeTree.get_child("", pt::ptree()));
}
}
示例14: unSerialize
void SAMKeyStorage::unSerialize(boost::property_tree::ptree& node)
{
d_key_slot = node.get_child("KeySlot").get_value<unsigned char>();
}
示例15:
void Wiegand37WithFacilityFormat::unSerialize(boost::property_tree::ptree& node)
{
setFacilityCode(node.get_child("FacilityCode").get_value<unsigned short>());
setUid(node.get_child("Uid").get_value<unsigned long long>());
}