Loading...
Searching...
No Matches
juce_Value.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API Value final
{
public:
//==============================================================================
Value();
Value (const Value& other);
explicit Value (const var& initialValue);
Value (Value&&) noexcept;
~Value();
//==============================================================================
var getValue() const;
operator var() const;
String toString() const;
void setValue (const var& newValue);
Value& operator= (const var& newValue);
Value& operator= (Value&&) noexcept;
void referTo (const Value& valueToReferTo);
bool refersToSameSourceAs (const Value& other) const;
bool operator== (const Value& other) const;
bool operator!= (const Value& other) const;
//==============================================================================
class JUCE_API Listener
{
public:
Listener() = default;
virtual ~Listener() = default;
virtual void valueChanged (Value& value) = 0;
};
void addListener (Listener* listener);
void removeListener (Listener* listener);
//==============================================================================
class JUCE_API ValueSource : public ReferenceCountedObject,
private AsyncUpdater
{
public:
ValueSource();
~ValueSource() override;
virtual var getValue() const = 0;
virtual void setValue (const var& newValue) = 0;
void sendChangeMessage (bool dispatchSynchronously);
protected:
//==============================================================================
friend class Value;
SortedSet<Value*> valuesWithListeners;
private:
void handleAsyncUpdate() override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValueSource)
};
//==============================================================================
explicit Value (ValueSource* valueSource);
ValueSource& getValueSource() noexcept { return *value; }
private:
//==============================================================================
friend class ValueSource;
ReferenceCountedObjectPtr<ValueSource> value;
ListenerList<Listener> listeners;
void callListeners();
void removeFromListenerList();
// This is disallowed to avoid confusion about whether it should
// do a by-value or by-reference copy.
Value& operator= (const Value&) = delete;
// This declaration prevents accidental construction from an integer of 0,
// which is possible in some compilers via an implicit cast to a pointer.
explicit Value (void*) = delete;
};
OutputStream& JUCE_CALLTYPE operator<< (OutputStream&, const Value&);
} // namespace juce
juce::AsyncUpdater::AsyncUpdater
AsyncUpdater()
Definition juce_AsyncUpdater.cpp:44
juce::ListenerList
Definition juce_ListenerList.h:81
juce::ReferenceCountedObjectPtr
Definition juce_ReferenceCountedObject.h:247
juce::ReferenceCountedObject::ReferenceCountedObject
ReferenceCountedObject()=default
juce::SortedSet
Definition juce_SortedSet.h:54
juce::String
Definition juce_String.h:53
juce::Value::Listener
Definition juce_Value.h:139
juce::Value::Listener::valueChanged
virtual void valueChanged(Value &value)=0
juce::Value::ValueSource
Definition juce_Value.h:180
juce::Value::ValueSource::getValue
virtual var getValue() const =0
juce::Value::ValueSource::sendChangeMessage
void sendChangeMessage(bool dispatchSynchronously)
Definition juce_Value.cpp:43
juce::Value::ValueSource::setValue
virtual void setValue(const var &newValue)=0
juce::Value
Definition juce_Value.h:51
juce::Value::setValue
void setValue(const var &newValue)
Definition juce_Value.cpp:161
juce::Value::addListener
void addListener(Listener *listener)
Definition juce_Value.cpp:208
juce::Value::removeListener
void removeListener(Listener *listener)
Definition juce_Value.cpp:219
juce::Value::refersToSameSourceAs
bool refersToSameSourceAs(const Value &other) const
Definition juce_Value.cpp:192
juce::Value::getValueSource
ValueSource & getValueSource() noexcept
Definition juce_Value.h:218
juce::Value::referTo
void referTo(const Value &valueToReferTo)
Definition juce_Value.cpp:177
juce::Value::Value
Value()
Definition juce_Value.cpp:101
juce::Value::getValue
var getValue() const
Definition juce_Value.cpp:151
juce::Value::toString
String toString() const
Definition juce_Value.cpp:166
juce::var
Definition juce_Variant.h:42