本文整理汇总了C++中Ptree::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptree::push_back方法的具体用法?C++ Ptree::push_back怎么用?C++ Ptree::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ptree
的用法示例。
在下文中一共展示了Ptree::push_back方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_xml_node
void read_xml_node( pugi::xml_node node, Ptree &pt, int flags)
{
typedef typename Ptree::key_type::value_type Ch;
switch ( node.type() )
{
case pugi::node_element:
{
Ptree &tmp = pt.push_back(std::make_pair( node.name(), Ptree()))->second;
for ( pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute() )
tmp.put( xmlattr<Ch>() + "." + attr.name(), attr.value());
for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling())
read_xml_node(child, tmp, flags);
}
break;
case pugi::node_pcdata:
{
if (flags & no_concat_text)
pt.push_back(std::make_pair(xmltext<Ch>(), Ptree( node.value() )));
else
pt.data() += node.value();
}
break;
case pugi::node_comment:
{
if (!(flags & no_comments))
pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree( node.value() )));
}
break;
default:
// skip other types
break;
}
}
示例2: read_xml_node
void read_xml_node(detail::pdalboostrapidxml::xml_node<Ch> *node,
Ptree &pt, int flags)
{
using namespace detail::pdalboostrapidxml;
switch (node->type())
{
// Element nodes
case node_element:
{
// Create node
Ptree &pt_node = pt.push_back(std::make_pair(node->name(),
Ptree()))->second;
// Copy attributes
if (node->first_attribute())
{
Ptree &pt_attr_root = pt_node.push_back(
std::make_pair(xmlattr<typename Ptree::key_type>(), Ptree()))->second;
for (xml_attribute<Ch> *attr = node->first_attribute();
attr; attr = attr->next_attribute())
{
Ptree &pt_attr = pt_attr_root.push_back(
std::make_pair(attr->name(), Ptree()))->second;
pt_attr.data() = typename Ptree::key_type(attr->value(), attr->value_size());
}
}
// Copy children
for (xml_node<Ch> *child = node->first_node();
child; child = child->next_sibling())
read_xml_node(child, pt_node, flags);
}
break;
// Data nodes
case node_data:
case node_cdata:
{
if (flags & no_concat_text)
pt.push_back(std::make_pair(xmltext<typename Ptree::key_type>(),
Ptree(node->value())));
else
pt.data() += typename Ptree::key_type(node->value(), node->value_size());
}
break;
// Comment nodes
case node_comment:
{
if (!(flags & no_comments))
pt.push_back(std::make_pair(xmlcomment<typename Ptree::key_type>(),
Ptree(typename Ptree::key_type(node->value(), node->value_size()))));
}
break;
default:
// Skip other node types
break;
}
}
示例3: operator
void operator()(Ch) const
{
if (c.stack.empty())
c.stack.push_back(&c.root);
else
{
Ptree *parent = c.stack.back();
Ptree *child = &parent->push_back(std::make_pair(c.name, Ptree()))->second;
c.stack.push_back(child);
c.name.clear();
}
}
示例4: read_ini
void read_ini(std::basic_istream<
typename Ptree::key_type::value_type> &stream,
Ptree &pt)
{
typedef typename Ptree::key_type::value_type Ch;
typedef std::basic_string<Ch> Str;
const Ch semicolon = stream.widen(';');
const Ch hash = stream.widen('#');
const Ch lbracket = stream.widen('[');
const Ch rbracket = stream.widen(']');
Ptree local;
unsigned long line_no = 0;
Ptree *section = 0;
Str line;
// For all lines
while (stream.good())
{
// Get line from stream
++line_no;
std::getline(stream, line);
if (!stream.good() && !stream.eof())
BOOST_PROPERTY_TREE_THROW(ini_parser_error(
"read error", "", line_no));
// If line is non-empty
line = property_tree::detail::trim(line, stream.getloc());
if (!line.empty())
{
// Comment, section or key?
if (line[0] == semicolon || line[0] == hash)
{
// Ignore comments
}
else if (line[0] == lbracket)
{
// If the previous section was empty, drop it again.
if (section && section->empty())
local.pop_back();
typename Str::size_type end = line.find(rbracket);
if (end == Str::npos)
BOOST_PROPERTY_TREE_THROW(ini_parser_error(
"unmatched '['", "", line_no));
Str key = property_tree::detail::trim(
line.substr(1, end - 1), stream.getloc());
if (local.find(key) != local.not_found())
BOOST_PROPERTY_TREE_THROW(ini_parser_error(
"duplicate section name", "", line_no));
section = &local.push_back(
std::make_pair(key, Ptree()))->second;
}
else
{
Ptree &container = section ? *section : local;
typename Str::size_type eqpos = line.find(Ch('='));
if (eqpos == Str::npos)
BOOST_PROPERTY_TREE_THROW(ini_parser_error(
"'=' character not found in line", "", line_no));
if (eqpos == 0)
BOOST_PROPERTY_TREE_THROW(ini_parser_error(
"key expected", "", line_no));
Str key = property_tree::detail::trim(
line.substr(0, eqpos), stream.getloc());
Str data = property_tree::detail::trim(
line.substr(eqpos + 1, Str::npos), stream.getloc());
if (container.find(key) != container.not_found())
BOOST_PROPERTY_TREE_THROW(ini_parser_error(
"duplicate key name", "", line_no));
container.push_back(std::make_pair(key, Ptree(data)));
}
}
}
// If the last section was empty, drop it again.
if (section && section->empty())
local.pop_back();
// Swap local ptree with result ptree
pt.swap(local);
}