/**
     * @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
0
파일: parts.cpp 프로젝트: Xerox16/Liero3D
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
0
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);
    }
  }
}