30Value::ValueSource::ValueSource()
34Value::ValueSource::~ValueSource()
36 cancelPendingUpdate();
39void Value::ValueSource::handleAsyncUpdate()
41 sendChangeMessage (
true);
46 const int numListeners = valuesWithListeners.size();
54 cancelPendingUpdate();
56 for (
int i = numListeners; --i >= 0;)
57 if (
Value*
const v = valuesWithListeners[i])
76 : value (initialValue)
90 sendChangeMessage (
false);
108 jassert (v !=
nullptr);
123 jassert (other.listeners.size() == 0);
125 other.removeFromListenerList();
126 value = std::move (other.value);
133 jassert (other.listeners.size() == 0);
135 other.removeFromListenerList();
136 value = std::move (other.value);
142 removeFromListenerList();
145void Value::removeFromListenerList()
147 if (listeners.size() > 0 && value !=
nullptr)
148 value->valuesWithListeners.removeValue (
this);
154 return value->getValue();
157Value::operator
var()
const
159 return value->getValue();
164 value->setValue (newValue);
169 return value->getValue().toString();
174 value->setValue (newValue);
180 if (valueToReferTo.value != value)
182 if (listeners.size() > 0)
184 value->valuesWithListeners.removeValue (
this);
185 valueToReferTo.value->valuesWithListeners.add (
this);
188 value = valueToReferTo.value;
195 return value == other.value;
200 return value == other.value || value->getValue() == other.
getValue();
205 return value != other.value && value->getValue() != other.
getValue();
211 if (listener !=
nullptr)
213 if (listeners.size() == 0)
214 value->valuesWithListeners.add (
this);
216 listeners.add (listener);
222 listeners.remove (listener);
224 if (listeners.size() == 0)
225 value->valuesWithListeners.removeValue (
this);
228void Value::callListeners()
230 if (listeners.size() > 0)
237OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream,
const Value& value)
239 return stream << value.toString();
A smart-pointer class which points to a reference-counted object.
var getValue() const override
Returns the current value of this object.
void setValue(const var &newValue) override
Changes the current value.
Receives callbacks when a Value object changes.
virtual void valueChanged(Value &value)=0
Called when a Value object is changed.
Used internally by the Value class as the base class for its shared value objects.
void sendChangeMessage(bool dispatchSynchronously)
Delivers a change message to all the listeners that are registered with this value.
Represents a shared variant value.
bool operator==(const Value &other) const
Compares two values.
void setValue(const var &newValue)
Sets the current value.
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
void removeListener(Listener *listener)
Removes a listener that was previously added with addListener().
bool refersToSameSourceAs(const Value &other) const
Returns true if this value and the other one are references to the same value.
Value & operator=(const var &newValue)
Sets the current value.
void referTo(const Value &valueToReferTo)
Makes this object refer to the same underlying ValueSource as another one.
Value()
Creates an empty Value, containing a void var.
var getValue() const
Returns the current value.
bool operator!=(const Value &other) const
Compares two values.
String toString() const
Returns the value as a string.
A variant class, that can be used to hold a range of primitive values.
bool equalsWithSameType(const var &other) const noexcept
Returns true if this var has the same value and type as the one supplied.