JUCE
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes
var Class Reference

A variant class, that can be used to hold a range of primitive values. More...

List of all members.

Public Types

typedef const var(DynamicObject::* MethodFunction )(const var *arguments, int numArguments)
typedef Identifier identifier

Public Member Functions

 var () noexcept
 Creates a void variant.
 ~var () noexcept
 Destructor.
 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 (ReferenceCountedObject *object)
 var (MethodFunction method) noexcept
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 Array< var > &value)
varoperator= (ReferenceCountedObject *object)
varoperator= (MethodFunction method)
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
ReferenceCountedObjectgetObject () const noexcept
DynamicObjectgetDynamicObject () const noexcept
bool isVoid () 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 isMethod () const noexcept
bool equals (const var &other) const noexcept
 Returns true if this var has the same value as the one supplied.
bool equalsWithSameType (const var &other) const noexcept
 Returns true if this var has the same value and type as the one supplied.
int size () const
 If the var is an array, this returns the number of elements.
const varoperator[] (int arrayIndex) const
 If the var is an array, this can be used to return one of its elements.
varoperator[] (int arrayIndex)
 If the var is an array, this can be used to return one of its elements.
void append (const var &valueToAppend)
 Appends an element to the var, converting it to an array if it isn't already one.
void insert (int index, const var &value)
 Inserts an element to the var, converting it to an array if it isn't already one.
void remove (int index)
 If the var is an array, this removes one of its elements.
void resize (int numArrayElementsWanted)
 Treating the var as an array, this resizes it to contain the specified number of elements.
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.
var operator[] (const Identifier &propertyName) const
 If this variant is an object, this returns one of its properties.
var operator[] (const char *propertyName) const
 If this variant is an object, this returns one of its properties.
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.
var call (const Identifier &method) const
 If this variant is an object, this invokes one of its methods with no arguments.
var call (const Identifier &method, const var &arg1) const
 If this variant is an object, this invokes one of its methods with one argument.
var call (const Identifier &method, const var &arg1, const var &arg2) const
 If this variant is an object, this invokes one of its methods with 2 arguments.
var call (const Identifier &method, const var &arg1, const var &arg2, const var &arg3)
 If this variant is an object, this invokes one of its methods with 3 arguments.
var call (const Identifier &method, const var &arg1, const var &arg2, const var &arg3, const var &arg4) const
 If this variant is an object, this invokes one of its methods with 4 arguments.
var call (const Identifier &method, const var &arg1, const var &arg2, const var &arg3, const var &arg4, const var &arg5) const
 If this variant is an object, this invokes one of its methods with 5 arguments.
var invoke (const Identifier &method, const var *arguments, int numArguments) const
 If this variant is an object, this invokes one of its methods with a list of arguments.
void writeToStream (OutputStream &output) const
 Writes a binary representation of this value to a stream.

Static Public Member Functions

static var readFromStream (InputStream &input)
 Reads back a stored binary representation of a value.

Static Public Attributes

static const var null
 A static var object that can be used where you need an empty variant object.

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

Member Typedef Documentation

typedef const var(DynamicObject::* var::MethodFunction)(const var *arguments, int numArguments)

Constructor & Destructor Documentation

var::var ( )

Creates a void variant.

var::~var ( )

Destructor.

var::var ( const var valueToCopy)
var::var ( int  value)
var::var ( int64  value)
var::var ( bool  value)
var::var ( double  value)
var::var ( const char *  value)
var::var ( const wchar_t *  value)
var::var ( const String value)
var::var ( const Array< var > &  value)
var::var ( MethodFunction  method)

Member Function Documentation

var& var::operator= ( const var valueToCopy)
var& var::operator= ( int  value)
var& var::operator= ( int64  value)
var& var::operator= ( bool  value)
var& var::operator= ( double  value)
var& var::operator= ( const char *  value)
var& var::operator= ( const wchar_t *  value)
var& var::operator= ( const String value)
var& var::operator= ( const Array< var > &  value)
var& var::operator= ( ReferenceCountedObject object)
var& var::operator= ( MethodFunction  method)
void var::swapWith ( var other)
var::operator int ( ) const
var::operator int64 ( ) const
var::operator bool ( ) const
var::operator float ( ) const
var::operator double ( ) const
var::operator String ( ) const
String var::toString ( ) const
Array<var>* var::getArray ( ) const
bool var::isVoid ( ) const
bool var::isInt ( ) const
bool var::isInt64 ( ) const
bool var::isBool ( ) const
bool var::isDouble ( ) const
bool var::isString ( ) const
bool var::isObject ( ) const
bool var::isArray ( ) const
bool var::isMethod ( ) const
bool var::equals ( const var other) const

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
bool var::equalsWithSameType ( const var other) const

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

const var& 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>.

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

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

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

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

var var::operator[] ( const Identifier propertyName) const

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

var var::operator[] ( const char *  propertyName) const

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

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

var var::call ( const Identifier method) const

If this variant is an object, this invokes one of its methods with no arguments.

var var::call ( const Identifier method,
const var arg1 
) const

If this variant is an object, this invokes one of its methods with one argument.

var var::call ( const Identifier method,
const var arg1,
const var arg2 
) const

If this variant is an object, this invokes one of its methods with 2 arguments.

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

If this variant is an object, this invokes one of its methods with 3 arguments.

var var::call ( const Identifier method,
const var arg1,
const var arg2,
const var arg3,
const var arg4 
) const

If this variant is an object, this invokes one of its methods with 4 arguments.

var var::call ( const Identifier method,
const var arg1,
const var arg2,
const var arg3,
const var arg4,
const var arg5 
) const

If this variant is an object, this invokes one of its methods with 5 arguments.

var var::invoke ( const Identifier method,
const var arguments,
int  numArguments 
) const

If this variant is an object, this invokes one of its methods with a list of arguments.

void 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
static var 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

Member Data Documentation

const var var::null [static]

A static var object that can be used where you need an empty variant object.


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