Hello,
I have a class which has a juce::Value member. Methods of this class mutate this value, and other classes listen for changes to that value by implementing the juce::Value::Listener interface.
This works well when the juce::Value wraps a primitive data-type, but it does not work out-of-the-box when attempting to wrap class instances- or complex data types in a juce::Value, as there is “no suitable user-defined conversion” to juce::var.
What I would like to do is to do something like this:
void SomeClass::someMethodThatTriggersListeners()
{
const auto newValue = std::pair<int, int>(1, 2); // For example
this->value.setValue(newValue) // Error: no suitable user-defined conversion from "const std::pair<int, int>" to "const juce::var" exists
}
The fact that this doesn’t work does not surprise me, as juce::var is intended for primitives. But, I am struggling with trying to remedy this.
I did take a look at juce::Value::ValueSource - the docs have this to say:
Used internally by the Value class as the base class for its shared value objects. The Value class is essentially a reference-counted pointer to a shared instance of a ValueSource object. If you're feeling adventurous, you can create your own custom ValueSource classes to allow Value objects to represent your own custom data items.
Which suggests it’s possible to do what I’m trying to achieve, though I’m not sure if this is the right approach, and also I could not find any documentation, tutorials or examples of how to properly implement the ValueSource interface.
I did find a few threads on this forum that are adjacent to my issue, but they seem to be more concerned with ValueTrees or dumping information to a JSON file. Note: I am not interested in serializing data to JSON or XML or anything like that. I just want something like a juce::Value that wraps around a complex data type that can broadcast an onChange signal to potential listeners.
