本文整理汇总了C++中boost::property_tree::ptree::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::size方法的具体用法?C++ ptree::size怎么用?C++ ptree::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::property_tree::ptree
的用法示例。
在下文中一共展示了ptree::size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PropertyTreeValue
/**
* @brief Construct a PropertyTreeValue from a tree object
*
* This function will determine whether the tree object represents an array
* or an object by scanning the key names for any non-empty strings. In the
* case of an empty tree object, it is not possible to determine whether it
* is an array or an object, so it will be treated as an array by default.
* Empty arrays are considered equal to empty objects when compared using
* non-strict type comparison. Empty strings will also be stored as empty
* arrays.
*
* @param tree Tree object to be wrapped
*/
PropertyTreeValue(const boost::property_tree::ptree &tree)
{
if (tree.data().empty()) { // No string content
if (tree.size() == 0) { // No children
array = tree; // Treat as empty array
} else {
bool isArray = true;
boost::property_tree::ptree::const_iterator itr;
for (itr = tree.begin(); itr != tree.end(); itr++) {
if (!itr->first.empty()) {
isArray = false;
break;
}
}
if (isArray) {
array = tree;
} else {
object = tree;
}
}
} else {
value = tree.data();
}
}
示例2: getVectorFromJsonArray
core::vector3df getVectorFromJsonArray(const boost::property_tree::ptree& tree) {
//if position array has correct size, fetch the three elements via incrementing iterator to first element two times
if(tree.size() == 3) {
auto begin = tree.begin();
float x = (begin++)->second.get_value<float>();
float y = (begin++)->second.get_value<float>();
float z = begin->second.get_value<float>();
return core::vector3df(x,y,z);
} else {
return core::vector3df();
}
}
示例3: 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);
}
}
}