OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_Variant.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 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23 namespace juce
24{
25
26//==============================================================================
41 class JUCE_API var
42{
43 public:
44 //==============================================================================
48 struct JUCE_API NativeFunctionArgs
49 {
50 NativeFunctionArgs (const var& thisObject, const var* args, int numArgs) noexcept;
51
52 const var& thisObject;
53 const var* arguments;
54 int numArguments;
55 };
56
57 using NativeFunction = std::function<var(const NativeFunctionArgs&)>;
58
59 //==============================================================================
61 var() noexcept;
62
64 ~var() noexcept;
65
66 var (const var& valueToCopy);
67 var (int value) noexcept;
68 var (int64 value) noexcept;
69 var (bool value) noexcept;
70 var (double value) noexcept;
71 var (const char* value);
72 var (const wchar_t* value);
73 var (const String& value);
74 var (const Array<var>& value);
75 var (const StringArray& value);
76 var (ReferenceCountedObject* object);
77 var (NativeFunction method) noexcept;
78 var (const void* binaryData, size_t dataSize);
79 var (const MemoryBlock& binaryData);
80
81 var& operator= (const var& valueToCopy);
82 var& operator= (int value);
83 var& operator= (int64 value);
84 var& operator= (bool value);
85 var& operator= (double value);
86 var& operator= (const char* value);
87 var& operator= (const wchar_t* value);
88 var& operator= (const String& value);
89 var& operator= (const MemoryBlock& value);
90 var& operator= (const Array<var>& value);
91 var& operator= (ReferenceCountedObject* object);
92 var& operator= (NativeFunction method);
93
94 var (var&&) noexcept;
95 var (String&&);
96 var (MemoryBlock&&);
97 var (Array<var>&&);
98 var& operator= (var&&) noexcept;
99 var& operator= (String&&);
100
101 void swapWith (var& other) noexcept;
102
104 static var undefined() noexcept;
105
106 //==============================================================================
107 operator int() const noexcept;
108 operator int64() const noexcept;
109 operator bool() const noexcept;
110 operator float() const noexcept;
111 operator double() const noexcept;
112 operator String() const;
113 String toString() const;
114
121 Array<var>* getArray() const noexcept;
122
129 MemoryBlock* getBinaryData() const noexcept;
130
131 ReferenceCountedObject* getObject() const noexcept;
132 DynamicObject* getDynamicObject() const noexcept;
133
134 //==============================================================================
135 bool isVoid() const noexcept;
136 bool isUndefined() const noexcept;
137 bool isInt() const noexcept;
138 bool isInt64() const noexcept;
139 bool isBool() const noexcept;
140 bool isDouble() const noexcept;
141 bool isString() const noexcept;
142 bool isObject() const noexcept;
143 bool isArray() const noexcept;
144 bool isBinaryData() const noexcept;
145 bool isMethod() const noexcept;
146
152 bool equals (const var& other) const noexcept;
153
158 bool equalsWithSameType (const var& other) const noexcept;
159
161 bool hasSameTypeAs (const var& other) const noexcept;
162
167 var clone() const noexcept;
168
169 //==============================================================================
173 int size() const;
174
182 const var& operator[] (int arrayIndex) const;
183
191 var& operator[] (int arrayIndex);
192
200 void append (const var& valueToAppend);
201
209 void insert (int index, const var& value);
210
216 void remove (int index);
217
224 void resize (int numArrayElementsWanted);
225
230 int indexOf (const var& value) const;
231
232 //==============================================================================
234 const var& operator[] (const Identifier& propertyName) const;
236 const var& operator[] (const char* propertyName) const;
239 var getProperty (const Identifier& propertyName, const var& defaultReturnValue) const;
241 bool hasProperty (const Identifier& propertyName) const noexcept;
242
244 var call (const Identifier& method) const;
246 var call (const Identifier& method, const var& arg1) const;
248 var call (const Identifier& method, const var& arg1, const var& arg2) const;
250 var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3);
252 var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const;
254 var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const;
256 var invoke (const Identifier& method, const var* arguments, int numArguments) const;
258 NativeFunction getNativeFunction() const;
259
260 //==============================================================================
265 void writeToStream (OutputStream& output) const;
266
272 static var readFromStream (InputStream& input);
273
274 /* This was a static empty var object, but is now deprecated as it's too easy to accidentally
275 use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation
276 problems.
277 @deprecated If you need a default-constructed var, just use var() or {}.
278 The only time you might miss having var::null available might be if you need to return an
279 empty var from a function by reference, but if you need to do that, it's easy enough to use
280 a function-local static var and return that, avoiding any order-of-initialisation issues.
281 */
282 JUCE_DEPRECATED_STATIC (static const var null;)
283
284private:
285 //==============================================================================
286 class VariantType;
287 class VariantType_Void;
288 class VariantType_Undefined;
289 class VariantType_Int;
290 class VariantType_Int64;
291 class VariantType_Double;
292 class VariantType_Bool;
293 class VariantType_String;
294 class VariantType_Object;
295 class VariantType_Array;
296 class VariantType_Binary;
297 class VariantType_Method;
298
299 union ValueUnion
300 {
301 int intValue;
302 int64 int64Value;
303 bool boolValue;
304 double doubleValue;
305 char stringValue[sizeof (String)];
306 ReferenceCountedObject* objectValue;
307 MemoryBlock* binaryValue;
308 NativeFunction* methodValue;
309 };
310
311 friend bool canCompare (const var&, const var&);
312
313 const VariantType* type;
314 ValueUnion value;
315
316 Array<var>* convertToArray();
317 var (const VariantType&) noexcept;
318
319 // This is needed to prevent the wrong constructor/operator being called
320 var (const ReferenceCountedObject*) = delete;
321 var& operator= (const ReferenceCountedObject*) = delete;
322 var (const void*) = delete;
323 var& operator= (const void*) = delete;
324};
325
327JUCE_API bool operator== (const var&, const var&);
329JUCE_API bool operator!= (const var&, const var&);
331JUCE_API bool operator< (const var&, const var&);
333JUCE_API bool operator<= (const var&, const var&);
335JUCE_API bool operator> (const var&, const var&);
337JUCE_API bool operator>= (const var&, const var&);
338
339JUCE_API bool operator== (const var&, const String&);
340JUCE_API bool operator!= (const var&, const String&);
341JUCE_API bool operator== (const var&, const char*);
342JUCE_API bool operator!= (const var&, const char*);
343
344//==============================================================================
349 template <typename Type>
350 struct VariantConverter
351{
352 static Type fromVar (const var& v) { return static_cast<Type> (v); }
353 static var toVar (const Type& t) { return t; }
354};
355
356#ifndef DOXYGEN
357 template <>
358 struct VariantConverter<String>
359{
360 static String fromVar (const var& v) { return v.toString(); }
361 static var toVar (const String& s) { return s; }
362};
363#endif
364
365} // namespace juce
juce::Array
Definition: juce_Array.h:56
juce::DynamicObject
Definition: juce_DynamicObject.h:40
juce::Identifier
Definition: juce_Identifier.h:39
juce::InputStream
Definition: juce_InputStream.h:37
juce::MemoryBlock
Definition: juce_MemoryBlock.h:33
juce::OutputStream
Definition: juce_OutputStream.h:38
juce::ReferenceCountedObject
Definition: juce_ReferenceCountedObject.h:66
juce::StringArray
Definition: juce_StringArray.h:35
juce::String
Definition: juce_String.h:39
juce::var
Definition: juce_Variant.h:42
juce::VariantConverter
Definition: juce_Variant.h:351
juce::var::NativeFunctionArgs
Definition: juce_Variant.h:49