本文整理汇总了C++中boost::property_tree::ptree::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::empty方法的具体用法?C++ ptree::empty怎么用?C++ ptree::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::property_tree::ptree
的用法示例。
在下文中一共展示了ptree::empty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_ptree
void print_ptree(std::ostream& os, const boost::property_tree::ptree& pt, int depth)
{
typedef bp::ptree::const_iterator c_it;
if(pt.empty())
os << "'" << pt.data() << "'\n";
else
{
std::string pad("");
pad.assign(depth*4,' ');
++depth;
std::string pad2 = pad + " ";
if(is_list(pt))
{
os << "[\n";
for(c_it it=pt.begin(); it!=pt.end(); ++it)
{
os << pad2;
print_ptree(os, it->second, depth);
}
os << pad << "]\n";
}
else
{
os << "{\n";
for(c_it it=pt.begin(); it!=pt.end(); ++it)
{
os << pad2 << "'" << it->first << "': ";
print_ptree(os, it->second, depth);
}
os << pad << "}\n";
}
}
}
示例2: deserialize_json
bool deserialize_json (bool & upgraded, boost::property_tree::ptree & tree_a)
{
auto error (false);
if (!tree_a.empty ())
{
auto text_l (tree_a.get <std::string> ("thing"));
if (text_l == "junktest")
{
upgraded = true;
text_l = "changed";
tree_a.put ("thing", text_l);
}
if (text_l == "error")
{
error = true;
}
text = text_l;
}
else
{
upgraded = true;
text = "created";
tree_a.put ("thing", text);
}
return error;
}
示例3: genOSXPlistPrefValue
void genOSXPlistPrefValue(const pt::ptree& tree,
const Row& base,
unsigned int level,
QueryData& results) {
if (tree.empty()) {
Row r = base;
r["value"] = tree.data();
results.push_back(std::move(r));
// No more levels to parse.
return;
}
for (const auto& item : tree) {
Row r = base;
if (r["subkey"].size() > 0) {
r["subkey"] += '/';
if (item.first.size() == 0) {
r["subkey"] += std::to_string(level++);
}
}
r["subkey"] += item.first;
genOSXPlistPrefValue(item.second, r, level, results);
}
}
示例4: error
bool rai_daemon::daemon_config::deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
{
auto error (false);
try
{
if (!tree_a.empty ())
{
auto version_l (tree_a.get_optional <std::string> ("version"));
if (!version_l)
{
tree_a.put ("version", "1");
version_l = "1";
}
upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a);
rpc_enable = tree_a.get <bool> ("rpc_enable");
auto rpc_l (tree_a.get_child ("rpc"));
error |= rpc.deserialize_json (rpc_l);
auto & node_l (tree_a.get_child ("node"));
error |= node.deserialize_json (upgraded_a, node_l);
opencl_enable = tree_a.get <bool> ("opencl_enable");
auto & opencl_l (tree_a.get_child ("opencl"));
error |= opencl.deserialize_json (opencl_l);
}
else
{
upgraded_a = true;
serialize_json (tree_a);
}
}
catch (std::runtime_error const &)
{
error = true;
}
return error;
}
示例5: ParseUniprotPtree
size_t ProteinSequence::ParseUniprotPtree(const boost::property_tree::ptree& rt_tree) {
using namespace boost::property_tree;
if (rt_tree.empty())
return 0;
BOOST_FOREACH(const ptree::value_type& v, rt_tree) {
if (v.first == "accession") {
add_accession(v.second.data());
}
else if (v.first == "name") {
vector<string> tokens;
boost::split(tokens, v.second.data(), is_any_of("_"));
if (tokens.size() != 2)
cerr << "Warning: name tokens not equal to 2" << endl;
else {
set_name(tokens[0]);
set_species(tokens[1]);
}
}
else if (v.first == "reference") {
const ptree &ptree_citation = v.second.get_child("citation", EmptyPtree());
BOOST_FOREACH(const ptree::value_type& v2, ptree_citation) {
if (v2.first == "dbReference") {
string db = boost::to_upper_copy(v2.second.get("<xmlattr>.type", string()));
if (db == "PUBMED") {
int pmid = v2.second.get("<xmlattr>.id", -1);
if (pmid < 0)
cerr << "Warning: pmid not valid" << endl;
else
add_ref_pmid(pmid);
}
}
}
}
else if (v.first == "dbReference") {
string db = boost::to_upper_copy(v.second.get("<xmlattr>.type", string()));
if (db == "GO") {
string str_id = v.second.get("<xmlattr>.id", string());
size_t pos = str_id.rfind(":") + 1;
str_id = str_id.substr(pos);
if (str_id.empty()) {
cerr << "Warning: GO id is empty" << endl;
}
else {
ProteinSequence::GOType go;
BOOST_FOREACH(const ptree::value_type& v2, v.second) {
string type = v2.second.get("<xmlattr>.type", string());
if (type == "term")
go.term_ = v2.second.get("<xmlattr>.value", string());
else if (type == "evidence")
go.evidence_ = v2.second.get("<xmlattr>.value", string());
}
go.id_ = atoi(str_id.data());
add_go_term(go);
}
}
示例6:
extracted_ptree_iterator(const extracted_ptree& extracted_ptree,
const pqrs::string::replacement& replacement,
const boost::property_tree::ptree& pt) :
extracted_ptree_(extracted_ptree),
stack_size_(extracted_ptree.stack_.size() + 1)
{
if (! pt.empty()) {
extracted_ptree_.stack_.push(stack_data(pt, replacement));
extract_include_();
}
}
示例7: deserialize_json
bool deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
{
auto error (false);
if (!tree_a.empty ())
{
auto version_l (tree_a.get_optional<std::string> ("version"));
if (!version_l)
{
tree_a.put ("version", "1");
version_l = "1";
upgraded_a = true;
}
upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a);
auto wallet_l (tree_a.get<std::string> ("wallet"));
auto account_l (tree_a.get<std::string> ("account"));
auto & node_l (tree_a.get_child ("node"));
rpc_enable = tree_a.get<bool> ("rpc_enable");
auto & rpc_l (tree_a.get_child ("rpc"));
opencl_enable = tree_a.get<bool> ("opencl_enable");
auto & opencl_l (tree_a.get_child ("opencl"));
try
{
error |= wallet.decode_hex (wallet_l);
error |= account.decode_account (account_l);
error |= node.deserialize_json (upgraded_a, node_l);
error |= rpc.deserialize_json (rpc_l);
error |= opencl.deserialize_json (opencl_l);
if (wallet.is_zero ())
{
rai::random_pool.GenerateBlock (wallet.bytes.data (), wallet.bytes.size ());
upgraded_a = true;
}
}
catch (std::logic_error const &)
{
error = true;
}
}
else
{
serialize_json (tree_a);
upgraded_a = true;
}
return error;
}
示例8: printTree
void printTree (boost::property_tree::ptree &pt, int level) {
if (pt.empty()) {
std::cout << "\""<< pt.data()<< "\"";
} else {
if (level) std::cout << std::endl;
std::cout << indent(level) << "{" << std::endl;
for (boost::property_tree::ptree::iterator pos = pt.begin(); pos != pt.end();) {
std::cout << indent(level+1) << "\"" << pos->first << "\": ";
printTree(pos->second, level + 1);
++pos;
if (pos != pt.end()) {
std::cout << ",";
}
std::cout << std::endl;
}
std::cout << indent(level) << " }";
}
return;
}
示例9: drawSnake
void drawSnake(boost::property_tree::ptree &snakeData, std::unique_ptr<QPainter> &painter, std::unique_ptr<label> &l) {
if (snakeData.empty()) {
painter->fillRect(500, 0, 50, 500, Qt::darkGray);
}
else {
if (snakeData.get<std::string>("game_status") == "GAME OVER") {
QFont font;
font.setPixelSize(50);
font.setBold(true);
painter->setFont(font);
painter->drawText(snakeData.get<int>("table.width") * 2, snakeData.get<int>("table.height") * 2, "GAME OVER");
painter->drawText(snakeData.get<int>("table.width") * 2 + 60, snakeData.get<int>("table.height") * 2 + 50, "SCORE:");
painter->drawText(snakeData.get<int>("table.width") * 2 + 130, snakeData.get<int>("table.height") * 2 + 100, QString::number(snakeData.get<int>("game_score")));
painter->drawText(snakeData.get<int>("table.width") * 2, snakeData.get<int>("table.height") * 2 + 150, "F5 - New Game");
}
else {
if (l->direction == Direction::newGame)l->direction = Direction::right;
QFont font;
font.setPixelSize(10);
font.setBold(true);
painter->setFont(font);
painter->fillRect(0, 0, snakeData.get<int>("table.width") * 10, snakeData.get<int>("table.height") * 10, Qt::gray);
painter->drawPixmap(snakeData.get<int>("snakefood.x") * 10, snakeData.get<int>("snakefood.y") * 10, 10, 10, QPixmap("strawberry.png"));
painter->fillRect(snakeData.get<int>("table.width") * 10, 0, 50, snakeData.get<int>("table.height") * 10, Qt::darkGray);
painter->drawText(snakeData.get<int>("table.width") * 10 + 5, 10, "SCORE:");
painter->drawText(snakeData.get<int>("table.width") * 10 + 20, 10 + 20, QString::number(snakeData.get<int>("game_score")));
for (int j = 0; j < snakeData.get<int>("numberofsnakes"); j++) {
for (int i = 0; i < snakeData.get<int>("snakebody."+std::to_string(j)+".length"); i++) {
painter->fillRect(snakeData.get<int>("snakebody."+std::to_string(j)+".point." + std::to_string(i) + ".x") * 10, snakeData.get<int>("snakebody."+std::to_string(j)+".point." + std::to_string(i) + ".y") * 10, 10, 10, Qt::Dense2Pattern);
};
}
}
}
};
示例10: if
void
mergePropertyTrees (boost::property_tree::ptree &ptMerged,
const boost::property_tree::ptree &ptSecond, int level )
{
// Value or object or array
if (level > 0 && ptSecond.empty() ) {
// Copy value
ptMerged = ptSecond;
} else if (level > 0 && ptSecond.count (std::string() ) == ptSecond.size() ) {
// Copy array
ptMerged = ptSecond;
} else {
auto it = ptSecond.begin();
for (; it != ptSecond.end(); ++it) {
boost::property_tree::ptree child = ptMerged.get_child (it->first.data(),
boost::property_tree::ptree() );
mergePropertyTrees (child, it->second, level + 1);
ptMerged.erase (it->first.data() );
ptMerged.add_child (it->first.data(), child);
}
}
}
示例11: setup
void utility::setup(const boost::property_tree::ptree &ptree) {
if (!ptree.empty()) BOOST_THROW_EXCEPTION(error("not implemented"));
}