30 Value::ValueSource::ValueSource()
34 Value::ValueSource::~ValueSource()
39 void Value::ValueSource::handleAsyncUpdate()
46 const int numListeners = valuesWithListeners.size();
56 for (
int i = numListeners; --i >= 0;)
57 if (
Value*
const v = valuesWithListeners[i])
76 : value (initialValue)
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();
145 void Value::removeFromListenerList()
147 if (listeners.size() > 0 && value !=
nullptr)
148 value->valuesWithListeners.removeValue (
this);
154 return value->getValue();
157 Value::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);
228 void Value::callListeners()
230 if (listeners.size() > 0)
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.
void sendChangeMessage(bool dispatchSynchronously)
Delivers a change message to all the listeners that are registered with this value.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
var getValue() const
Returns the current value.
void cancelPendingUpdate() noexcept
This will stop any pending updates from happening.
Receives callbacks when a Value object changes.
void setValue(const var &newValue) override
Changes the current value.
bool operator==(const Value &other) const
Compares two values.
var getValue() const override
Returns the current value of this object.
Used internally by the Value class as the base class for its shared value objects.
Represents a shared variant value.
The base class for streams that write data to some kind of destination.
bool equalsWithSameType(const var &other) const noexcept
Returns true if this var has the same value and type as the one supplied.
A smart-pointer class which points to a reference-counted object.
void referTo(const Value &valueToReferTo)
Makes this object refer to the same underlying ValueSource as another one.
Value & operator=(const var &newValue)
Sets the current value.
Value()
Creates an empty Value, containing a void var.
void setValue(const var &newValue)
Sets the current value.
virtual void valueChanged(Value &value)=0
Called when a Value object is changed.
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
bool refersToSameSourceAs(const Value &other) const
Returns true if this value and the other one are references to the same value.
void removeListener(Listener *listener)
Removes a listener that was previously added with addListener().