OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
juce::var Class Reference

`#include <juce_Variant.h>`

## Classes
struct | NativeFunctionArgs

## Public Types
using | NativeFunction = std::function<var (const NativeFunctionArgs&)>

## Public Member Functions
| 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
| 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 Public Member Functions
static var | undefined () noexcept
static var | readFromStream (InputStream &input)

## Detailed Description

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.

See also
  JSON, DynamicObject

Definition at line 41 of file juce_Variant.h.

## Member Typedef Documentation

## ◆ NativeFunction

using juce::var::NativeFunction = std::function<var (const NativeFunctionArgs&)>

Definition at line 57 of file juce_Variant.h.

## Constructor & Destructor Documentation

## ◆ var() [1/19]

juce::var::var | ( |  | ) |
| noexcept

Creates a void variant.

Definition at line 497 of file juce_Variant.cpp.

Referenced by readFromStream(), and undefined().

## ◆ ~var()

juce::var::~var | ( |  | ) |
| noexcept

Destructor.

Definition at line 499 of file juce_Variant.cpp.

## ◆ var() [2/19]

juce::var::var | ( | const var & | valueToCopy | ) |

Definition at line 502 of file juce_Variant.cpp.

## ◆ var() [3/19]

juce::var::var | ( | int | value | ) |
| noexcept

Definition at line 507 of file juce_Variant.cpp.

## ◆ var() [4/19]

juce::var::var | ( | int64 | value | ) |
| noexcept

Definition at line 508 of file juce_Variant.cpp.

## ◆ var() [5/19]

juce::var::var | ( | bool | value | ) |
| noexcept

Definition at line 509 of file juce_Variant.cpp.

## ◆ var() [6/19]

juce::var::var | ( | double | value | ) |
| noexcept

Definition at line 510 of file juce_Variant.cpp.

## ◆ var() [7/19]

juce::var::var | ( | const char * | value | ) |

Definition at line 514 of file juce_Variant.cpp.

## ◆ var() [8/19]

juce::var::var | ( | const wchar_t * | value | ) |

Definition at line 515 of file juce_Variant.cpp.

## ◆ var() [9/19]

juce::var::var | ( | const String & | value | ) |

Definition at line 513 of file juce_Variant.cpp.

## ◆ var() [10/19]

juce::var::var | ( | const Array< var > & | value | ) |

Definition at line 512 of file juce_Variant.cpp.

## ◆ var() [11/19]

juce::var::var | ( | const StringArray & | value | ) |

Definition at line 519 of file juce_Variant.cpp.

## ◆ var() [12/19]

juce::var::var | ( | ReferenceCountedObject * | object | ) |

Definition at line 530 of file juce_Variant.cpp.

## ◆ var() [13/19]

juce::var::var | ( | NativeFunction | method | ) |
| noexcept

Definition at line 511 of file juce_Variant.cpp.

## ◆ var() [14/19]

juce::var::var | ( | const void * | binaryData,
|  | size_t | dataSize )

Definition at line 516 of file juce_Variant.cpp.

## ◆ var() [15/19]

juce::var::var | ( | const MemoryBlock & | binaryData | ) |

Definition at line 517 of file juce_Variant.cpp.

## ◆ var() [16/19]

juce::var::var | ( | var && | other | ) |
| noexcept

Definition at line 585 of file juce_Variant.cpp.

## ◆ var() [17/19]

juce::var::var | ( | String && | v | ) |

Definition at line 598 of file juce_Variant.cpp.

## ◆ var() [18/19]

juce::var::var | ( | MemoryBlock && | v | ) |

Definition at line 603 of file juce_Variant.cpp.

## ◆ var() [19/19]

juce::var::var | ( | Array< var > && | v | ) |

Definition at line 608 of file juce_Variant.cpp.

## Member Function Documentation

## ◆ append()

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>.

Definition at line 791 of file juce_Variant.cpp.

## ◆ call() [1/6]

