Question / request re: Var

Hello all.

I’m finding the ValueTree very useful in rewriting a better version of my program, using it especially for undo/redo and state recall. With the individual elements, the vars, I presume one of the primary uses is to replace the basic member elements of objects into the ValueTree. Once this has been done, the values need to be retrieved from the ValueTree for use by the object. To do this with a number you have to convert the var to a String using toString(), then into whatever number you want using, for example, getIntValue(). Is it possible to add toInt(), toFloat() etc to var so you can reduce the method calls and shorten the amount of code?

So that:

valueTree.getProperty (“property”).toString().getIntValue();


valueTree.getProperty (“property”).toInt();

Thank you.

You can do e.g.

valueTree.getProperty("stringProperty").operator String()
valueTree.getProperty("intProperty").operator int()

Ah, thank you!

I second that proposal. Especially since c++11 is widely adopted and one tends to initialize variables with auto.

isn’t it the same?


Correct modern syntax is:

static_cast<int> (valueTree.getProperty ("foo"))
static_cast<String> (valueTree.getProperty ("foo"))

Never use C-style casts where classes are involved.

But often you don’t need the cast if e.g. you’re passing it into a function that takes an int or String.


True. But often you also want to assign a variable.

Sure, so you’d write:

String s = valueTree.getProperty ("foo");

Still no need for a cast.

1 Like

I didn’t consider that a property would deduce according to the type to which it was passed, thank you!