I want to make a function which finds the last item in a boost::property_tree::ptree and returns it as ptree
I have following code which finds last item, however I do not know how to pass its ptree as a return value - it should be possible, however I have not found any examples that returns a ptree without first copying it.
Reason for wanting this is to be able to handle an update of last item with new values
BOOST_FOREACH( boost::property_tree::ptree::value_type const&rowPair, pt.get_child( "" ) )
{
cout << rowPair.first << ": " << endl;
BOOST_REVERSE_FOREACH( boost::property_tree::ptree::value_type const& itemPair, rowPair.second )
{
std::cout << "\t" << itemPair.first << " ";
BOOST_FOREACH( boost::property_tree::ptree::value_type const& node, itemPair.second )
{
std::cout << node.second.get_value<std::string>() << " ";
}
std::cout << std::endl;
//TODO: return itemPair
break;
}
std::cout << std::endl;
}
Trying to clarify it a bit more. following code line appends to an already existing entry
pt.insert(pt.get_child("item").end(), subpt.front());
this works perfectly if Items.item only have one item, however if it has multiple "Items" and multiple "item" in Items, then it will insert new entry in first Items.item
<xml>
<listOfItems>
<Items>
<item>
</item>
<item>
... inserts new sub pt here
</item>
</Items>
<Items>
<item>
</item>
<item>
... Should insert new sub pt here
</item>
</Items>
</listOfItems>
so in order to get what I want I somehow have to make the insert statement better or create a function which can give me the correct item and then insert into it