本文整理汇总了C++中ptree类的典型用法代码示例。如果您正苦于以下问题:C++ ptree类的具体用法?C++ ptree怎么用?C++ ptree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ptree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: collect_attributes
void PipelineReaderXML::parseElement_Pipeline(const ptree& tree)
{
Stage *stage = NULL;
Stage *writer = NULL;
map_t attrs;
collect_attributes(attrs, tree);
std::string version = "";
if (attrs.count("version"))
version = attrs["version"];
if (version != "1.0")
throw pdal_error("PipelineReaderXML: unsupported pipeline xml version");
for (auto iter = tree.begin(); iter != tree.end(); ++iter)
{
const std::string& name = iter->first;
const ptree subtree = iter->second;
if (name == "Reader" || name == "Filter" )
{
stage = parseElement_anystage(name, subtree);
}
else if (name == "Writer")
{
writer = parseElement_Writer(subtree);
}
else if (name == "<xmlattr>")
{
// ignore it, already parsed
}
else
{
throw pdal_error("PipelineReaderXML: xml reader invalid child of "
"ReaderPipeline element");
}
}
if (writer && stage)
{
throw pdal_error("PipelineReaderXML: extra nodes at front of "
"writer pipeline");
}
}
开发者ID:Rafaelaniemann,项目名称:PDAL,代码行数:44,代码来源:PipelineReaderXML.cpp
示例2: catch
///////////////////////////////////////////////////////////////////////////////
/// @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;
}
}
开发者ID:Annovae,项目名称:FREEDM,代码行数:50,代码来源:CMessage.cpp
示例3: process_pde_text
void process_pde_text(PdeTextP text, ptree& node) {
PdfTextState ts;
switch (text->GetType())
{
case kPdeText:
{
node.put("type", "text_paragraph");
std::wstring s;
s.resize(text->GetText(nullptr, 0));
text->GetText((wchar_t*)s.c_str(), s.size());
node.put("text", w2utf8(s.c_str()));
text->GetTextState(&ts);
auto num_lines = text->GetNumTextLines();
for (auto i = 0; i < num_lines; i++) {
ptree line_node;
PdeTextLineP text_line = text->GetTextLine(i);
process_pde_element((PdeElementP)text_line, line_node);
node.add_child("element", line_node);
}
}
break;
case kPdeTextLine:
{
PdeTextLineP text_line = (PdeTextLine*)text;
node.put("type", "text_line");
std::wstring s;
s.resize(text_line->GetText(nullptr, 0));
text_line->GetText((wchar_t*)s.c_str(), s.size());
node.put("text", w2utf8(s.c_str()));
text_line->GetTextState(&ts);
auto num_word = text_line->GetNumWords();
for (auto i = 0; i < num_word; i++) {
ptree word_node;
PdeWordP text_word = text_line->GetWord(i);
process_pde_element((PdeElementP)text_word, word_node);
node.add_child("element", word_node);
}
}
break;
case kPdeWord:
{
PdeWordP word = (PdeWord*)text;
node.put("type", "text_word");
std::wstring s;
s.resize(word->GetText(nullptr, 0));
word->GetText((wchar_t*)s.c_str(), s.size());
node.put("text", w2utf8(s.c_str()));
word->GetTextState(&ts);
}
break;
}
process_pdf_text_state(ts, node);
}
开发者ID:malcolmgreaves,项目名称:pdf2json,代码行数:54,代码来源:pdf_to_json.cpp
示例4: if
gradient::gradient(element* doc, const ptree& pt)
: core_attribs(pt),
coord_system_(GradientCoordSystem::OBJECT_BOUNDING_BOX),
spread_(GradientSpreadMethod::PAD)
{
// Process attributes
auto attributes = pt.get_child_optional("<xmlattr>");
if(attributes) {
auto xlink_href = attributes->get_child_optional("xlink:xref");
auto transforms = attributes->get_child_optional("gradientTransforms");
auto units = attributes->get_child_optional("gradientUnits");
auto spread = attributes->get_child_optional("spreadMethod");
if(transforms) {
transforms_ = transform::factory(transforms->data());
}
if(xlink_href) {
xlink_href_ = xlink_href->data();
}
if(units) {
std::string csystem = units->data();
if(csystem == "userSpaceOnUse") {
coord_system_ = GradientCoordSystem::USERSPACE_ON_USE;
} else if(csystem =="objectBoundingBox") {
coord_system_ = GradientCoordSystem::OBJECT_BOUNDING_BOX;
} else {
ASSERT_LOG(false, "Unrecognised 'gradientUnits' value: " << csystem);
}
}
if(spread) {
std::string spread_val = units->data();
if(spread_val == "pad") {
spread_ = GradientSpreadMethod::PAD;
} else if(spread_val =="reflect") {
spread_ = GradientSpreadMethod::REFLECT;
} else if(spread_val =="repeat") {
spread_ = GradientSpreadMethod::REPEAT;
} else {
ASSERT_LOG(false, "Unrecognised 'spreadMethod' value: " << spread_val);
}
}
// Process child elements
for(auto& v : pt) {
if(v.first == "stop") {
stops_.emplace_back(new gradient_stop(doc, v.second));
} else if(v.first == "<xmlattr>") {
// ignore
} else if(v.first == "<xmlcomment>") {
// ignore
} else {
ASSERT_LOG(false, "unexpected child element in gradient stop list: " << v.first);
}
}
}
}
开发者ID:AsKorysti,项目名称:anura,代码行数:56,代码来源:svg_gradient.cpp
示例5: paramFromPtree
bool ConfigTree::paramFromPtree(ptree fromPtree, ConfigParameter &toParam)
{
CONFIGSYS_DEBUG_CALLS;
std::string typStr = fromPtree.get<std::string>("type");
value_type vt = stringToValueType(typStr);
toParam = ConfigParameter(vt);
toParam.setDescription(fromPtree.get("desc", ""));
std::string modStr = fromPtree.get("modified", "false");
toParam.setModified(modStr.compare("true") == 0);
std::string lockStr = fromPtree.get("locked", "false");
toParam.setLocked(lockStr.compare("true") == 0);
return addPtreeValueandRangeToParam(fromPtree, toParam);
}
开发者ID:NUbots,项目名称:robocup,代码行数:19,代码来源:ConfigTree.cpp
示例6: writeToPropertyTree
void CompShapePolygon::writeToPropertyTree(ptree& propTree) const
{
for ( size_t i = 0; i < getVertexCount(); ++i )
{
ptree vertexPropTree;
vertexPropTree.add("x", m_vertices[i].x);
vertexPropTree.add("y", m_vertices[i].y);
propTree.add_child("polygon.vertex", vertexPropTree);
}
}
开发者ID:zommerfelds,项目名称:astroattack,代码行数:10,代码来源:CompShape.cpp
示例7: foreach
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) );
}
}
开发者ID:zommerfelds,项目名称:astroattack,代码行数:10,代码来源:CompShape.cpp
示例8: api_call
ptree api_call(const Remote &r, const String &api, ptree request)
{
request.put("auth.user", r.user);
request.put("auth.token", r.token);
HttpRequest req = httpSettings;
req.type = HttpRequest::POST;
req.url = r.url + "/api/" + api;
req.data = ptree2string(request);
auto resp = url_request(req);
auto ret = string2ptree(resp.response);
if (resp.http_code != 200)
{
auto e = ret.get<String>("error", "");
throw std::runtime_error(e);
}
return string2ptree(resp.response);
}
开发者ID:cppan,项目名称:cppan,代码行数:19,代码来源:api.cpp
示例9: unparseElements
template<typename T> static void
unparseElements(ptree& tree, const std::string& key, const T& elements)
{
if (elements.size()) {
ptree list;
for (const auto& elem : elements)
list.push_back({"", unparse(elem)});
tree.add_child(key, list);
}
}
开发者ID:hartenfels,项目名称:Cpp101,代码行数:10,代码来源:Persistence.cpp
示例10: createSprite
boost::shared_ptr<T> createSprite(ptree params = ptree())
{
boost::shared_ptr<T> newSprite(new T(graphicsMgr));
if(!params.empty())
newSprite->set(params);
this->addSprite(newSprite);
return newSprite;
};
开发者ID:iliis,项目名称:Anathea,代码行数:10,代码来源:sprite_mgr.hpp
示例11: writeSelf
void MultiMatcher::writeSelf(ptree& writeTo) const {
writeTo.put(OPERATE_MODE_KEY,OPERATE_MODE_MAP_NAME[m_operateMode]);
int index=0;
ptree values;
for(auto &child : m_values){
ptree childTree;
write(child,childTree);
values.add_child(MATCHER_KEY,childTree);
}
writeTo.put_child(VALUES_KEY,values);
}
开发者ID:comicfans,项目名称:UnifiedKeyboardCombo,代码行数:19,代码来源:MultiMatcher.cpp
示例12: initial
void scxml_parser::parse_state(const ptree &pt, const boost::shared_ptr<state> &parent)
{
try {
using namespace boost::algorithm;
const ptree &xmlattr = pt.get_child("<xmlattr>");
boost::shared_ptr<state> st = boost::make_shared<state>();
st->id = xmlattr.get<string>("id");
if(parent) {
using_compound = true;
st->parent = parent;
}
boost::optional<string> initial(xmlattr.get_optional<string>("initial"));
if(initial) split(st->initial.target, *initial, is_any_of(" "), token_compress_on);
if(st->initial.target.size() > 1) parallel_target_sizes.insert(st->initial.target.size());
st->type = xmlattr.get_optional<string>("type");
m_scxml.states.push_back(st);
state_list::iterator state_i = --m_scxml.states.end();
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 == "state") parse_state(it->second, st);
else if (it->first == "history") parse_state(it->second, st);
else if (it->first == "parallel") parse_parallel(it->second, st);
else if (it->first == "transition") state_i->get()->transitions.push_back(parse_transition(it->second));
else if (it->first == "onentry") state_i->get()->entry_actions = parse_entry(it->second);
else if (it->first == "onexit") state_i->get()->exit_actions = parse_entry(it->second);
else if (it->first == "initial") state_i->get()->initial = parse_initial(it->second);
else cerr << "warning: unknown item '" << it->first << "' in <state>" << endl;
}
// if initial state is not set, use first state in document order
// if parent is parallel put all states in initial
if(parent && (parent->initial.target.empty() || (parent->type && *parent->type == "parallel"))) {
parent->initial.target.push_back(st->id);
}
}
catch (ptree_error e) {
cerr << "error: state: " << e.what() << endl;
exit(1);
}
}
开发者ID:Kampbell,项目名称:scxmlcc,代码行数:42,代码来源:scxml_parser.cpp
示例13: write
void ProperyTreeUtils::write(ptree & properties, const std::vector<uint8_t> & data) {
ptree propertiesData {};
for(const uint8_t & value: data){
ptree propertyValue {boost::lexical_cast<std::string>((int)value)};
propertiesData.push_back({DATA_VALUE_NAME, propertyValue});
}
properties.put_child(DATA_NAME, propertiesData);
}
开发者ID:paoloach,项目名称:zdomus,代码行数:11,代码来源:ProperyTreeUtils.cpp
示例14: readScriptObjectNode
/*
<scriptComponent>
<scriptObject constructor="addPlayer" destructor="removePlayer" />
<scriptData actorType="player"/>
</scriptComponent>
*/
bool ScriptComponent::vInit(const ptree componentNode) {
optional<const ptree&> optScriptObject = componentNode.get_child_optional(SCRIPT_OBJECT_NODE_NAME);
if (optScriptObject.is_initialized()) {
bool result = readScriptObjectNode(optScriptObject.get());
if (!result) {
return false;
}
}
optional<const ptree&> optScriptData = componentNode.get_child_optional(SCRIPT_DATA_NODE_NAME);
if (optScriptData.is_initialized()) {
bool result = readScriptDataNode(optScriptData.get());
if (!result) {
return false;
}
}
return true;
};
开发者ID:krzy4ztof,项目名称:Main,代码行数:26,代码来源:ScriptComponent.cpp
示例15: parseJsonAndGetChat
Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const {
Chat::Ptr result(new Chat);
result->id = data.get<int64_t>("id");
string type = data.get<string>("type");
if (type == "private") {
result->type = Chat::Type::Private;
} else if (type == "group") {
result->type = Chat::Type::Group;
} else if (type == "supergroup") {
result->type = Chat::Type::Supergroup;
} else if (type == "channel") {
result->type = Chat::Type::Channel;
}
result->title = data.get("title", "");
result->username = data.get("username", "");
result->firstName = data.get<string>("first_name", "");
result->lastName = data.get("last_name", "");
return result;
}
开发者ID:flode,项目名称:tgbot-cpp,代码行数:20,代码来源:TgTypeParser.cpp
示例16: MakeFilter
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;
}
开发者ID:rkrijnen,项目名称:DebugViewPP,代码行数:11,代码来源:LogFilter.cpp
示例17: loadSigmoidParamsFromMatlab
shared_ptr<ProbabilisticWvmClassifier> ProbabilisticWvmClassifier::load(const ptree& subtree)
{
pair<double, double> sigmoidParams = loadSigmoidParamsFromMatlab(subtree.get<string>("thresholdsFile"));
// Load the detector and thresholds:
shared_ptr<WvmClassifier> wvm = WvmClassifier::loadFromMatlab(subtree.get<string>("classifierFile"), subtree.get<string>("thresholdsFile"));
shared_ptr<ProbabilisticWvmClassifier> pwvm = make_shared<ProbabilisticWvmClassifier>(wvm, sigmoidParams.first, sigmoidParams.second);
pwvm->getWvm()->setLimitReliabilityFilter(subtree.get("threshold", 0.0f));
return pwvm;
}
开发者ID:HVisionSensing,项目名称:FeatureDetection,代码行数:11,代码来源:ProbabilisticWvmClassifier.cpp
示例18: setLocalGravitationPoint
void CompPhysics::loadFromPropertyTree(const ptree& propTree)
{
float linearDamping = propTree.get("damping.linear", 0.0f);
float angularDamping = propTree.get("damping.angular", 0.0f);
bool fixedRotation = propTree.get("isFixedRotation", false);
bool isBullet = propTree.get("isBullet", false);
Vector2D gravitationPoint;
gravitationPoint.x = propTree.get("gravitationPoint.x", 0.0f);
gravitationPoint.y = propTree.get("gravitationPoint.y", 0.0f);
BodyDef body_def;
body_def.angularDamping = angularDamping;
body_def.fixedRotation = fixedRotation;
body_def.bullet = isBullet;
body_def.linearDamping = linearDamping;
setLocalGravitationPoint(gravitationPoint);
m_shapeInfos.clear();
foreach(const ptree::value_type &v, propTree)
{
if (v.first != "shape")
continue;
const ptree& shapeProps = v.second;
std::string shapeName = shapeProps.get<std::string>("comp_id");
float density = shapeProps.get("density", 0.0f);
float friction = shapeProps.get("friction", 0.0f);
float restitution = shapeProps.get("restitution", 0.0f);
bool isSensor = shapeProps.get("isSensor", false);
addShapeDef(boost::make_shared<ShapeDef>(shapeName, density, friction, restitution, isSensor));
}
setBodyDef(body_def);
}
开发者ID:zommerfelds,项目名称:astroattack,代码行数:41,代码来源:CompPhysics.cpp
示例19: ptree
bool ConfigTree::ptreeFromParam(ConfigParameter fromParam, ptree &toPtree)
{
CONFIGSYS_DEBUG_CALLS;
toPtree = ptree();
toPtree.put("desc", fromParam.getDescription());
std::string modStr = (fromParam.isModified())? "true" : "false";
toPtree.put("modified", modStr);
std::string lockStr = (fromParam.isLocked())? "true" : "false";
toPtree.put("locked", lockStr);
value_type vt = fromParam.getType();
std::string typStr = makeValueTypeString(vt);
toPtree.put("type", typStr);
return addParamValueandRangeToPtree(fromParam, toPtree);
}
开发者ID:NUbots,项目名称:robocup,代码行数:21,代码来源:ConfigTree.cpp
示例20: if
scxml_parser::transition scxml_parser::parse_initial(const ptree &pt)
{
scxml_parser::transition initial;
initial.event = "initial";
try {
for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
if (it->first == "<xmlcomment>") ; // ignore comments
else if (it->first == "transition") initial = *parse_transition(it->second);
else cerr << "warning: unknown item '" << it->first << "' in <initial>" << endl;
}
}
catch (ptree_error e) {
cerr << "error: initial: " << e.what() << endl;
exit(1);
}
return initial;
}
开发者ID:Kampbell,项目名称:scxmlcc,代码行数:21,代码来源:scxml_parser.cpp
注:本文中的ptree类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论