本文整理汇总了C++中Ptree::put方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptree::put方法的具体用法?C++ Ptree::put怎么用?C++ Ptree::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ptree
的用法示例。
在下文中一共展示了Ptree::put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: get_test_ptree
Ptree get_test_ptree()
{
using namespace boost::property_tree;
typedef typename Ptree::key_type::value_type Ch;
Ptree pt;
pt.put_value(detail::widen<Ch>("data0"));
pt.put(detail::widen<Ch>("key1"), detail::widen<Ch>("data1"));
pt.put(detail::widen<Ch>("key1.key"), detail::widen<Ch>("data2"));
pt.put(detail::widen<Ch>("key2"), detail::widen<Ch>("data3"));
pt.put(detail::widen<Ch>("key2.key"), detail::widen<Ch>("data4"));
return pt;
}