Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXVariant Class Reference

A Variant type can hold any kind of object, be it a boolean, integer, real, string, or even array of Variants or dictionaries of variants. More...

#include <FXVariant.h>

Public Types

enum  Type {
  NullType =0, BoolType, CharType, IntType,
  UIntType, LongType, ULongType, FloatType,
  DoubleType, PointerType, StringType, ArrayType,
  MapType
}
 

Public Member Functions

 FXVariant ()
 Default constructor makes null type.
 
 FXVariant (const FXVariant &other)
 Copy constructor.
 
 FXVariant (FXbool val)
 Construct and initialize with bool.
 
 FXVariant (FXchar val)
 Construct and initialize with char.
 
 FXVariant (FXint val)
 Construct and initialize with int.
 
 FXVariant (FXuint val)
 Construct and initialize with unsigned int.
 
 FXVariant (FXlong val)
 Construct and initialize with long.
 
 FXVariant (FXulong val)
 Construct and initialize with unsigned long.
 
 FXVariant (FXfloat val)
 Construct and initialize with float.
 
 FXVariant (FXdouble val)
 Construct and initialize with double.
 
 FXVariant (FXptr val)
 Construct and initialize with pointer.
 
 FXVariant (const FXchar *val)
 Construct and initialize with constant string.
 
 FXVariant (const FXString &val)
 Construct and initialize with string.
 
void setType (Type t)
 Change type.
 
Type getType () const
 Return type.
 
FXival no () const
 Return size of array.
 
FXbool no (FXival n)
 Change number of elements in array.
 
FXbool isNull () const
 Is it a null?
 
FXbool isBool () const
 Is it a bool?
 
FXbool isChar () const
 Is it a character?
 
FXbool isInt () const
 Is it a int?
 
FXbool isUInt () const
 Is it a unsigned int?
 
FXbool isLong () const
 Is it a long?
 
FXbool isULong () const
 Is it a unsigned long?
 
FXbool isFloat () const
 Is it a float?
 
FXbool isDouble () const
 Is it a double?
 
FXbool isInteger () const
 Is it a integer (bool, char, ..., or long)?
 
FXbool isReal () const
 Is it a real (float or double)?
 
FXbool isNumber () const
 Is it any kind of number?
 
FXbool isPtr () const
 Is it a pointer?
 
FXbool isString () const
 Is it a string?
 
FXbool isArray () const
 Is it a array?
 
FXbool isMap () const
 Is it a map?
 
FXbool toBool () const
 Convert to bool; always OK.
 
FXptr toPtr () const
 Convert to pointer.
 
FXint toInt (FXbool *ok=nullptr) const
 Convert to int.
 
FXuint toUInt (FXbool *ok=nullptr) const
 Convert to unsigned int.
 
FXlong toLong (FXbool *ok=nullptr) const
 Convert to long.
 
FXulong toULong (FXbool *ok=nullptr) const
 Convert to unsigned long.
 
FXfloat toFloat (FXbool *ok=nullptr) const
 Convert to float.
 
FXdouble toDouble (FXbool *ok=nullptr) const
 Convert to double.
 
const FXchar * toChars () const
 Convert to char pointer.
 
FXString toString (FXbool *ok=nullptr) const
 Convert to string.
 
 operator FXbool () const
 Convert to bool.
 
 operator FXptr () const
 Convert to pointer.
 
 operator FXchar () const
 Convert to char.
 
 operator FXuchar () const
 Convert to unsigned char.
 
 operator FXshort () const
 Convert to short.
 
 operator FXushort () const
 Convert to unsigned short.
 
 operator FXint () const
 Convert to int.
 
 operator FXuint () const
 Convert to unsigned int.
 
 operator FXlong () const
 Convert to long.
 
 operator FXulong () const
 Convert to unsigned long.
 
 operator FXfloat () const
 Convert to float.
 
 operator FXdouble () const
 Convert to double.
 
 operator FXString () const
 Convert to string.
 
FXVariantoperator= (FXbool val)
 Assign with bool.
 
FXVariantoperator= (FXchar val)
 Assign with char.
 
FXVariantoperator= (FXint val)
 Assign with int.
 
FXVariantoperator= (FXuint val)
 Assign with unsigned int.
 
FXVariantoperator= (FXlong val)
 Assign with long.
 
FXVariantoperator= (FXulong val)
 Assign with unsigned long.
 
FXVariantoperator= (FXfloat val)
 Assign with float.
 
FXVariantoperator= (FXdouble val)
 Assign with double.
 
FXVariantoperator= (FXptr val)
 Assign with pointer.
 
FXVariantoperator= (const FXchar *val)
 Assign with constant string.
 
FXVariantoperator= (const FXString &val)
 Assign with string.
 
FXVariantoperator= (const FXVariant &val)
 Assign with variant.
 
FXVariantassign (const FXVariant &other)
 Assign with variant.
 
FXVariantadopt (FXVariant &other)
 Adopt variant from another.
 
FXVariantat (const FXchar *key)
 Return value of object member.
 
const FXVariantat (const FXchar *key) const
 Return value of object member.
 
FXVariantoperator[] (const FXchar *key)
 Return value of object member.
 
const FXVariantoperator[] (const FXchar *key) const
 Return value of object member.
 
FXVariantat (const FXString &key)
 Return value of object member.
 
const FXVariantat (const FXString &key) const
 Return value of object member.
 
FXVariantoperator[] (const FXString &key)
 Return value of object member.
 
const FXVariantoperator[] (const FXString &key) const
 Return value of object member.
 
FXVariantat (FXival idx)
 Return value of array member.
 
const FXVariantat (FXival idx) const
 Return value of array member.
 
FXVariantoperator[] (FXint idx)
 Return value of array member.
 
const FXVariantoperator[] (FXint idx) const
 
FXVariantoperator[] (FXival idx)
 Return value of array member.
 
const FXVariantoperator[] (FXival idx) const
 
FXbool has (const FXchar *key) const
 Check if key is mapped.
 
FXbool has (const FXString &key) const
 Check if key is mapped.
 
FXptr & asPtr ()
 Return the value of the variant as a pointer; variant type MUST be PointerType.
 
const FXptr & asPtr () const
 Return the value of the variant as a pointer; variant type MUST be PointerType.
 
FXlong & asLong ()
 Return the value of the variant as a long; variant type MUST be LongType.
 
const FXlong & asLong () const
 Return the value of the variant as a long; variant type MUST be LongType.
 
FXulong & asULong ()
 Return the value of the variant as an unsigned long; variant type MUST be ULongType.
 
const FXulong & asULong () const
 Return the value of the variant as an unsigned long; variant type MUST be ULongType.
 
FXdouble & asDouble ()
 Return the value of the variant as a double; variant type MUST be DoubleType.
 
const FXdouble & asDouble () const
 Return the value of the variant as a double; variant type MUST be DoubleType.
 
const FXchar * asChars () const
 Return the value of the variant as a char pointer; variant type MUST be StringType.
 
FXStringasString ()
 Return the value of the variant as a string-reference; variant type MUST be StringType.
 
const FXStringasString () const
 Return the value of the variant as a const string-reference; variant type MUST be StringType.
 
FXVariantArrayasArray ()
 Return the value of the variant as an array-reference; variant type MUST be ArrayType.
 
const FXVariantArrayasArray () const
 Return the value of the variant as a const array-reference; variant type MUST be ArrayType.
 
FXVariantMapasMap ()
 Return the value of the variant as an map-reference; variant type MUST be MapType.
 
const FXVariantMapasMap () const
 Return the value of the variant as a const map-reference; variant type MUST be MapType.
 
FXbool remove (const FXchar *key)
 Remove variant at key from map.
 
FXbool remove (const FXString &key)
 Remove variant at key from map.
 
FXbool erase (FXival idx)
 Erase variant at idx from array.
 
FXbool clear ()
 Clear the data.
 
 ~FXVariant ()
 Destroy.
 

Static Public Attributes

static const FXVariant null
 Default constant variant.
 

Detailed Description

A Variant type can hold any kind of object, be it a boolean, integer, real, string, or even array of Variants or dictionaries of variants.

Complex hierarchies of Variants can be loaded (and saved) using the JSON parser. When writing Variants, dictionaries and arrays are automatically grown. When reading Variants, non-existing dictionary entries or indexes outside arrays will read as 0 (for numbers), the empty string, or as an empty dictionary or array. For efficiency, you can hold references to Variants, for example to avoid repeatedly accessing dictionaries or arrays with the same key or index. However, be aware that adding or removing sub-items to dictionaries or arrays may cause reallocations of existing items and thus some care must be exercised when doing this.


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

Copyright © 1997-2022 Jeroen van der Zijp