本文整理汇总了C++中ptree::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::begin方法的具体用法?C++ ptree::begin怎么用?C++ ptree::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ptree
的用法示例。
在下文中一共展示了ptree::begin方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invalid_argument
static utymap::GeoCoordinate parseCoordinate(const ptree &coordinate) {
if (std::distance(coordinate.begin(), coordinate.end())!=2)
throw std::invalid_argument("Invalid geometry.");
auto iter = coordinate.begin();
double longitude = iter->second.get_value<double>();
double latitude = (++iter)->second.get_value<double>();
return utymap::GeoCoordinate(latitude, longitude);
}
示例2: if
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;
}
示例3: parse
void scxml_parser::parse(const ptree &pt)
{
for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
if (it->first == "<xmlcomment>") ; // ignore comments
else if (it->first == "scxml") parse_scxml(it->second);
else cerr << "warning: unknown item '" << it->first << "'" << endl;
}
}
示例4: parse_attributes
void PipelineReaderXML::parse_attributes(map_t& attrs, const ptree& tree)
{
for (auto iter = tree.begin(); iter != tree.end(); ++iter)
{
std::string name = iter->first;
std::string value = tree.get<std::string>(name);
Utils::trim(value);
attrs[name] = value;
}
}
示例5: MakeFilters
std::vector<Filter> MakeFilters(const ptree& pt)
{
std::vector<Filter> filters;
for (auto it = pt.begin(); it != pt.end(); ++it)
{
if (it->first == "MessageFilter" ||
it->first == "ProcessFilter" ||
it->first == "Filter")
filters.push_back(MakeFilter(it->second));
}
return filters;
}
示例6:
boost::shared_ptr<scxml_parser::action> scxml_parser::parse_script(const ptree &pt)
{
boost::shared_ptr<action> ac = boost::make_shared<action>();
try {
ac->type = "script";
ac->attr["expr"] = pt.get_value<string>();
for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
if (it->first == "<xmlcomment>") ; // ignore comments
else cerr << "warning: unknown item '" << it->first << "' in <script>" << endl;
}
}
catch (ptree_error e) {
cerr << "error: action: " << e.what() << endl;
exit(1);
}
return ac;
}
示例7: parse_state
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);
}
}
示例8: parse_initial
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;
}
示例9: parse_scxml
void scxml_parser::parse_scxml(const ptree &pt)
{
try {
using namespace boost::algorithm;
const ptree &xmlattr = pt.get_child("<xmlattr>");
boost::optional<string> initial(xmlattr.get_optional<string>("initial"));
if(initial) split(m_scxml.initial.target, *initial, is_any_of(" "), token_compress_on);
if(m_scxml.initial.target.size() > 1) parallel_target_sizes.insert(m_scxml.initial.target.size());
m_scxml.name = xmlattr.get<string>("name", m_scxml.name);
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, boost::shared_ptr<state>());
else if (it->first == "history") parse_state(it->second, boost::shared_ptr<state>());
else if (it->first == "parallel") parse_parallel(it->second, boost::shared_ptr<state>());
else if (it->first == "initial") m_scxml.initial = parse_initial(it->second);
else cerr << "warning: unknown item '" << it->first << "' in <scxml>" << endl;
}
// if initial state is not set, use first state in document order
if(m_scxml.initial.target.empty()) {
if(m_scxml.states.size()) {
m_scxml.initial.target.push_back((*m_scxml.states.begin())->id);
}
else {
cerr << "error: could not set initial state" << endl;
exit(1);
}
}
}
catch (ptree_error e) {
cerr << "error: scxml: " << e.what() << endl;
exit(1);
}
}