When opening a file to input new values into the value tree from XML, I would like to be able to recursively search the tree (i.e. check all the sibling trees for properties) to see which values have changed and set the new properties accordingly. Currently I just have a mess of nested for and if statements which checks for the number of children on the current tree, obtains the properties of the current tree and then checks if it has any children (repeating the process if it does). Is there a method in JUCE I’ve missed which will provide similar functionality in a more efficient or visually cleaner way to recursively search a ValueTree?
edit: For anybody interested, I cleaned it all up into a function (below) which returns the list of properties as a vector and prints the list of properties to the console for debugging purposes.
std::vector<String> MyoMapperApplication::searchTree (juce::ValueTree tree)
{
std::vector<String> propertyList;
for (int i = 0; i < tree.getNumChildren(); ++i)
{
auto childTree = tree.getChild (i);
for (int j = 0; j < childTree.getNumProperties(); ++j)
{
auto propertyName = childTree.getPropertyName(j);
auto property = childTree.getProperty (propertyName);
propertyList.push_back (childTree.getProperty (name).toString() + ": " + property.toString() + newLine);
}
if (childTree.getNumChildren() != 0)
{
searchTree (childTree);
}
}
for (auto i = propertyList.begin(); i != propertyList.end(); ++i)
{
DBG (*i);
}
return propertyList;
}