var juce::var::call | ( | const Identifier & | method | ) | const

Invokes a named method call with no arguments.

Definition at line 712 of file juce_Variant.cpp.

## ◆ call() [2/6]

var juce::var::call | ( | const Identifier & | method,
|  | const var & | arg1 ) const

Invokes a named method call with one argument.

Definition at line 717 of file juce_Variant.cpp.

## ◆ call() [3/6]

var juce::var::call | ( | const Identifier & | method,
|  | const var & | arg1,
|  | const var & | arg2 ) const

Invokes a named method call with 2 arguments.

Definition at line 722 of file juce_Variant.cpp.

## ◆ call() [4/6]

var juce::var::call | ( | const Identifier & | method,
|  | const var & | arg1,
|  | const var & | arg2,
|  | const var & | arg3 )

Invokes a named method call with 3 arguments.

Definition at line 728 of file juce_Variant.cpp.

## ◆ call() [5/6]

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.

Definition at line 734 of file juce_Variant.cpp.

## ◆ call() [6/6]

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.

Definition at line 740 of file juce_Variant.cpp.

## ◆ clone()

var juce::var::clone | ( |  | ) | const
| 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).

Definition at line 664 of file juce_Variant.cpp.

## ◆ equals()

bool juce::var::equals | ( | const var & | other | ) | const
| noexcept

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.

Note that equality checking depends on the "wrapped" type of the object on which equals() is called. That means the following code will convert the right-hand-side argument to a string and compare the string values, because the object on the left-hand-side was initialised from a string:

var ("123").equals (var (123))
juce::var
Definition juce_Variant.h:42
juce::var::var
var() noexcept
Definition juce_Variant.cpp:497

However, the following code will convert the right-hand-side argument to a double and compare the values as doubles, because the object on the left-hand-side was initialised from a double:

var (45.6).equals ("45.6000")

See also
  equalsWithSameType

Definition at line 622 of file juce_Variant.cpp.

## ◆ equalsWithSameType()

bool juce::var::equalsWithSameType | ( | const var & | other | ) | const
| noexcept

Returns true if this var has the same value and type as the one supplied. This differs from equals() because e.g. "123" and 123 will be considered different.

See also
  equals

Definition at line 627 of file juce_Variant.cpp.

## ◆ getArray()

Array< var > * juce::var::getArray | ( |  | ) | const
| noexcept

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!

Definition at line 561 of file juce_Variant.cpp.

Referenced by juce::JSONUtils::deepEqual(), indexOf(), operator[](), operator[](), remove(), juce::JSONUtils::setPointer(), juce::ValueTreePropertyWithDefault::setValue(), size(), and juce::JSON::writeToStream().

## ◆ getBinaryData()

MemoryBlock * juce::var::getBinaryData | ( |  | ) | const
| 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!

Definition at line 562 of file juce_Variant.cpp.

## ◆ getDynamicObject()

DynamicObject * juce::var::getDynamicObject | ( |  | ) | const
| noexcept

Definition at line 563 of file juce_Variant.cpp.

## ◆ getNativeFunction()

var::NativeFunction juce::var::getNativeFunction | ( |  | ) | const

If this object is a method, this returns the function pointer.

Definition at line 699 of file juce_Variant.cpp.

## ◆ getObject()

ReferenceCountedObject * juce::var::getObject | ( |  | ) | const
| noexcept

Definition at line 560 of file juce_Variant.cpp.

## ◆ getProperty()

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.

Definition at line 683 of file juce_Variant.cpp.

Referenced by operator[]().

## ◆ hasProperty()

bool juce::var::hasProperty | ( | const Identifier & | propertyName | ) | const
| noexcept

Returns true if this variant is an object and if it has the given property.

Definition at line 691 of file juce_Variant.cpp.

## ◆ hasSameTypeAs()

bool juce::var::hasSameTypeAs | ( | const var & | other | ) | const
| noexcept

Returns true if this var has the same type as the one supplied.

Definition at line 632 of file juce_Variant.cpp.

## ◆ indexOf()

int juce::var::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. If the var isn't an array, or if the value isn't found, this returns -1.

Definition at line 812 of file juce_Variant.cpp.

## ◆ insert()

void juce::var::insert | ( | int | index,
|  | const var & | value )

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>.

Definition at line 802 of file juce_Variant.cpp.

## ◆ invoke()

var juce::var::invoke | ( | const Identifier & | method,
|  | const var * | arguments,
|  | int | numArguments ) const

Invokes a named method call with a list of arguments.

Definition at line 704 of file juce_Variant.cpp.

Referenced by call(), call(), call(), call(), call(), and call().

## ◆ isArray()

bool juce::var::isArray | ( |  | ) | const
| noexcept

Definition at line 549 of file juce_Variant.cpp.

## ◆ isBinaryData()

bool juce::var::isBinaryData | ( |  | ) | const
| noexcept

Definition at line 550 of file juce_Variant.cpp.

## ◆ isBool()

bool juce::var::isBool | ( |  | ) | const
| noexcept

Definition at line 545 of file juce_Variant.cpp.

## ◆ isDouble()

bool juce::var::isDouble | ( |  | ) | const
| noexcept

Definition at line 546 of file juce_Variant.cpp.

## ◆ isInt()

bool juce::var::isInt | ( |  | ) | const
| noexcept

Definition at line 543 of file juce_Variant.cpp.

## ◆ isInt64()

bool juce::var::isInt64 | ( |  | ) | const
| noexcept

Definition at line 544 of file juce_Variant.cpp.

## ◆ isMethod()

bool juce::var::isMethod | ( |  | ) | const
| noexcept

Definition at line 551 of file juce_Variant.cpp.

## ◆ isObject()

bool juce::var::isObject | ( |  | ) | const
| noexcept

Definition at line 548 of file juce_Variant.cpp.

## ◆ isString()

bool juce::var::isString | ( |  | ) | const
| noexcept

Definition at line 547 of file juce_Variant.cpp.

## ◆ isUndefined()

bool juce::var::isUndefined | ( |  | ) | const
| noexcept

Definition at line 542 of file juce_Variant.cpp.

## ◆ isVoid()

bool juce::var::isVoid | ( |  | ) | const
| noexcept

Definition at line 541 of file juce_Variant.cpp.

## ◆ operator bool()

juce::var::operator bool | ( |  | ) | const
| noexcept

Definition at line 555 of file juce_Variant.cpp.

## ◆ operator double()

juce::var::operator double | ( |  | ) | const
| noexcept

Definition at line 557 of file juce_Variant.cpp.

## ◆ operator float()

juce::var::operator float | ( |  | ) | const
| noexcept

Definition at line 556 of file juce_Variant.cpp.

## ◆ operator int()

juce::var::operator int | ( |  | ) | const
| noexcept

Definition at line 553 of file juce_Variant.cpp.

## ◆ operator int64()

juce::var::operator int64 | ( |  | ) | const
| noexcept

Definition at line 554 of file juce_Variant.cpp.

## ◆ operator String()

juce::var::operator String | ( |  | ) | const

Definition at line 559 of file juce_Variant.cpp.

## ◆ operator=() [1/14]

var & juce::var::operator= | ( | bool | value | ) |

Definition at line 575 of file juce_Variant.cpp.

## ◆ operator=() [2/14]

var & juce::var::operator= | ( | const Array< var > & | value | ) |

Definition at line 581 of file juce_Variant.cpp.

## ◆ operator=() [3/14]

var & juce::var::operator= | ( | const char * | value | ) |

Definition at line 577 of file juce_Variant.cpp.

## ◆ operator=() [4/14]

var & juce::var::operator= | ( | const MemoryBlock & | value | ) |

Definition at line 580 of file juce_Variant.cpp.

