ValueTree with multi-value property

is there any convinience way to get from ValueTree the child with more than one properties which meet specified juce::var s?

in ValueTree there is nice function:
ValueTree::getChildWithProperty(const Identifier& propertyName, const var& propertyValue);

But it allows me to specify only one property while I have an object whose uniqueness is expressed by two values. I think it can be compared to file in file system. Such file uniqueness is expressed by file name and it’s extention.

I thought to make my unique property as a String expressed with something like that: "x|y". Where “x” is first value (let’s say file name) and “y” is second value (let’s say file extention). And then I can tokenize those values.

And with such property I can easily get exact child with property equal to var("x|y").

But the problem is that in my case both values are very often in use. And I also often need to filter or reorder my ValueTree children with one of those two values. So I would like to have easy and intuitive access to them independently. But geting the String property and tokenizing it every time I need only value “x” or only “y” seems to be not intuitive.

So another idea was that in addition to tekonized String property I could also keep both values independently in next two properties so I could maintain intuitive access to both of them. But in such case it seems to be nice to make both of those properties to be listeners of tokenized String property and vice versa. But I am not sure how to make one property of ValueTree to be listener of another property. It seems that I could achieve that by creating my own class which handle all of that. But I am affraid to spend a lot of time to change my whole application to implement such solution while I am not even sure if it’s optimal solution.

I also had idea to keep both values in one property which would be expressed as var array. But I am not sure if it would solve all descriped problems.

That’s why I would like to ask you for help if you know any convinience ways to get from ValueTree the children which meets two properties variables.

For any advice great thanks in advance.

Best Regards.

1 Like

There’s nothing built in to juce::ValueTree to do that, but you could easily do it with std::find_if:

auto child = std::find_if(std::begin(tree),
                          [&x, &y](auto&& child) {
                              return child["x"] == juce::var{ x } && child["y"] == juce::var{ y };

if (child != std::end(tree))
    // found a child that matches
1 Like

hmm… thanks for suggestion I will think about that.