openshot-audio  0.1.4
juce_Value.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_VALUE_H_INCLUDED
26 #define JUCE_VALUE_H_INCLUDED
27 
28 
29 //==============================================================================
45 {
46 public:
47  //==============================================================================
49  Value();
50 
57  Value (const Value& other);
58 
60  explicit Value (const var& initialValue);
61 
62  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
63  Value (Value&&) noexcept;
64  Value& operator= (Value&&) noexcept;
65  #endif
66 
68  ~Value();
69 
70  //==============================================================================
72  var getValue() const;
73 
75  operator var() const;
76 
80  String toString() const;
81 
89  void setValue (const var& newValue);
90 
98  Value& operator= (const var& newValue);
99 
108  void referTo (const Value& valueToReferTo);
109 
112  bool refersToSameSourceAs (const Value& other) const;
113 
118  bool operator== (const Value& other) const;
119 
124  bool operator!= (const Value& other) const;
125 
126  //==============================================================================
131  {
132  public:
133  Listener() {}
134  virtual ~Listener() {}
135 
142  virtual void valueChanged (Value& value) = 0;
143  };
144 
156  void addListener (Listener* listener);
157 
159  void removeListener (Listener* listener);
160 
161 
162  //==============================================================================
171  private AsyncUpdater
172  {
173  public:
174  ValueSource();
175  virtual ~ValueSource();
176 
178  virtual var getValue() const = 0;
179 
183  virtual void setValue (const var& newValue) = 0;
184 
191  void sendChangeMessage (bool dispatchSynchronously);
192 
193  protected:
194  //==============================================================================
195  friend class Value;
197 
198  private:
199  void handleAsyncUpdate() override;
200 
202  };
203 
204 
205  //==============================================================================
207  explicit Value (ValueSource* valueSource);
208 
210  ValueSource& getValueSource() noexcept { return *value; }
211 
212 
213 private:
214  //==============================================================================
215  friend class ValueSource;
217  ListenerList<Listener> listeners;
218 
219  void callListeners();
220  void removeFromListenerList();
221 
222  // This is disallowed to avoid confusion about whether it should
223  // do a by-value or by-reference copy.
224  Value& operator= (const Value&) JUCE_DELETED_FUNCTION;
225 
226  // This declaration prevents accidental construction from an integer of 0,
227  // which is possible in some compilers via an implicit cast to a pointer.
228  explicit Value (void*) JUCE_DELETED_FUNCTION;
229 };
230 
233 
236 
237 #endif // JUCE_VALUE_H_INCLUDED
Definition: juce_Variant.h:46
#define noexcept
Definition: juce_CompilerSupport.h:141
SortedSet< Value * > valuesWithListeners
Definition: juce_Value.h:196
Definition: juce_SortedSet.h:60
virtual void handleAsyncUpdate()=0
Definition: juce_Value.h:130
virtual ~Listener()
Definition: juce_Value.h:134
#define JUCE_CALLTYPE
Definition: juce_PlatformDefs.h:50
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
Definition: juce_AsyncUpdater.h:39
Definition: juce_Value.h:170
OutputStream &JUCE_CALLTYPE operator<<(OutputStream &, const Value &)
Definition: juce_Value.cpp:234
Definition: juce_ReferenceCountedObject.h:65
Definition: juce_ListenerList.h:69
Definition: juce_ReferenceCountedObject.h:227
Listener()
Definition: juce_Value.h:133
#define JUCE_DELETED_FUNCTION
Definition: juce_CompilerSupport.h:133
Definition: juce_OutputStream.h:42
bool operator==(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:565
Definition: juce_Value.h:44
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Value::Listener ValueListener
Definition: juce_Value.h:235
bool operator!=(const var &v1, const var &v2) noexcept
Definition: juce_Variant.cpp:566
ValueSource & getValueSource() noexcept
Definition: juce_Value.h:210
Value()
Definition: juce_Value.cpp:97