## ◆ operator=() [5/14]

var & juce::var::operator= | ( | const String & | value | ) |

Definition at line 579 of file juce_Variant.cpp.

## ◆ operator=() [6/14]

var & juce::var::operator= | ( | const var & | valueToCopy | ) |

Definition at line 572 of file juce_Variant.cpp.

## ◆ operator=() [7/14]

var & juce::var::operator= | ( | const wchar_t * | value | ) |

Definition at line 578 of file juce_Variant.cpp.

## ◆ operator=() [8/14]

var & juce::var::operator= | ( | double | value | ) |

Definition at line 576 of file juce_Variant.cpp.

## ◆ operator=() [9/14]

var & juce::var::operator= | ( | int | value | ) |

Definition at line 573 of file juce_Variant.cpp.

## ◆ operator=() [10/14]

var & juce::var::operator= | ( | int64 | value | ) |

Definition at line 574 of file juce_Variant.cpp.

## ◆ operator=() [11/14]

var & juce::var::operator= | ( | NativeFunction | method | ) |

Definition at line 583 of file juce_Variant.cpp.

## ◆ operator=() [12/14]

var & juce::var::operator= | ( | ReferenceCountedObject * | object | ) |

Definition at line 582 of file juce_Variant.cpp.

## ◆ operator=() [13/14]

var & juce::var::operator= | ( | String && | v | ) |

Definition at line 613 of file juce_Variant.cpp.

## ◆ operator=() [14/14]

var & juce::var::operator= | ( | var && | other | ) |
| noexcept

Definition at line 592 of file juce_Variant.cpp.

## ◆ operator[]() [1/4]

const var & juce::var::operator[] | ( | const char * | propertyName | ) | const

If this variant is an object, this returns one of its properties.

Definition at line 678 of file juce_Variant.cpp.

## ◆ operator[]() [2/4]

const var & juce::var::operator[] | ( | const Identifier & | propertyName | ) | const

If this variant is an object, this returns one of its properties.

Definition at line 670 of file juce_Variant.cpp.

## ◆ operator[]() [3/4]

var & juce::var::operator[] | ( | int | arrayIndex | ) |

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>.

Definition at line 766 of file juce_Variant.cpp.

## ◆ operator[]() [4/4]

const var & juce::var::operator[] | ( | int | arrayIndex | ) | const

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>.

Definition at line 755 of file juce_Variant.cpp.

Referenced by operator[]().

## ◆ readFromStream()

var juce::var::readFromStream | ( | InputStream & | input | ) |
| 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.

See also
  JSON

Definition at line 826 of file juce_Variant.cpp.

Referenced by juce::ValueTreeSynchroniser::applyChange(), juce::ValueTree::readFromStream(), and readFromStream().

## ◆ remove()

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>.

Definition at line 796 of file juce_Variant.cpp.

Referenced by juce::DynamicObject::removeProperty().

## ◆ resize()

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>.

Definition at line 807 of file juce_Variant.cpp.

## ◆ size()

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.

Definition at line 747 of file juce_Variant.cpp.

## ◆ swapWith()

void juce::var::swapWith | ( | var & | other | ) |
| noexcept

Definition at line 566 of file juce_Variant.cpp.

## ◆ toString()

String juce::var::toString | ( |  | ) | const

Definition at line 558 of file juce_Variant.cpp.

## ◆ undefined()

var juce::var::undefined | ( |  | ) |
| static noexcept

Returns a var object that can be used where you need the javascript "undefined" value.

Definition at line 538 of file juce_Variant.cpp.

Referenced by juce::JavascriptEngine::callFunction(), juce::JavascriptEngine::callFunctionObject(), and juce::JavascriptEngine::evaluate().

## ◆ writeToStream()

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().

See also
  JSON

Definition at line 821 of file juce_Variant.cpp.

The documentation for this class was generated from the following files:

- juce_Variant.h
- juce_Variant.cpp