Hi, I’d like to understand how to refer to the same value tree in a scenario like this below.
I’m sure the string searched is equal to a property contained by a ValueTree, but it seems that calling ValueTree::getChild(int) the ValueTree is passed by copy as his underling pointer … while reading in doc the underling pointer should be the same
ValueTree Engine::getTeatroValueTree(String const teatroNome) const
{
for (int i = 0; i < treeStructure.getNumChildren(); i++)
{
ValueTree regioneValueTree(treeStructure.getChild(i));
for (int i2 = 0; i2 < regioneValueTree.getNumChildren(); i2++)
{
ValueTree provinciaValueTree(regioneValueTree.getChild(i2));
for (int i3 = 0; i3 < regioneValueTree.getNumChildren(); i3++)
{
ValueTree teatroValueTree(provinciaValueTree.getChild(i3));
if (teatroNome == teatroValueTree.getProperty(IDs::nomeProvincia).toString()) { return teatroValueTree; DBG("I'm here"); }
}
}
}
return ValueTree();
}
A ValueTree is a wrapper for the actual data. How are you discerning this issue? to clarify, yes getChild returns a copy of the ValueTree object, but, as mentioned, this object still refers to the same underlying data. You have to be very specific if you want to actual copy ValueTree data.
I can’t help based on that small snippet, but for me, developing and understanding of things can sometimes be aided by looking at the data. If you are using Visual Studio you can install and use the juce.natvis portion of this repo (GitHub - jcredland/juce-toys: Debugging utilities in a JUCE Module, plus NatVis and LLDB customizations) to look at your ValueTree in the debugger. That extensions helps the debugger understand the format of the ValueTree (and other juce related datatypes), so you can easily navigate and examine them. Or, you can run your ValueTrees through some function that dumps them our for viewing. Here is a quick and dirty one that I use.
If you just need something quick and dirty and don’t mind reading XML, DBG (myValueTree.toXmlString()); is pretty handy, too!
@chopin20 How are you creating the ValueTree? Assuming the tree was constructed properly, your code to print the property value should work as expected.
Here’s a minimal example that’s similar to what you’re trying to do, and it prints the string “Value” when the DBG statement is hit: