A variant class, that can be used to hold a range of primitive values. More...
#include <juce_Variant.h>
Classes | |
struct | NativeFunctionArgs |
This structure is passed to a NativeFunction callback, and contains invocation details about the function's arguments and context. More... | |
union | ValueUnion |
Public Types | |
using | NativeFunction = std::function< var(const NativeFunctionArgs &)> |
Public Member Functions | |
var () noexcept | |
Creates a void variant. More... | |
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 (var &&) noexcept | |
var (String &&) | |
var (MemoryBlock &&) | |
var (Array< var > &&) | |
~var () noexcept | |
Destructor. More... | |
void | append (const var &valueToAppend) |
Appends an element to the var, converting it to an array if it isn't already one. More... | |
var | call (const Identifier &method) const |
Invokes a named method call with no arguments. More... | |
var | call (const Identifier &method, const var &arg1) const |
Invokes a named method call with one argument. More... | |
var | call (const Identifier &method, const var &arg1, const var &arg2) const |
Invokes a named method call with 2 arguments. More... | |
var | call (const Identifier &method, const var &arg1, const var &arg2, const var &arg3) |
Invokes a named method call with 3 arguments. More... | |
var | call (const Identifier &method, const var &arg1, const var &arg2, const var &arg3, const var &arg4) const |
Invokes a named method call with 4 arguments. More... | |
var | call (const Identifier &method, const var &arg1, const var &arg2, const var &arg3, const var &arg4, const var &arg5) const |
Invokes a named method call with 5 arguments. More... | |
var | clone () const noexcept |
Returns a deep copy of this object. More... | |
bool | equals (const var &other) const noexcept |
Returns true if this var has the same value as the one supplied. More... | |
bool | equalsWithSameType (const var &other) const noexcept |
Returns true if this var has the same value and type as the one supplied. More... | |
Array< var > * | getArray () const noexcept |
If this variant holds an array, this provides access to it. More... | |
MemoryBlock * | getBinaryData () const noexcept |
If this variant holds a memory block, this provides access to it. More... | |
DynamicObject * | getDynamicObject () const noexcept |
NativeFunction | getNativeFunction () const |
If this object is a method, this returns the function pointer. More... | |
ReferenceCountedObject * | getObject () const noexcept |
var | getProperty (const Identifier &propertyName, const var &defaultReturnValue) const |
If this variant is an object, this returns one of its properties, or a default fallback value if the property is not set. More... | |
bool | hasProperty (const Identifier &propertyName) const noexcept |
Returns true if this variant is an object and if it has the given property. More... | |
bool | hasSameTypeAs (const var &other) const noexcept |
Returns true if this var has the same type as the one supplied. More... | |
int | indexOf (const var &value) const |
If the var is an array, this searches it for the first occurrence of the specified value, and returns its index. More... | |
void | insert (int index, const var &value) |
Inserts an element to the var, converting it to an array if it isn't already one. More... | |
var | invoke (const Identifier &method, const var *arguments, int numArguments) const |
Invokes a named method call with a list of arguments. More... | |
bool | isArray () const noexcept |
bool | isBinaryData () const noexcept |
bool | isBool () const noexcept |
bool | isDouble () const noexcept |
bool | isInt () const noexcept |
bool | isInt64 () const noexcept |
bool | isMethod () const noexcept |
bool | isObject () const noexcept |
bool | isString () const noexcept |
bool | isUndefined () const noexcept |
bool | isVoid () const noexcept |
operator bool () const noexcept | |
operator double () const noexcept | |
operator float () const noexcept | |
operator int () const noexcept | |
operator int64 () const noexcept | |
operator String () const | |
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 & | operator= (var &&) noexcept |
var & | operator= (String &&) |
const var & | operator[] (int arrayIndex) const |
If the var is an array, this can be used to return one of its elements. More... | |
var & | operator[] (int arrayIndex) |
If the var is an array, this can be used to return one of its elements. More... | |
const var & | operator[] (const Identifier &propertyName) const |
If this variant is an object, this returns one of its properties. More... | |
const var & | operator[] (const char *propertyName) const |
If this variant is an object, this returns one of its properties. More... | |
void | remove (int index) |
If the var is an array, this removes one of its elements. More... | |
void | resize (int numArrayElementsWanted) |
Treating the var as an array, this resizes it to contain the specified number of elements. More... | |
int | size () const |
If the var is an array, this returns the number of elements. More... | |
void | swapWith (var &other) noexcept |
String | toString () const |
void | writeToStream (OutputStream &output) const |
Writes a binary representation of this value to a stream. More... | |
Static Public Member Functions | |
static var | readFromStream (InputStream &input) |
Reads back a stored binary representation of a value. More... | |
static var | undefined () noexcept |
Returns a var object that can be used where you need the javascript "undefined" value. More... | |
Private Member Functions | |
var (const VariantType &) noexcept | |
Array< var > * | convertToArray () |
Private Attributes | |
const VariantType * | type |
ValueUnion | value |
Friends | |
bool | canCompare (const var &, const var &) |
A variant class, that can be used to hold a range of primitive values.
A var object can hold a range of simple primitive values, strings, or any kind of ReferenceCountedObject. The var class is intended to act like the kind of values used in dynamic scripting languages.
You can save/load var objects either in a small, proprietary binary format using writeToStream()/readFromStream(), or as JSON by using the JSON class.
{Core}
using juce::var::NativeFunction = std::function<var (const NativeFunctionArgs&)> |
|
noexcept |
Creates a void variant.
|
noexcept |
Destructor.
juce::var::var | ( | const var & | valueToCopy | ) |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
juce::var::var | ( | const char * | value | ) |
juce::var::var | ( | const wchar_t * | value | ) |
juce::var::var | ( | const String & | value | ) |
juce::var::var | ( | const StringArray & | value | ) |
juce::var::var | ( | ReferenceCountedObject * | object | ) |
|
noexcept |
juce::var::var | ( | const void * | binaryData, |
size_t | dataSize | ||
) |
juce::var::var | ( | const MemoryBlock & | binaryData | ) |
|
noexcept |
juce::var::var | ( | String && | ) |
juce::var::var | ( | MemoryBlock && | ) |
|
privatenoexcept |
void juce::var::append | ( | const var & | valueToAppend | ) |
Appends an element to the var, converting it to an array if it isn't already one.
If the var isn't an array, it will be converted to one, and if its value was non-void, this value will be kept as the first element of the new array. The parameter value will then be appended to it. For more control over the array's contents, you can call getArray() and manipulate it directly as an Array<var>.
var juce::var::call | ( | const Identifier & | method | ) | const |
Invokes a named method call with no arguments.
var juce::var::call | ( | const Identifier & | method, |
const var & | arg1 | ||
) | const |
Invokes a named method call with one argument.
var juce::var::call | ( | const Identifier & | method, |
const var & | arg1, | ||
const var & | arg2 | ||
) | const |
Invokes a named method call with 2 arguments.
var juce::var::call | ( | const Identifier & | method, |
const var & | arg1, | ||
const var & | arg2, | ||
const var & | arg3 | ||
) |
Invokes a named method call with 3 arguments.
var juce::var::call | ( | const Identifier & | method, |
const var & | arg1, | ||
const var & | arg2, | ||
const var & | arg3, | ||
const var & | arg4 | ||
) | const |
Invokes a named method call with 4 arguments.
var juce::var::call | ( | const Identifier & | method, |
const var & | arg1, | ||
const var & | arg2, | ||
const var & | arg3, | ||
const var & | arg4, | ||
const var & | arg5 | ||
) | const |
Invokes a named method call with 5 arguments.
|
noexcept |
Returns a deep copy of this object.
For simple types this just returns a copy, but if the object contains any arrays or DynamicObjects, they will be cloned (recursively).
Returns true if this var has the same value as the one supplied.
Note that this ignores the type, so a string var "123" and an integer var with the value 123 are considered to be equal.
If this variant holds an array, this provides access to it.
NOTE: Beware when you use this - the array pointer is only valid for the lifetime of the variant that returned it, so be very careful not to call this method on temporary var objects that are the return-value of a function, and which may go out of scope before you use the array!
Referenced by juce::ValueWithDefault::setValue(), and juce::varArrayToNSArray().
|
noexcept |
If this variant holds a memory block, this provides access to it.
NOTE: Beware when you use this - the MemoryBlock pointer is only valid for the lifetime of the variant that returned it, so be very careful not to call this method on temporary var objects that are the return-value of a function, and which may go out of scope before you use the MemoryBlock!
|
noexcept |
Referenced by juce::varObjectToNSDictionary().
NativeFunction juce::var::getNativeFunction | ( | ) | const |
If this object is a method, this returns the function pointer.
|
noexcept |
var juce::var::getProperty | ( | const Identifier & | propertyName, |
const var & | defaultReturnValue | ||
) | const |
If this variant is an object, this returns one of its properties, or a default fallback value if the property is not set.
|
noexcept |
Returns true if this variant is an object and if it has the given property.
Returns true if this var has the same type as the one supplied.
If the var is an array, this searches it for the first occurrence of the specified value, and returns its index.
If the var isn't an array, or if the value isn't found, this returns -1.
Inserts an element to the var, converting it to an array if it isn't already one.
If the var isn't an array, it will be converted to one, and if its value was non-void, this value will be kept as the first element of the new array. The parameter value will then be inserted into it. For more control over the array's contents, you can call getArray() and manipulate it directly as an Array<var>.
var juce::var::invoke | ( | const Identifier & | method, |
const var * | arguments, | ||
int | numArguments | ||
) | const |
Invokes a named method call with a list of arguments.
|
noexcept |
Referenced by juce::varArrayToNSArray().
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
Referenced by juce::varObjectToNSDictionary().
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
juce::var::operator String | ( | ) | const |
var& juce::var::operator= | ( | double | value | ) |
var& juce::var::operator= | ( | const char * | value | ) |
var& juce::var::operator= | ( | const wchar_t * | value | ) |
var& juce::var::operator= | ( | const MemoryBlock & | value | ) |
var& juce::var::operator= | ( | ReferenceCountedObject * | object | ) |
var& juce::var::operator= | ( | NativeFunction | method | ) |
If the var is an array, this can be used to return one of its elements.
To call this method, you must make sure that the var is actually an array, and that the index is a valid number. If these conditions aren't met, behaviour is undefined. For more control over the array's contents, you can call getArray() and manipulate it directly as an Array<var>.
If the var is an array, this can be used to return one of its elements.
To call this method, you must make sure that the var is actually an array, and that the index is a valid number. If these conditions aren't met, behaviour is undefined. For more control over the array's contents, you can call getArray() and manipulate it directly as an Array<var>.
const var& juce::var::operator[] | ( | const Identifier & | propertyName | ) | const |
If this variant is an object, this returns one of its properties.
const var& juce::var::operator[] | ( | const char * | propertyName | ) | const |
If this variant is an object, this returns one of its properties.
|
static |
Reads back a stored binary representation of a value.
The data in the stream must have been written using writeToStream(), or this will have unpredictable results.
void juce::var::remove | ( | int | index | ) |
If the var is an array, this removes one of its elements.
If the index is out-of-range or the var isn't an array, nothing will be done. For more control over the array's contents, you can call getArray() and manipulate it directly as an Array<var>.
void juce::var::resize | ( | int | numArrayElementsWanted | ) |
Treating the var as an array, this resizes it to contain the specified number of elements.
If the var isn't an array, it will be converted to one, and if its value was non-void, this value will be kept as the first element of the new array before resizing. For more control over the array's contents, you can call getArray() and manipulate it directly as an Array<var>.
int juce::var::size | ( | ) | const |
If the var is an array, this returns the number of elements.
If the var isn't actually an array, this will return 0.
|
noexcept |
String juce::var::toString | ( | ) | const |
Referenced by juce::ValueWithDefault::isUsingDefault(), and juce::VariantConverter< Type >::toVar().
|
staticnoexcept |
Returns a var object that can be used where you need the javascript "undefined" value.
void juce::var::writeToStream | ( | OutputStream & | output | ) | const |
Writes a binary representation of this value to a stream.
The data can be read back later using readFromStream().
|
private |
|
private |