boost::property_tree::ptree
Dashboard::mergePropertyTrees( const boost::property_tree::ptree& rptFirst, const boost::property_tree::ptree& rptSecond )
{
// Take over first property tree
boost::property_tree::ptree ptMerged = rptFirst;
// Keep track of keys and values (subtrees) in second property tree
queue<string> qKeys;
queue<boost::property_tree::ptree> qValues;
qValues.push( rptSecond );
// Iterate over second property tree
while( !qValues.empty() )
{
// Setup keys and corresponding values
boost::property_tree::ptree ptree = qValues.front();
qValues.pop();
string keychain = "";
if( !qKeys.empty() )
{
keychain = qKeys.front();
qKeys.pop();
}
// Iterate over keys level-wise
BOOST_FOREACH( const boost::property_tree::ptree::value_type& child, ptree )
{
// Leaf
if( child.second.size() == 0 )
{
// No "." for first level entries
string s;
if( keychain != "" )
s = keychain + "." + child.first.data();
else
s = child.first.data();
// Put into combined property tree
ptMerged.put( s, child.second.data() );
}
// Subtree
else
{
// Put keys (identifiers of subtrees) and all of its parents (where present)
// aside for later iteration. Keys on first level have no parents
if( keychain != "" )
qKeys.push( keychain + "." + child.first.data() );
else
qKeys.push( child.first.data() );
// Put values (the subtrees) aside, too
qValues.push( child.second );
}
} // -- End of BOOST_FOREACH
} // --- End of while
return ptMerged;
}