OpenShot Audio Library | OpenShotAudio: juce_Variant.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_Variant.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
23namespace juce
24{
25
26//==============================================================================
41 class JUCE_API var
42{
43public:
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
163 bool equals (const var& other) const noexcept;
164
169 bool equalsWithSameType (const var& other) const noexcept;
170
172 bool hasSameTypeAs (const var& other) const noexcept;
173
178 var clone() const noexcept;
179
180 //==============================================================================
184 int size() const;
185
193 const var& operator[] (int arrayIndex) const;
194
202 var& operator[] (int arrayIndex);
203
211 void append (const var& valueToAppend);
212
220 void insert (int index, const var& value);
221
227 void remove (int index);
228
235 void resize (int numArrayElementsWanted);
236
241 int indexOf (const var& value) const;
242
243 //==============================================================================
245 const var& operator[] (const Identifier& propertyName) const;
247 const var& operator[] (const char* propertyName) const;
250 var getProperty (const Identifier& propertyName, const var& defaultReturnValue) const;
252 bool hasProperty (const Identifier& propertyName) const noexcept;
253
255 var call (const Identifier& method) const;
257 var call (const Identifier& method, const var& arg1) const;
259 var call (const Identifier& method, const var& arg1, const var& arg2) const;
261 var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3);
263 var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const;
265 var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const;
267 var invoke (const Identifier& method, const var* arguments, int numArguments) const;
269 NativeFunction getNativeFunction() const;
270
271 //==============================================================================
276 void writeToStream (OutputStream& output) const;
277
283 static var readFromStream (InputStream& input);
284
285 //==============================================================================
286 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
287 [[deprecated ("This was a static empty var object, but is now deprecated as it's too easy to accidentally "
288 "use it indirectly during a static constructor leading to hard-to-find order-of-initialisation "
289 "problems. Use var() or {} instead. For returning an empty var from a function by reference, "
290 "use a function-local static var and return that.")]]
291 static const var null;
292 #endif
293
294private:
295 //==============================================================================
296 struct VariantType;
297 struct Instance;
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} // 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:53
juce::var
Definition juce_Variant.h:42
juce::var::NativeFunctionArgs
Definition juce_Variant.h:49