示例#1
0
void Settings::merge(const boost::property_tree::ptree& from,
                     boost::property_tree::ptree& to,
                     bool overwrite)
{
    // Is this a single value or a subtree?
    if (!from.data().empty()) {
        // Single value
        if (overwrite || to.data().empty()) {
            to.put_value(from.data());
        }
        return;
    }

    // Subtree
    for (const auto& fromEntry : from) {
        // Does the key exist in the destination?
        auto toIt = to.find(fromEntry.first);
        if (toIt == to.not_found()) {
            ptree::ptree child;

            // Recurse into the new child
            merge(fromEntry.second, child, overwrite);

            // Create a path object because ptree uses '.' as a path delimiter
            // when strings are used
            ptree::ptree::path_type treePath = createPath(fromEntry.first);
            to.add_child(treePath, child);
        } else {
            // Recurse into the subtrees
            merge(fromEntry.second, toIt->second, overwrite);
        }
    }
}
    /**
     * @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();
        }
    }
void updateOnly(boost::property_tree::ptree &dest, bool ignoreEmptyUpdates, const boost::property_tree::ptree::path_type &childPath, const boost::property_tree::ptree &child) {
    if(ignoreEmptyUpdates && (child.data().empty() || child.data().find_first_not_of(" \n\t\r") == std::string::npos)) return;
    if(!dest.get_optional<std::string>(childPath)) {
        throw PropertyTree::KeyNotFoundException(std::string("Could not find the destination '") + childPath.dump() + "' to update with '" + child.data() + "'.");
    }
    dest.put(childPath, child.data());
}
示例#4
0
int ParallelFilter::handleConfigItem(const std::string& confFile,
				     const boost::property_tree::ptree::const_iterator& it)
{
    BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":: "<< type() << " " << it->first ;

    cout << "PF::handle "  << it->first << endl;
    if (it->first == "parallelFilter") {
	// recurse
 	return loadConfig(confFile, it->second.begin(), it->second.end());
    } else if (it->first == "thread") {
	cout << "PF::THREAD FOUND!"<< endl;
	Filter* f;
	if ( it->second.size() > 1 
	     ) {
	    // instantiate a filterbank
	    FilterBank* fb = new FilterBank();

	    fb->bank(NULL);
	    fb->loadConfig( it->second );
	    
	    f=fb;
	} else if (it->second.begin()->first == "filterGroup") {
	    // instantiate a filterbank
	    FilterBank* fb = new FilterBank();
	    const boost::property_tree::ptree pt = it->second.begin()->second;

	    cout << "DD " << pt.data() << endl;
	    fb->bank(NULL);
	    fb->loadFileConfig(pt.data());

	    f=fb;
	} else {
	    const boost::property_tree::ptree pt = it->second;
	    f = instantiateFilter(pt.begin() );
	}

	FilterThread* ft = new FilterThread(f);
	lanes.push_back(ft);

	add(f); // book-keeping

    } else if (it->first == "barrier") {
	boost::property_tree::ptree::const_iterator child = it->second.begin();
	cout << "PF::BARRIER FOUND! "<< child->first << endl;

	Filter* f = instantiateFilter( child );
	
	f->loadConfig( it->second );

	this->mux = (Mux*) f;

	add(f); // book-keeping

    } else {
	//return FilterBank::handleConfigItem(confFile, it);
    }
    return 1;
}
示例#5
0
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";
		}
	}
}
示例#6
0
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);
  }
}
示例#7
0
文件: xml.cpp 项目: spolitov/lib
void convert(const boost::property_tree::wptree & in, boost::property_tree::ptree & out)
{
    out.data() = utf8(in.data());
    for(boost::property_tree::wptree::const_iterator i = in.begin(), end = in.end(); i != end; ++i)
    {
        out.push_back(boost::property_tree::ptree::value_type(utf8(i->first), boost::property_tree::ptree()));
        convert(i->second, out.back().second);
    }
}
示例#8
0
void printPTree(const boost::property_tree::ptree &pt, const std::string prefix)
{
	std::cout << prefix << "data = \"" << pt.data() << '"' << std::endl;
	using boost::property_tree::ptree;
	for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it)
	{
		std::cout << prefix << "child = \""  << it->first << '"' << std::endl;
		printPTree(it->second, prefix + "\t");
	}
}
示例#9
0
bool is_list(const boost::property_tree::ptree& pt)
{
	if(!pt.data().empty())
		return false;

	for(bp::ptree::const_iterator it=pt.begin(); it!=pt.end(); ++it)
	{
		if(!it->first.empty())
			return false;
	}
	return true;
}
示例#10
0
T get_value(const boost::property_tree::ptree & node, const std::string & name)
{
    try
    {
        return node.get_value<T>();
    }
    catch (...)
    {
        throw config_error(std::string("Failed to parse ") +
                           name + ". Expected " + name_trait<T>::name() +
                           " but got '" + node.data() + "'");
    }
}
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; 
}
void merge(boost::property_tree::ptree &dest, bool ignoreEmptyUpdates, const boost::property_tree::ptree::path_type &childPath, const boost::property_tree::ptree &child) {
    if(ignoreEmptyUpdates && (child.data().empty() || child.data().find_first_not_of(" \n\t\r") == std::string::npos)) return;
    dest.put(childPath, child.data());
}