本文整理汇总了C++中Ptree::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptree::swap方法的具体用法?C++ Ptree::swap怎么用?C++ Ptree::swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ptree
的用法示例。
在下文中一共展示了Ptree::swap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_xml_internal
void read_xml_internal(std::basic_istream<typename Ptree::key_type::value_type> &stream,
Ptree &pt,
int flags,
const std::string &filename)
{
typedef typename Ptree::key_type::value_type Ch;
// Create and load document from stream
stream.unsetf(std::ios::skipws);
if (!stream.good())
throw xml_parser_error("read error", filename, 0);
std::vector<Ch> buf;
std::copy(std::istream_iterator<Ch>(stream), std::istream_iterator<Ch>(), std::back_inserter(buf));
buf.push_back(0); // zero-terminate
unsigned int pugi_flags = pugi::parse_w3c;
if ( flags & no_comments )
pugi_flags = pugi_flags & ~pugi::parse_comments;
pugi::xml_parser parser(&buf[0], pugi_flags);
pugi::xml_node doc = parser.document();
// Create ptree from nodes
Ptree local;
for ( pugi::xml_node child = doc.first_child(); child; child = child.next_sibling())
read_xml_node( child, local, flags );
// Swap local and result ptrees
pt.swap(local);
}
示例2: read_cmdline
void read_cmdline(int argc,
typename Ptree::char_type *argv[],
const std::basic_string<typename Ptree::char_type> &metachars,
Ptree &pt)
{
typedef typename Ptree::char_type Ch;
typedef std::basic_string<Ch> Str;
Ptree local;
// For all arguments
for (int i = 0; i < argc; ++i)
{
Str text = detail::trim<Ch>(argv[i]);
if (!text.empty())
if (metachars.find(text[0]) != Str::npos)
{
if (text.size() == 1)
{
Ptree &child = local.put(text, Str());
Str key;
if (child.size() < 10)
key.push_back(typename Ptree::char_type('0' + child.size()));
child.push_back(std::make_pair(key, Ptree(child.data())));
}
else if (text.size() == 2)
{
Ptree &child = local.put(text.substr(1, 1), Str());
Str key;
if (child.size() < 10)
key.push_back(typename Ptree::char_type('0' + child.size()));
child.push_back(std::make_pair(key, Ptree(child.data())));
}
else
{
Ptree &child = local.put(text.substr(1, 1), detail::trim<Ch>(text.substr(2, Str::npos)));
Str key;
if (child.size() < 10)
key.push_back(typename Ptree::char_type('0' + child.size()));
child.push_back(std::make_pair(key, Ptree(child.data())));
}
}
else
{
Ptree &child = local.put(Str(), detail::trim<Ch>(text));
Str key;
if (child.size() < 10)
key.push_back(typename Ptree::char_type('0' + child.size()));
child.push_back(std::make_pair(key, Ptree(child.data())));
}
}
// Swap local and pt
pt.swap(local);
}
示例3: read_xml_internal
void read_xml_internal(std::basic_istream<
typename Ptree::key_type::value_type> &stream,
Ptree &pt,
int flags,
const std::string &filename)
{
typedef typename Ptree::key_type::value_type Ch;
using namespace detail::pdalboostrapidxml;
// Load data into vector
stream.unsetf(std::ios::skipws);
std::vector<Ch> v(std::istreambuf_iterator<Ch>(stream.rdbuf()),
std::istreambuf_iterator<Ch>());
if (!stream.good())
BOOST_PROPERTY_TREE_THROW(
xml_parser_error("read error", filename, 0));
v.push_back(0); // zero-terminate
try {
// Parse using appropriate flags
const int f_tws = parse_normalize_whitespace
| parse_trim_whitespace;
const int f_c = parse_comment_nodes;
// Some compilers don't like the bitwise or in the template arg.
const int f_tws_c = parse_normalize_whitespace
| parse_trim_whitespace
| parse_comment_nodes;
xml_document<Ch> doc;
if (flags & no_comments) {
if (flags & trim_whitespace)
doc.BOOST_NESTED_TEMPLATE parse<f_tws>(&v.front());
else
doc.BOOST_NESTED_TEMPLATE parse<0>(&v.front());
} else {
if (flags & trim_whitespace)
doc.BOOST_NESTED_TEMPLATE parse<f_tws_c>(&v.front());
else
doc.BOOST_NESTED_TEMPLATE parse<f_c>(&v.front());
}
// Create ptree from nodes
Ptree local;
for (xml_node<Ch> *child = doc.first_node();
child; child = child->next_sibling())
read_xml_node(child, local, flags);
// Swap local and result ptrees
pt.swap(local);
} catch (parse_error &e) {
long line = static_cast<long>(
std::count(&v.front(), e.where<Ch>(), Ch('\n')) + 1);
BOOST_PROPERTY_TREE_THROW(
xml_parser_error(e.what(), filename, line));
}
}
示例4: read_info
void read_info(const std::string &filename, Ptree &pt,
const std::locale &loc = std::locale())
{
std::basic_ifstream<typename Ptree::key_type::value_type>
stream(filename.c_str());
if (!stream) {
BOOST_PROPERTY_TREE_THROW(info_parser_error(
"cannot open file for reading", filename, 0));
}
stream.imbue(loc);
Ptree local;
read_info_internal(stream, local, filename, 0);
pt.swap(local);
}
示例5: read_json_internal
void read_json_internal(
std::basic_istream<typename Ptree::key_type::value_type> &stream,
Ptree &pt, const std::string &filename)
{
typedef typename Ptree::key_type::value_type char_type;
typedef standard_callbacks<Ptree> callbacks_type;
typedef detail::encoding<char_type> encoding_type;
typedef std::istreambuf_iterator<char_type> iterator;
callbacks_type callbacks;
encoding_type encoding;
detail::parser<callbacks_type, encoding_type, iterator, iterator>
parser(callbacks, encoding);
parser.set_input(filename,
boost::make_iterator_range(iterator(stream), iterator()));
parser.parse_value();
parser.finish();
pt.swap(callbacks.output());
}
示例6: 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);
}
示例7: read_info
void read_info(typename Ptree::BOOST_NESTED_TEMPLATE for_char<Ch>::basic_istream &stream, Ptree &pt)
{
Ptree local;
read_info_internal(stream, local, typename Ptree::string_type(), 0);
pt.swap(local);
}