Loading...
Searching...
No Matches
juce_Variant.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.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
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 var
{
public:
//==============================================================================
struct JUCE_API NativeFunctionArgs
{
NativeFunctionArgs (const var& thisObject, const var* args, int numArgs) noexcept;
const var& thisObject;
const var* arguments;
int numArguments;
};
using NativeFunction = std::function<var (const NativeFunctionArgs&)>;
//==============================================================================
var() noexcept;
~var() noexcept;
var (const var& valueToCopy);
var (int value) noexcept;
var (int64 value) noexcept;
var (bool value) noexcept;
var (double value) noexcept;
var (const char* value);
var (const wchar_t* value);
var (const String& value);
var (const Array<var>& value);
var (const StringArray& value);
var (ReferenceCountedObject* object);
var (NativeFunction method) noexcept;
var (const void* binaryData, size_t dataSize);
var (const MemoryBlock& binaryData);
var& operator= (const var& valueToCopy);
var& operator= (int value);
var& operator= (int64 value);
var& operator= (bool value);
var& operator= (double value);
var& operator= (const char* value);
var& operator= (const wchar_t* value);
var& operator= (const String& value);
var& operator= (const MemoryBlock& value);
var& operator= (const Array<var>& value);
var& operator= (ReferenceCountedObject* object);
var& operator= (NativeFunction method);
var (var&&) noexcept;
var (String&&);
var (MemoryBlock&&);
var (Array<var>&&);
var& operator= (var&&) noexcept;
var& operator= (String&&);
void swapWith (var& other) noexcept;
static var undefined() noexcept;
//==============================================================================
operator int() const noexcept;
operator int64() const noexcept;
operator bool() const noexcept;
operator float() const noexcept;
operator double() const noexcept;
operator String() const;
String toString() const;
Array<var>* getArray() const noexcept;
MemoryBlock* getBinaryData() const noexcept;
ReferenceCountedObject* getObject() const noexcept;
DynamicObject* getDynamicObject() const noexcept;
//==============================================================================
bool isVoid() const noexcept;
bool isUndefined() const noexcept;
bool isInt() const noexcept;
bool isInt64() const noexcept;
bool isBool() const noexcept;
bool isDouble() const noexcept;
bool isString() const noexcept;
bool isObject() const noexcept;
bool isArray() const noexcept;
bool isBinaryData() const noexcept;
bool isMethod() const noexcept;
bool equals (const var& other) const noexcept;
bool equalsWithSameType (const var& other) const noexcept;
bool hasSameTypeAs (const var& other) const noexcept;
var clone() const noexcept;
//==============================================================================
int size() const;
const var& operator[] (int arrayIndex) const;
var& operator[] (int arrayIndex);
void append (const var& valueToAppend);
void insert (int index, const var& value);
void remove (int index);
void resize (int numArrayElementsWanted);
int indexOf (const var& value) const;
//==============================================================================
const var& operator[] (const Identifier& propertyName) const;
const var& operator[] (const char* propertyName) const;
var getProperty (const Identifier& propertyName, const var& defaultReturnValue) const;
bool hasProperty (const Identifier& propertyName) const noexcept;
var call (const Identifier& method) const;
var call (const Identifier& method, const var& arg1) const;
var call (const Identifier& method, const var& arg1, const var& arg2) const;
var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3);
var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const;
var call (const Identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const;
var invoke (const Identifier& method, const var* arguments, int numArguments) const;
NativeFunction getNativeFunction() const;
//==============================================================================
void writeToStream (OutputStream& output) const;
static var readFromStream (InputStream& input);
//==============================================================================
#if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
[[deprecated ("This was a static empty var object, but is now deprecated as it's too easy to accidentally "
"use it indirectly during a static constructor leading to hard-to-find order-of-initialisation "
"problems. Use var() or {} instead. For returning an empty var from a function by reference, "
"use a function-local static var and return that.")]]
static const var null;
#endif
private:
//==============================================================================
struct VariantType;
struct Instance;
union ValueUnion
{
int intValue;
int64 int64Value;
bool boolValue;
double doubleValue;
char stringValue[sizeof (String)];
ReferenceCountedObject* objectValue;
MemoryBlock* binaryValue;
NativeFunction* methodValue;
};
friend bool canCompare (const var&, const var&);
const VariantType* type;
ValueUnion value;
Array<var>* convertToArray();
var (const VariantType&) noexcept;
// This is needed to prevent the wrong constructor/operator being called
var (const ReferenceCountedObject*) = delete;
var& operator= (const ReferenceCountedObject*) = delete;
var (const void*) = delete;
var& operator= (const void*) = delete;
};
JUCE_API bool operator== (const var&, const var&);
JUCE_API bool operator!= (const var&, const var&);
JUCE_API bool operator< (const var&, const var&);
JUCE_API bool operator<= (const var&, const var&);
JUCE_API bool operator> (const var&, const var&);
JUCE_API bool operator>= (const var&, const var&);
JUCE_API bool operator== (const var&, const String&);
JUCE_API bool operator!= (const var&, const String&);
JUCE_API bool operator== (const var&, const char*);
JUCE_API bool operator!= (const var&, const char*);
} // 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::undefined
static var undefined() noexcept
Definition juce_Variant.cpp:538
juce::var::insert
void insert(int index, const var &value)
Definition juce_Variant.cpp:802
juce::var::size
int size() const
Definition juce_Variant.cpp:747
juce::var::invoke
var invoke(const Identifier &method, const var *arguments, int numArguments) const
Definition juce_Variant.cpp:704
juce::var::writeToStream
void writeToStream(OutputStream &output) const
Definition juce_Variant.cpp:821
juce::var::var
var() noexcept
Definition juce_Variant.cpp:497
juce::var::getArray
Array< var > * getArray() const noexcept
Definition juce_Variant.cpp:561
juce::var::indexOf
int indexOf(const var &value) const
Definition juce_Variant.cpp:812
juce::var::getNativeFunction
NativeFunction getNativeFunction() const
Definition juce_Variant.cpp:699
juce::var::hasProperty
bool hasProperty(const Identifier &propertyName) const noexcept
Definition juce_Variant.cpp:691
juce::var::readFromStream
static var readFromStream(InputStream &input)
Definition juce_Variant.cpp:826
juce::var::append
void append(const var &valueToAppend)
Definition juce_Variant.cpp:791
juce::var::equals
bool equals(const var &other) const noexcept
Definition juce_Variant.cpp:622
juce::var::equalsWithSameType
bool equalsWithSameType(const var &other) const noexcept
Definition juce_Variant.cpp:627
juce::var::resize
void resize(int numArrayElementsWanted)
Definition juce_Variant.cpp:807
juce::var::getProperty
var getProperty(const Identifier &propertyName, const var &defaultReturnValue) const
Definition juce_Variant.cpp:683
juce::var::remove
void remove(int index)
Definition juce_Variant.cpp:796
juce::var::call
var call(const Identifier &method) const
Definition juce_Variant.cpp:712
juce::var::hasSameTypeAs
bool hasSameTypeAs(const var &other) const noexcept
Definition juce_Variant.cpp:632
juce::var::clone
var clone() const noexcept
Definition juce_Variant.cpp:664
juce::var::getBinaryData
MemoryBlock * getBinaryData() const noexcept
Definition juce_Variant.cpp:562
juce::var::NativeFunctionArgs
Definition juce_Variant.h:49