I donβt quite get why you use the intermediate juce::Array here? You could copy the content into the std::vector right away using the iterator constructor (untested)
Edit: Being so used to C++ 20 in the meantime I just realized that the iterator constructor is not available pre C++ 20. Anyway, this slightly more old school version using a std::memcpy should work with older C++ standards and still avoids an extra Array:
Personally, Iβve have done with with a template overload of juce::VariantConverter which would allow you to use your type with things like juce::CachedValueβ¦
Also, I donβt see the need to use a memoryblock and then convert to a string? juce::var has a constructor that takes a juce::MemoryBlock so you could just use that directly and let JUCE handle the string convertions.
Thanks @ImJimmi and @PluginPenguin
Those are 2 approaches that I never thought of using!
I have used VariantConverter in the past, but sometimes the fastest/quickest solution is to just write exactly what you need, and not implement a βbridge classβ to conform with a frameworkβs intended usage.
I didnβt need to use CachedValue for this project, and I wanted to be able to inspect the Base64 string in the debugger. I canβt do that if I use the MemoryBlock -> var approach.
A lot of my code choices center around the ability to debug the code and inspect the variables. memcpy doesnβt let me do this during the copy stage.
but itβs good to know that you can use memcpy to write directly into std::vector.
the temporary juce::Array followed by the manual copy was my solution that gave me the ability to inspect what was being added to the std::vector, while it was being copied.
I use this approach too β Iβve got templated helper structs for converting different container types to and from var, and then elsewhere in my codebase Iβve got helper functions for converting vars to/from ValueTrees.
The only downside I can see to this approach is that the initial conversion to var may result in the final ValueTree not looking quite as nice as if youβd built it βmanuallyβ from the container, but this approach makes the C++ workflow much nicerβ¦