Utility methods for working with object-typed var's?


#1

Hi all!

I've been working quite a bit with creating a Juce command-line utility that has to communicate via JSON, and I was wondering if there's an intentional reason why there aren't utility methods for creating and modifying juce::var's whose types are objects. There are a lot of methods (like append, insert, operator[] returning a var reference) for coercing a var into an array and modifying it. But for object-type var's, there's no setProperty or operator[] returning a var reference. So I've had to resort to creating temporary DynamicObjects by hand all over my code (on that note - my understanding is that once a var takes ownership of a DynamicObject created with "new," the DynamicObject doesn't need to be deleted, right?). Anyways, are there potential pitfalls with adding utility methods to juce::var to mimic how it works with arrays? I'd be happy to submit a pull request if there aren't objections or problems.

Best,

Brenton


#2

I don't really do much with DynamicObjects so there could indeed be things that could be added to make it easier. Would need to be careful about overloaded operators clashing with existing ones though.

Some suggested code changes might be the best way to explain what you're trying to do, but please don't send a pull-request, I never accept them (I always clean up or rewrite any contributions before they're allowed near the repo). Best thing for me would just be to email me your changed source-files and I can diff them locally to see what's going on.

my understanding is that once a var takes ownership of a DynamicObject created with "new," the DynamicObject doesn't need to be deleted, right?

That's right, it's reference-counted and the var holds a reference.