OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce_Value.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
11 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12 27th April 2017).
13
14 End User License Agreement: www.juce.com/juce-5-licence
15 Privacy Policy: www.juce.com/juce-5-privacy-policy
16
17 Or: You may also use this code under the terms of the GPL v3 (see
18 www.gnu.org/licenses).
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
51class JUCE_API Value final
52{
53public:
54 //==============================================================================
56 Value();
57
64 Value (const Value& other);
65
67 explicit Value (const var& initialValue);
68
70 Value (Value&&) noexcept;
71
73 ~Value();
74
75 //==============================================================================
77 var getValue() const;
78
80 operator var() const;
81
85 String toString() const;
86
94 void setValue (const var& newValue);
95
103 Value& operator= (const var& newValue);
104
106 Value& operator= (Value&&) noexcept;
107
116 void referTo (const Value& valueToReferTo);
117
120 bool refersToSameSourceAs (const Value& other) const;
121
126 bool operator== (const Value& other) const;
127
132 bool operator!= (const Value& other) const;
133
134 //==============================================================================
138 class JUCE_API Listener
139 {
140 public:
141 Listener() = default;
142 virtual ~Listener() = default;
143
150 virtual void valueChanged (Value& value) = 0;
151 };
152
164 void addListener (Listener* listener);
165
167 void removeListener (Listener* listener);
168
169
170 //==============================================================================
178 class JUCE_API ValueSource : public ReferenceCountedObject,
179 private AsyncUpdater
180 {
181 public:
182 ValueSource();
183 ~ValueSource() override;
184
186 virtual var getValue() const = 0;
187
191 virtual void setValue (const var& newValue) = 0;
192
199 void sendChangeMessage (bool dispatchSynchronously);
200
201 protected:
202 //==============================================================================
203 friend class Value;
204 SortedSet<Value*> valuesWithListeners;
205
206 private:
207 void handleAsyncUpdate() override;
208
209 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValueSource)
210 };
211
212
213 //==============================================================================
215 explicit Value (ValueSource* valueSource);
216
218 ValueSource& getValueSource() noexcept { return *value; }
219
220
221private:
222 //==============================================================================
223 friend class ValueSource;
225 ListenerList<Listener> listeners;
226
227 void callListeners();
228 void removeFromListenerList();
229
230 // This is disallowed to avoid confusion about whether it should
231 // do a by-value or by-reference copy.
232 Value& operator= (const Value&) = delete;
233
234 // This declaration prevents accidental construction from an integer of 0,
235 // which is possible in some compilers via an implicit cast to a pointer.
236 explicit Value (void*) = delete;
237};
238
240OutputStream& JUCE_CALLTYPE operator<< (OutputStream&, const Value&);
241
242
243} // namespace juce
virtual void valueChanged(Value &value)=0
virtual var getValue() const =0
virtual void setValue(const var &newValue)=0
ValueSource & getValueSource() noexcept
Definition juce_Value.h:218