OpenShot Library | libopenshot-audio  0.1.9
juce::var Class Reference

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...
 
class  VariantType
 
class  VariantType_Array
 
class  VariantType_Binary
 
class  VariantType_Bool
 
class  VariantType_Double
 
class  VariantType_Int
 
class  VariantType_Int64
 
class  VariantType_Method
 
class  VariantType_Object
 
class  VariantType_String
 
class  VariantType_Undefined
 
class  VariantType_Void
 

Public Types

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

Public Member Functions

 var () noexcept
 Creates a void variant. More...
 
 ~var () noexcept
 Destructor. 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)
 
varoperator= (const var &valueToCopy)
 
varoperator= (int value)
 
varoperator= (int64 value)
 
varoperator= (bool value)
 
varoperator= (double value)
 
varoperator= (const char *value)
 
varoperator= (const wchar_t *value)
 
varoperator= (const String &value)
 
varoperator= (const MemoryBlock &value)
 
varoperator= (const Array< var > &value)
 
varoperator= (ReferenceCountedObject *object)
 
varoperator= (NativeFunction method)
 
 var (var &&) noexcept
 
 var (String &&)
 
 var (MemoryBlock &&)
 
 var (Array< var > &&)
 
varoperator= (var &&) noexcept
 
varoperator= (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
 If this variant holds an array, this provides access to it. More...
 
MemoryBlockgetBinaryData () const noexcept
 If this variant holds a memory block, this provides access to it. More...
 
ReferenceCountedObjectgetObject () const noexcept
 
DynamicObjectgetDynamicObject () 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
 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...
 
bool hasSameTypeAs (const var &other) const noexcept
 Returns true if this var has the same type as the one supplied. More...
 
var clone () const noexcept
 Returns a deep copy of this object. More...
 
int size () const
 If the var is an array, this returns the number of elements. More...
 
const varoperator[] (int arrayIndex) const
 If the var is an array, this can be used to return one of its elements. More...
 
varoperator[] (int arrayIndex)
 If the var is an array, this can be used to return one of its elements. More...
 
void append (const var &valueToAppend)
 Appends an element to the var, converting it to an array if it isn't already one. 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...
 
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 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...
 
const varoperator[] (const Identifier &propertyName) const
 If this variant is an object, this returns one of its properties. More...
 
const varoperator[] (const char *propertyName) const
 If this variant is an object, this returns one of its properties. More...
 
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...
 
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 invoke (const Identifier &method, const var *arguments, int numArguments) const
 Invokes a named method call with a list of arguments. More...
 
NativeFunction getNativeFunction () const
 If this object is a method, this returns the function pointer. More...
 
void writeToStream (OutputStream &output) const
 Writes a binary representation of this value to a stream. More...
 

Static Public Member Functions

static var undefined () noexcept
 Returns a var object that can be used where you need the javascript "undefined" value. More...
 
static var readFromStream (InputStream &input)
 Reads back a stored binary representation of a value. More...
 

Friends

bool canCompare (const var &, const var &)
 

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 45 of file juce_Variant.h.

Constructor & Destructor Documentation

◆ var()

juce::var::var ( )
noexcept

Creates a void variant.

Definition at line 441 of file juce_Variant.cpp.

Referenced by getBinaryData(), readFromStream(), undefined(), and ~var().

◆ ~var()

Member Function Documentation

◆ undefined()

var juce::var::undefined ( )
staticnoexcept

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

Definition at line 484 of file juce_Variant.cpp.

References var().

Referenced by juce::JavascriptEngine::RootObject::FunctionObject::writeAsJSON().

◆ 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 507 of file juce_Variant.cpp.

Referenced by indexOf(), operator[](), remove(), juce::ValueWithDefault::setValue(), and size().

◆ 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 508 of file juce_Variant.cpp.

References var().

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

See also
equalsWithSameType

Definition at line 568 of file juce_Variant.cpp.

Referenced by hasSameTypeAs(), and juce::StringRef::StringRef().

◆ 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 573 of file juce_Variant.cpp.

References hasSameTypeAs().

Referenced by juce::SimpleValueSource::setValue().

◆ 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 578 of file juce_Variant.cpp.

References juce::String::compare(), and equals().

Referenced by equalsWithSameType().

◆ 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 610 of file juce_Variant.cpp.

References clone().

Referenced by clone().

◆ 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 693 of file juce_Variant.cpp.

References getArray().

◆ operator[]() [1/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 701 of file juce_Variant.cpp.

References getArray().

Referenced by operator[]().

◆ operator[]() [2/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 712 of file juce_Variant.cpp.

References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::add(), and getArray().

◆ 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 737 of file juce_Variant.cpp.

Referenced by juce::JSON::parseQuotedString().

◆ 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 748 of file juce_Variant.cpp.

◆ 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 742 of file juce_Variant.cpp.

References getArray().

◆ 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 753 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 758 of file juce_Variant.cpp.

References getArray().

◆ operator[]() [3/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 616 of file juce_Variant.cpp.

References getProperty().

◆ operator[]() [4/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 624 of file juce_Variant.cpp.

References operator[]().

◆ 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 629 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 637 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 658 of file juce_Variant.cpp.

References invoke().

◆ 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 663 of file juce_Variant.cpp.

References invoke().

◆ 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 668 of file juce_Variant.cpp.

References invoke().

◆ 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 674 of file juce_Variant.cpp.

References invoke().

◆ 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 680 of file juce_Variant.cpp.

References invoke().

◆ 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 686 of file juce_Variant.cpp.

References invoke().

◆ 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 650 of file juce_Variant.cpp.

Referenced by call().

◆ getNativeFunction()

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

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

Definition at line 645 of file juce_Variant.cpp.

◆ 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 767 of file juce_Variant.cpp.

◆ readFromStream()


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