C12Adapter Opensource C++ Interface
MVariant Class Reference

Variant data type, where a particular value type is dynamically determined at runtime. More...

Classes

class  ObjectByValue
 Local placeholder class, used for passing small objects by value. More...
 
class  PointerBytesType
 A hidden type of pointer size. More...
 

Public Types

enum  Type {
  VAR_EMPTY,
  VAR_BOOL,
  VAR_BYTE,
  VAR_CHAR,
  VAR_UINT,
  VAR_INT,
  VAR_DOUBLE,
  VAR_BYTE_STRING,
  VAR_STRING,
  VAR_STRING_COLLECTION,
  VAR_OBJECT,
  VAR_OBJECT_EMBEDDED,
  VAR_VARIANT_COLLECTION,
  VAR_MAP,
  VAR_VARIANT
}
 Possible value types, sorted in the order of their promotional conversion. More...
 
enum  AcceptByteStringType { ACCEPT_BYTE_STRING }
 Tag that allows telling byte string constructor from the standard string constructor. More...
 
enum  AcceptByteStringCollectionType { ACCEPT_BYTE_STRING_COLLECTION }
 Tag that allows telling byte string constructor from the standard string constructor. More...
 
enum  AcceptStringType { ACCEPT_STRING }
 Tag that allows telling string constructor from the byte string constructor. More...
 
enum  AcceptObjectEmbedded { ACCEPT_OBJECT_EMBEDDED }
 Tag that allows telling an embedded object from an ordinary object. More...
 
typedef std::vector< MVariantVariantVector
 Externally visible collection of variants.
 

Public Member Functions

 MVariant ()
 Default constructor. More...
 
 MVariant (Type type)
 Create an empty object of a given type. More...
 
 MVariant (bool n)
 Construct the value of type bool. More...
 
 MVariant (char c)
 Construct the value of type char with the value specified. More...
 
 MVariant (wchar_t c)
 Construct the variant from a wide character. More...
 
 MVariant (Muint8 b)
 Construct the variant of byte type with the value specified. More...
 
 MVariant (int n)
 Construct the variant of type int with the value specified. More...
 
 MVariant (unsigned n)
 Construct the variant of type unsigned int with the value specified. More...
 
 MVariant (long n)
 Construct the variant with the long integer value. More...
 
 MVariant (unsigned long n)
 Construct the variant with the unsigned long integer value. More...
 
 MVariant (Mint64 n)
 Construct the variant from 64-bit signed integer. More...
 
 MVariant (Muint64 n)
 Construct the variant from 64-bit unsigned integer. More...
 
 MVariant (double n)
 Construct the variant of type double. More...
 
 MVariant (MConstChars s)
 Construct the variant of type string. More...
 
 MVariant (MConstChars s, unsigned len, AcceptStringType tag)
 Construct the variant of type string. More...
 
 MVariant (const wchar_t *s)
 Construct the variant of type string. More...
 
 MVariant (const wchar_t *s, unsigned len, AcceptStringType tag=MVariant::ACCEPT_STRING)
 Construct the variant of type string. More...
 
 MVariant (const MWideString &s)
 Construct the variant of type string. More...
 
 MVariant (const MStdString &s)
 Construct the variant of type string. More...
 
 MVariant (const MByteString &s, AcceptByteStringType tag)
 Construct the variant of type byte string. More...
 
 MVariant (const MByteStringVector &v, AcceptByteStringCollectionType tag)
 Construct the variant of type varaint collection that hold byte strings. More...
 
 MVariant (const MStdStringVector &v)
 Construct the variant of type string collection. More...
 
 MVariant (const VariantVector &v)
 Construct the variant of type varaint collection. More...
 
 MVariant (MObject *o)
 Construct the variant of type object, which references the object given. More...
 
template<class C >
 MVariant (const C *o, AcceptObjectEmbedded tag)
 Construct the variant of type embedded object. More...
 
 MVariant (const MVariant &other)
 Construct the variant from a given copy. More...
 
 ~MVariant ()
 Destroy the variant object, reclaim memory if necessary.
 
MVariant::Type GetType () const
 Get the type of the variant object.
 
bool IsEmpty () const
 Tells whether the variant has no value. More...
 
bool IsNumeric () const
 Whether the variant is of numeric type, so the arithmetic operations can be performed with it. More...
 
bool IsIndexed () const
 Whether the variant can be indexed. More...
 
bool IsCollection () const
 Whether the variant is a collection, array, or a map (which is a key-indexed collection). More...
 
bool IsObject () const
 Whether the variant is of object or embedded object type. More...
 
MVariantoperator= (bool b)
 Assignment operator that takes variable of type bool.
 
MVariantoperator= (char c)
 Assignment operator that takes variable of type char.
 
MVariantoperator= (wchar_t c)
 Assignment operator that takes variable of type char. More...
 
MVariantoperator= (Muint8 b)
 Assignment operator that takes variable of type byte.
 
MVariantoperator= (int n)
 Assignment operator that takes variable of type int.
 
MVariantoperator= (unsigned n)
 Assignment operator that takes variable of type unsigned int.
 
MVariantoperator= (long n)
 Assignment operator that takes variable of type long.
 
MVariantoperator= (unsigned long n)
 Assignment operator that takes variable of type unsigned long.
 
MVariantoperator= (Mint64 v)
 Assignment operator that takes variable of 64-bit integer type.
 
MVariantoperator= (Muint64 v)
 Assignment operator that takes variable of 64-bit unsigned integer type.
 
MVariantoperator= (double f)
 Assignment operator that takes variable of type double.
 
MVariantoperator= (MConstChars p)
 Assignment operator that takes variable of type pointer to the constant zero terminated string.
 
MVariantoperator= (const MStdString &s)
 Assignment operator that takes variable of type string.
 
MVariantoperator= (const wchar_t *s)
 Assignment operator that takes variable of type constant pointer to zero terminated wide character string. More...
 
MVariantoperator= (const MWideString &s)
 Assignment operator that takes variable of type to wide string. More...
 
MVariantoperator= (const MStdStringVector &s)
 Assignment operator that takes variable of type string collection.
 
MVariantoperator= (const VariantVector &s)
 Assignment operator that takes variable of type variant vector.
 
MVariantoperator= (const MVariant &v)
 Assignment operator that takes variable of type MVariant.
 
MVariantoperator= (const ObjectByValue &o)
 Assignment operator that takes ObjectByValue stub, as handled by reflection.
 
void AssignByteString (const MByteString &v)
 Assign the byte string to the variant type.
 
void AssignByteStringCollection (const MByteStringVector &v)
 Assign the byte string vector to the variant type.
 
void Assign (const Muint8 *p, unsigned len)
 Assign the byte string to the variant type.
 
void Assign (const char *p, unsigned len)
 Assign the byte string to the variant type.
 
void AssignString (MConstChars p, unsigned len)
 Assign the string to the variant type.
 
void AssignString (const wchar_t *p, unsigned len)
 Assign the wide string to the variant type. More...
 
template<class C >
void AssignObjectEmbedded (const C *o)
 Assign the byte embedded object to the variant type. More...
 
MVariantoperator= (const MObject *v)
 Assignment operator that takes variable of type MObject. More...
 
const char * AsConstChars () const
 Interpret string related values of this variant as zero terminated string. More...
 
bool AsBool () const
 Interpret the variant value as type bool, if possible. More...
 
Muint8 AsByte () const
 Interpret the variant value as byte, if possible. More...
 
char AsChar () const
 Interpret the variant value as type char, if possible. More...
 
Muint32 AsDWord () const
 Interpret the variant value as double word. More...
 
int AsInt () const
 Interpret the variant value as integer type, if possible. More...
 
unsigned AsUInt () const
 Interpret the variant value as unsigned integer type, if possible. More...
 
long AsLong () const
 Interpret the variant value as long integer type, if possible. More...
 
unsigned long AsULong () const
 Interpret the variant value as unsigned long integer type, if possible. More...
 
Mint64 AsInt64 () const
 Interpret the variant value as 64-bit integer type, if possible. More...
 
Muint64 AsUInt64 () const
 Interpret the variant value as unsigned long integer type, if possible. More...
 
size_t AsSizeT () const
 Interpret the variant value as an integer type equivalent to size_t, if possible. More...
 
double AsDouble () const
 Interpret the variant value as double precision floating point, if possible. More...
 
MByteString AsByteString () const
 Interpret the variant value as byte string, if possible. More...
 
MStdString AsString () const
 Interpret the variant value as string, if possible. More...
 
MStdString AsString (unsigned mask) const
 Interpret the variant value as string, if possible, using mask that specifies the conversions to make. More...
 
MSharedString AsSharedString () const
 Interpret the variant value as shared string, if possible. More...
 
MStdString AsEscapedString () const
 Interpret the variant value as a string with C escapes, if possible. More...
 
MWideString AsWideString () const
 Interpret the variant value as wide string, if possible. More...
 
MWideString AsWideString (unsigned mask) const
 Interpret the variant value as wide string, if possible, using mask that specifies the conversions to make. More...
 
MWideString AsEscapedWideString () const
 Interpret the variant value as a wide string with C escapes, if possible. More...
 
MStdStringVector AsStringCollection () const
 Interpret the variant value as string collection, if possible. More...
 
MByteStringVector AsByteStringCollection () const
 Interpret the variant value as byte string collection, if possible. More...
 
VariantVector AsVariantCollection () const
 Interpret the variant value as variant collection, if possible. More...
 
void SetEmpty ()
 Discard the value of the variant type.
 
void SetEmptyWithObjectDelete ()
 Discard the value of the variant type, and if it is an object, delete it. More...
 
void SetToNull (MVariant::Type type)
 Discard the value of the variant type, and set it to null, either empty or zero value depending on the given type. More...
 
void ReserveElements (int count)
 Reserve the number of elements in the variant when variant is indexed. More...
 
void Swap (MVariant &)
 Efficiently swap the value with the given value.
 
void MoveFrom (MVariant &other)
 Fast method that moves the value to another variant, and sets the other variant type to Empty. More...
 
MVariant Pow (const MVariant &) const
 Return this object with the power of the object given. More...
 
MVariant GetAllMapKeys () const
 Return a variant vector of keys in this map. More...
 
MVariant GetAllMapValues () const
 Return a variant vector of values in this map. More...
 
const MVariantGetMapKeyByIndex (int i) const
 Return the value of a key in the map by its index. More...
 
const MVariantGetMapValueByIndex (int i) const
 Return the value of a key in the map by its index. More...
 
void SwapItems (int index1, int index2)
 Swap two indexed items in the array or collection. More...
 
bool IsPresent (const MVariant &it) const
 Returns true if the given item is in the variant. More...
 
int FindIndexOf (const MVariant &, bool reverse=false) const
 Find index of the given element in the indexed variant. More...
 
void AddToVariantCollection (const MVariant &v)
 Add the given variant as a whole to the collection. More...
 
MVariant GetSlice (int from, int to) const
 Return the slice of values for types that support subscripts. More...
 
void SetSlice (int from, int to, const MVariant &values)
 Set the slice of values for types that support subscripts. More...
 
bool operator== (const MVariant &) const
 Equality operator. More...
 
bool operator!= (const MVariant &other) const
 Inequality operator. More...
 
bool operator< (const MVariant &) const
 Less-than operator. More...
 
bool operator> (const MVariant &) const
 Greater-than operator. More...
 
bool operator<= (const MVariant &v) const
 Less-or-equal-than operator. More...
 
bool operator>= (const MVariant &v) const
 Greater-or-equal-than operator. More...
 
MVariant operator| (const MVariant &) const
 Operator OR. More...
 
MVariant operator& (const MVariant &) const
 Operator AND. More...
 
MVariant operator^ (const MVariant &) const
 Operator XOR. More...
 
MVariant operator! () const
 Unary operator NOT. More...
 
MVariant operator- () const
 Unary operator minus. More...
 
MVariant operator+ (const MVariant &) const
 Binary operator plus. More...
 
MVariant operator- (const MVariant &) const
 Binary operator minus. More...
 
MVariant operator* (const MVariant &) const
 Binary multiplication operator. More...
 
MVariant operator/ (const MVariant &) const
 Binary division operator. More...
 
MVariant operator% (const MVariant &) const
 Binary modulus operator. More...
 
MVariant operator<< (const MVariant &) const
 Bitwise left shift operator. More...
 
MVariant operator>> (const MVariant &) const
 Bitwise right shift operator. More...
 
MVariantoperator++ ()
 Prefix increment operator. More...
 
MVariantoperator-- ()
 Prefix decrement operator. More...
 
MVariantoperator+= (const MVariant &)
 Binary operator increment self by value. More...
 
MVariantoperator-= (const MVariant &)
 Binary operator decrement self by value. More...
 
MVariantoperator*= (const MVariant &)
 Binary operator multiply self by value. More...
 
MVariantoperator/= (const MVariant &)
 Binary operator divide self by value. More...
 
MVariantoperator%= (const MVariant &)
 Binary operator modulus self by value. More...
 
MVariantoperator>>= (const MVariant &)
 Binary operator right shift self by value. More...
 
MVariantoperator<<= (const MVariant &)
 Binary operator left shift self by value. More...
 
MVariantoperator|= (const MVariant &)
 Binary operator, binary or logical 'or' of self by value. More...
 
MVariantoperator&= (const MVariant &)
 Binary operator, binary or logical 'and' of self by value. More...
 
MVariantoperator^= (const MVariant &)
 Binary operator, binary or logical 'xor' of self by value. More...
 
 MVariant (const char *p, unsigned len)
 
 MVariant (const Muint8 *p, unsigned len)
 
int GetCount () const
 
void SetCount (int)
 
MObjectAsObject ()
 
MObjectAsObject () const
 
MObjectAsExistingObject ()
 
MObjectAsExistingObject () const
 
MVariant GetItem (const MVariant &index) const
 
MVariant GetItem (int index) const
 
MVariant GetItem (unsigned index) const
 
void SetItem (const MVariant &index, const MVariant &value)
 
void SetItem (int index, const MVariant &value)
 
void SetItem (unsigned index, const MVariant &value)
 
MVariantAccessItem (const MVariant &index)
 
MVariantAccessItem (int index)
 
MVariantAccessItem (unsigned index)
 
const MVariantAccessItem (const MVariant &index) const
 
const MVariantAccessItem (int index) const
 
const MVariantAccessItem (unsigned index) const
 

Static Public Member Functions

static void AdjustIndex (int &index, unsigned count)
 Adjust a given index so the negative index will mean counting from the end of the array. More...
 
static int AdjustSlice (int &from, int &to, unsigned count)
 Adjust a given slice so the negative index will mean counting from the end of the array. More...
 
static bool StaticIsObject (const MVariant *var)
 
static bool StaticIsObject (const MVariant &var)
 

Static Public Attributes

static const MStdString s_emptyString
 Empty string that is used in many places through the code.
 
static const MVariant s_null
 Empty variant, the same as NULL for pointers.
 

Detailed Description

Variant data type, where a particular value type is dynamically determined at runtime.

The uninitialized variant variable would be of empty type, and should not participate in operations other than the assignment into it, or else an exception is thrown. When performing value based operations, the class performs type conversions.

Member Enumeration Documentation

Tag that allows telling byte string constructor from the standard string constructor.

Enumerator
ACCEPT_BYTE_STRING_COLLECTION 

Single value of the tag.

Tag that allows telling byte string constructor from the standard string constructor.

Enumerator
ACCEPT_BYTE_STRING 

Single value of the tag.

Tag that allows telling an embedded object from an ordinary object.

Enumerator
ACCEPT_OBJECT_EMBEDDED 

Single value of the tag.

Tag that allows telling string constructor from the byte string constructor.

Enumerator
ACCEPT_STRING 

Single value of the tag.

Possible value types, sorted in the order of their promotional conversion.

Enumerator
VAR_EMPTY 

No value in the variant.

VAR_BOOL 

Variant has Boolean value.

VAR_BYTE 

Variant has Byte value.

VAR_CHAR 

Variant has Character value.

VAR_UINT 

Variant has unsigned integer value. Its conversion rate is smaller than INT, not like in C.

VAR_INT 

Variant has integer value.

VAR_DOUBLE 

Variant has double value.

VAR_BYTE_STRING 

Variant has the byte string.

VAR_STRING 

Variant has string value.

VAR_STRING_COLLECTION 

Variant has string collection value.

VAR_OBJECT 

Variant has an object.

VAR_OBJECT_EMBEDDED 

Object, embedded into the variant, can be copied with memory copy operation.

VAR_VARIANT_COLLECTION 

Array of any type of elements, array of variants.

VAR_MAP 

Map of key:value pairs, both are variants.

VAR_VARIANT 

Variant type by itself. Used externally by applications to denote variant as the whole type.

Constructor & Destructor Documentation

MVariant::MVariant ( )
inline

Default constructor.

The result type of the variant is MVariant::VAR_EMPTY.

MVariant::MVariant ( Type  type)
inline

Create an empty object of a given type.

The result type of the variant is the one given. The result value of the variant depends on the type:

  • For MVariant::VAR_BOOL it is False.
  • For MVariant::VAR_CHAR it is '\0'.
  • For all numeric types it is zero.
  • For strings and byte strings it is an empty string.
  • For collection types it is an empty collection.
  • For object types it is null.
Parameters
typeType of the variant
MVariant::MVariant ( bool  n)
inline

Construct the value of type bool.

The result type of the variant is MVariant::VAR_BOOL.

Parameters
nBoolean value, true or false.
MVariant::MVariant ( char  c)
inline

Construct the value of type char with the value specified.

The result type of the variant is MVariant::VAR_CHAR.

Parameters
cCharacter value.
MVariant::MVariant ( wchar_t  c)
inline

Construct the variant from a wide character.

The result type of the variant will depend on the given value as follows:

  • If c is an ASCII character, range 0 to 127, the result variant will be MVariant::VAR_CHAR.
  • Otherwise, for non-ASCII character the result will be a string, MVariant::VAR_STRING. The method will work correctly only if the current code page is UTF-8, which correstonds to M_UNICODE = 1.
Parameters
cCharacter value.
MVariant::MVariant ( Muint8  b)
inline

Construct the variant of byte type with the value specified.

The result type of the variant is MVariant::VAR_BYTE.

Parameters
bByte unsigned value, 0 to 255.
MVariant::MVariant ( int  n)
inline

Construct the variant of type int with the value specified.

The result type of the variant is MVariant::VAR_INT, which will always be a signed 32-bit value.

Parameters
nInteger value.
MVariant::MVariant ( unsigned  n)
inline

Construct the variant of type unsigned int with the value specified.

The result type of the variant is MVariant::VAR_UINT, which will always be an unsigned 32-bit value.

Parameters
nUnsigned integer value.
MVariant::MVariant ( long  n)
inline

Construct the variant with the long integer value.

If the given value fits within range of 32-bits integer the result type will be MVariant::VAR_INT. Otherwise, and it is only possible on platforms where a long integer is 64-bits, this will produce a variant of type MVariant::VAR_DOUBLE.

Parameters
nLong integer value.
MVariant::MVariant ( unsigned long  n)
inline

Construct the variant with the unsigned long integer value.

If the given value fits within range of 32-bits unsigned integer the result type will be MVariant::VAR_UINT. Otherwise, and it is only possible on platforms where an unsigned long integer is 64-bits, this will produce a variant of type MVariant::VAR_DOUBLE.

Parameters
nUnsigned long integer value.
MVariant::MVariant ( Mint64  n)
inline

Construct the variant from 64-bit signed integer.

If the given value fits within range of 32-bits integer the result type will be MVariant::VAR_INT. Otherwise, this will produce a variant of type MVariant::VAR_DOUBLE.

Parameters
n64-bit integer value.
MVariant::MVariant ( Muint64  n)
inline

Construct the variant from 64-bit unsigned integer.

If the given value fits within range of 32-bits unsigned integer the result type will be MVariant::VAR_UINT. Otherwise, this will produce a variant of type MVariant::VAR_DOUBLE.

Parameters
n64-bit integer value.
MVariant::MVariant ( double  n)
inline

Construct the variant of type double.

This will produce a variant of type MVariant::VAR_DOUBLE.

Parameters
nDouble precision floating point value.
MVariant::MVariant ( MConstChars  s)
inline

Construct the variant of type string.

This will produce a variant of type MVariant::VAR_STRING.

Parameters
sZero terminated constant character string given as pointer to the first character.
MVariant::MVariant ( MConstChars  s,
unsigned  len,
AcceptStringType  tag 
)
inline

Construct the variant of type string.

This will produce a variant of type MVariant::VAR_STRING. The tag parameter is necessary to distinguish this constructor from the one that creates a byte string. Use MVariant(const char*, unsigned, AcceptByteStringType) to construct a byte string.

Parameters
sConstant character string given as pointer to the first character.
lenExplicitly given length of the character string.
tagThe only accepted value is MVariant::ACCEPT_STRING
MVariant::MVariant ( const wchar_t *  s)
inline

Construct the variant of type string.

This will produce a variant of type MVariant::VAR_STRING. The conversion from wide character string to regular string will be done according to the following rules:

  • Only on Windows when M_UNICODE is false the current system 8-bit codepage will be used.
  • Otherwise UTF-8 codepage will be used. Newer applications should assume this to be default on all platforms.
Parameters
sZero terminated constant wide character string given as pointer to the first wide character.
MVariant::MVariant ( const wchar_t *  s,
unsigned  len,
AcceptStringType  tag = MVariant::ACCEPT_STRING 
)
inline

Construct the variant of type string.

This will produce a variant of type MVariant::VAR_STRING. The conversion from wide character string to regular string will be done according to the following rules:

  • Only on Windows when M_UNICODE is false the current system 8-bit codepage will be used.
  • Otherwise UTF-8 codepage will be used. Newer applications should assume this to be default on all platforms.
Parameters
sConstant wide character string given as pointer to the first wide character.
lenExplicitly given length of the character string.
tagThe only accepted value is MVariant::ACCEPT_STRING, and it can be ommitted since there is no clash with the byte string version.
MVariant::MVariant ( const MWideString s)
inline

Construct the variant of type string.

This will produce a variant of type MVariant::VAR_STRING. The conversion from wide character string to regular string will be done according to the following rules:

  • Only on Windows when M_UNICODE is false the current system 8-bit codepage will be used.
  • Otherwise UTF-8 codepage will be used. Newer applications should assume this to be default on all platforms.
Parameters
sWide character string value.
MVariant::MVariant ( const MStdString s)
inline

Construct the variant of type string.

This will produce a variant of type MVariant::VAR_STRING. Note that to C++ the type MByteString is indistinguishable from MStdString. Use MVariant(const MByteString& s, AcceptByteStringType) to construct a byte string.

Parameters
sCharacter string value.
MVariant::MVariant ( const char *  p,
unsigned  len 
)
inline

Construct the variant of type byte string.

This will produce a variant of type MVariant::VAR_BYTE_STRING. Use MVariant(const char* p, unsigned len, AcceptStringType) to construct a regular string, not byte string.

Parameters
pConstant pointer to the first byte of the byte string.
lenLength of the byte string.
MVariant::MVariant ( const Muint8 *  p,
unsigned  len 
)
inline

Construct the variant of type byte string.

This will produce a variant of type MVariant::VAR_BYTE_STRING. Use MVariant(const char* p, unsigned len, AcceptStringType) to construct a regular string, not byte string.

Parameters
pConstant pointer to the first byte of the byte string.
lenLength of the byte string.
MVariant::MVariant ( const MByteString s,
AcceptByteStringType  tag 
)
inline

Construct the variant of type byte string.

This will produce a variant of type MVariant::VAR_BYTE_STRING. The second parameter should always be MVariant::ACCEPT_BYTE_STRING. Note that to C++ the type MByteString is indistinguishable from MStdString. Use MVariant(const MStdString& s) to construct a regular string, not byte string.

Parameters
sByte string value.
tagThe only accepted value is MVariant::ACCEPT_BYTE_STRING.
MVariant::MVariant ( const MByteStringVector v,
AcceptByteStringCollectionType  tag 
)
inline

Construct the variant of type varaint collection that hold byte strings.

This will produce a variant of type MVariant::VAR_VARIANT_COLLECTION where every element will be of type MVariant::VAR_BYTE_STRING. The second parameter should always be MVariant::ACCEPT_BYTE_STRING_COLLECTION, and it is necessary for distinguishing MByteStringVector from MStdStringVector, which are the same typedefs in C++. Use MVariant(const MStdStringVector&) to construct a variant of type MVariant::VAR_STRING_COLLECTION.

Parameters
vVector (collection) of byte strings.
tagThe only accepted value is MVariant::ACCEPT_BYTE_STRING_COLLECTION.
MVariant::MVariant ( const MStdStringVector v)
inline

Construct the variant of type string collection.

This will produce a variant of type MVariant::VAR_STRING_COLLECTION where every element will be of type MVariant::VAR_STRING. Use MVariant(const MByteStringVector&, AcceptByteStringCollectionType) to construct a variant of type MVariant::VAR_VARIANT_COLLECTION where every element will be of type MVariant::VAR_BYTE_STRING.

Parameters
vVector (collection) of strings.
MVariant::MVariant ( const VariantVector v)
inline

Construct the variant of type varaint collection.

This will produce a variant of type MVariant::VAR_VARIANT_COLLECTION.

Parameters
vVector (collection) of variants.
MVariant::MVariant ( MObject o)

Construct the variant of type object, which references the object given.

This will produce a variant of type MVariant::VAR_OBJECT. The variant does not own the object, and it is the responsibility of the application to ensure that the object is not discarded before its reference. To create a variant that holds and owns an embedded object use MVariant(const C* o, AcceptObjectEmbedded).

Parameters
oObject value, possibly NULL.
template<class C >
MVariant::MVariant ( const C *  o,
AcceptObjectEmbedded  tag 
)
inline

Construct the variant of type embedded object.

This will produce a variant of type MVariant::VAR_OBJECT_EMBEDDED. To create a variant that holds and does not own a regular object use MVariant(const MObject*).

Parameters
oEmbedded object value. There is a debug check to verify that the given object is not NULL, and it is indeed an embedded object.
tagThe only accepted value is MVariant::ACCEPT_OBJECT_EMBEDDED. The tag is necessary to distinguis this constructor from MVariant(MObject*).
MVariant::MVariant ( const MVariant other)
inline

Construct the variant from a given copy.

This will produce a variant of the same type as the one given. It is not an error to create a copy of an empty variant.

Parameters
otherVariant from which to copy the value.

Member Function Documentation

MVariant& MVariant::AccessItem ( const MVariant index)

Access constant element by index, efficient call.

This is the same as GetItem, but it works only for variant collection and a map. Constant reference is returned, therefore, it is more efficient than GetItem.

See also
GetItem
MVariant& MVariant::AccessItem ( int  index)

Access constant element by index, efficient call.

This is the same as GetItem, but it works only for variant collection and a map. Constant reference is returned, therefore, it is more efficient than GetItem.

See also
GetItem
MVariant& MVariant::AccessItem ( unsigned  index)
inline

Access constant element by index, efficient call.

This is the same as GetItem, but it works only for variant collection and a map. Constant reference is returned, therefore, it is more efficient than GetItem.

See also
GetItem
const MVariant& MVariant::AccessItem ( const MVariant index) const

Access constant element by index, efficient call.

This is the same as GetItem, but it works only for variant collection and a map. Constant reference is returned, therefore, it is more efficient than GetItem.

See also
GetItem
const MVariant& MVariant::AccessItem ( int  index) const

Access constant element by index, efficient call.

This is the same as GetItem, but it works only for variant collection and a map. Constant reference is returned, therefore, it is more efficient than GetItem.

See also
GetItem
const MVariant& MVariant::AccessItem ( unsigned  index) const
inline

Access constant element by index, efficient call.

This is the same as GetItem, but it works only for variant collection and a map. Constant reference is returned, therefore, it is more efficient than GetItem.

See also
GetItem
void MVariant::AddToVariantCollection ( const MVariant v)

Add the given variant as a whole to the collection.

This call is different from operator+=, as it does not unroll the collection items if the given parameter is a collection.

Precondition
The type of the variant shall be VARIANT_COLLECTION, there is a debug check.
static void MVariant::AdjustIndex ( int &  index,
unsigned  count 
)
static

Adjust a given index so the negative index will mean counting from the end of the array.

Precondition
The index shall be in range -count to count - 1, where count is a signed integer, otherwise an exception is thrown.
static int MVariant::AdjustSlice ( int &  from,
int &  to,
unsigned  count 
)
static

Adjust a given slice so the negative index will mean counting from the end of the array.

A negative slice will mean no elements.

Precondition
Slice is always adjusted correctly.
bool MVariant::AsBool ( ) const

Interpret the variant value as type bool, if possible.

The type of the value should allow conversion of it into boolean. It should either be boolean itself, or numeric. If the value is numeric, nonzero would mean TRUE. Also, string, byte string, and string collection, if empty, will yield to False. If they are not empty, their conversion to Long will be attempted as the result compared with zero.

Precondition
The conversion should be possible. If the current value is of incompatible type, bad conversion is thrown.
Muint8 MVariant::AsByte ( ) const

Interpret the variant value as byte, if possible.

The type of the value should fit within one byte.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases the type is incompatible or the range is bad.
MByteString MVariant::AsByteString ( ) const

Interpret the variant value as byte string, if possible.

The only value that cannot be interpreted as byte string is an empty value.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MByteStringVector MVariant::AsByteStringCollection ( ) const

Interpret the variant value as byte string collection, if possible.

The only value that cannot be interpreted as string is an empty value. For the rest, AsByteString is attempted for each element.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
char MVariant::AsChar ( ) const

Interpret the variant value as type char, if possible.

The type of the value should allow conversion of it into char. It should either be VAR_CHAR itself, or it should be numeric with the allowed range, or it should be a string with the size 1.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
const char* MVariant::AsConstChars ( ) const

Interpret string related values of this variant as zero terminated string.

This is an efficient conersion, and multiple restrictions apply depending on the variant type:

  • MVariant::VAR_EMPTY will throw a no value exception
  • MVariant::VAR_BYTE will be converted into a single character followed by terminating zero.
  • MVariant::VAR_CHAR will be converted into a single character followed by terminating zero.
  • MVariant::VAR_INT will only be converted successfully into a string of up to seven characters if it has range of -999999 to 9999999.
  • MVariant::VAR_UINT will only be converted successfully into a string of up to seven characters if it has range of 0 to 9999999.
  • MVariant::VAR_STRING will always be converted successfully and effieicntly. If a string has binary zeroes its real length can be deterined by GetCount.
  • MVariant::VAR_BYTE_STRING will always be converted successfully and effieicntly. If a string has binary zeroes its real length can be deterined by GetCount.
double MVariant::AsDouble ( ) const

Interpret the variant value as double precision floating point, if possible.

The type of the value should allow conversion of it into double precision floating point. If this is the string, the string has to be the valid string representation of double precision number.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
Muint32 MVariant::AsDWord ( ) const

Interpret the variant value as double word.

This service is like AsInt or AsUInt, but it will ignore the sign and never throw an exception or overflow.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
MStdString MVariant::AsEscapedString ( ) const

Interpret the variant value as a string with C escapes, if possible.

The only value that cannot be interpreted as string is an empty value. If the variant is an object, its AsString method is called, then converted to escaped string. For Boolean value, its string representations are numeric: 1 or 0.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MWideString MVariant::AsEscapedWideString ( ) const

Interpret the variant value as a wide string with C escapes, if possible.

The only value that cannot be interpreted as string is an empty value. If the variant is an object, its AsString method is called, then converted to escaped wide string. For Boolean value, its string representations are numeric: 1 or 0.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MObject* MVariant::AsExistingObject ( )

Interpret the variant value as an existing non-NULL object reference, if possible.

The only value that can be interpreted as object is an object itself.

Precondition
An exception is thrown in case the value is not of type object. If the object is NULL, the No Value exception is thrown.
MObject* MVariant::AsExistingObject ( ) const
inline

Interpret the variant value as an existing non-NULL object reference, if possible.

The only value that can be interpreted as object is an object itself.

Precondition
An exception is thrown in case the value is not of type object. If the object is NULL, the No Value exception is thrown.
int MVariant::AsInt ( ) const

Interpret the variant value as integer type, if possible.

The type of the value should allow conversion of it into integer. The numeric type has to fit within the range of integer, and the string has to be the valid string representation of integer.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
Mint64 MVariant::AsInt64 ( ) const

Interpret the variant value as 64-bit integer type, if possible.

The type of the value should allow conversion of it into 64-bit integer. The numeric type has to fit within the range of 64-bit integer, and the string has to be the valid string representation of such integer.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
long MVariant::AsLong ( ) const
inline

Interpret the variant value as long integer type, if possible.

The type of the value should allow conversion of it into long integer. The numeric type has to fit within the range of integer, and the string has to be the valid string representation of long integer.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
MObject* MVariant::AsObject ( )

Interpret the variant value as object reference, if possible.

The only value that can be interpreted as object is an object itself.

Precondition
An exception is thrown in case the value is not of type object.
MObject* MVariant::AsObject ( ) const
inline

Interpret the variant value as object reference, if possible.

The only value that can be interpreted as object is an object itself.

Precondition
An exception is thrown in case the value is not of type object.
MSharedString MVariant::AsSharedString ( ) const

Interpret the variant value as shared string, if possible.

The only value that cannot be interpreted as shared string is an empty value. If the variant is an object, its AsString method is called. For Boolean value, its string representations are numeric: 1 or 0.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
template<class C >
void MVariant::AssignObjectEmbedded ( const C *  o)
inline

Assign the byte embedded object to the variant type.

Precondition
The given object value is not null, there is a debug check.
void MVariant::AssignString ( const wchar_t *  p,
unsigned  len 
)

Assign the wide string to the variant type.

The result type of the variant will be a string.

size_t MVariant::AsSizeT ( ) const
inline

Interpret the variant value as an integer type equivalent to size_t, if possible.

The type of the value should allow conversion of it into size_t. The numeric type has to fit within the range of size_t, and the string has to be the valid string representation of size_t.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
MStdString MVariant::AsString ( ) const

Interpret the variant value as string, if possible.

The only value that cannot be interpreted as string is an empty value. If the variant is an object, its AsString method is called. For Boolean value, its string representations are numeric: 1 or 0.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MStdString MVariant::AsString ( unsigned  mask) const

Interpret the variant value as string, if possible, using mask that specifies the conversions to make.

The only value that cannot be interpreted as string is an empty value. If the variant is an object, its AsString method is called. For Boolean value, its string representations are numeric: 1 or 0.

Parameters
maskThe mask of type MStr::Mask
Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MStdStringVector MVariant::AsStringCollection ( ) const

Interpret the variant value as string collection, if possible.

The string collection returns directly. The only value that cannot be interpreted as string is an empty value. For the rest, AsString is attempted and the resulting collection will have only one string in it.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
unsigned MVariant::AsUInt ( ) const

Interpret the variant value as unsigned integer type, if possible.

The type of the value should allow conversion of it into unsigned integer. The numeric type has to fit within the range of integer, and the string has to be the valid string representation of unsigned integer.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
Muint64 MVariant::AsUInt64 ( ) const

Interpret the variant value as unsigned long integer type, if possible.

The type of the value should allow conversion of it into unsigned long integer. The numeric type has to fit within the range of integer, and the string has to be the valid string representation of unsigned long integer.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
unsigned long MVariant::AsULong ( ) const
inline

Interpret the variant value as unsigned long integer type, if possible.

The type of the value should allow conversion of it into unsigned long integer. The numeric type has to fit within the range of integer, and the string has to be the valid string representation of unsigned long integer.

Precondition
The conversion should be possible. Bad conversion can be thrown in cases such as the type is incompatible or the range is bad.
VariantVector MVariant::AsVariantCollection ( ) const

Interpret the variant value as variant collection, if possible.

The variant collection returns directly. The only value that cannot be interpreted as variant is an empty value. For the rest, the resulting collection will have only one element.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MWideString MVariant::AsWideString ( ) const

Interpret the variant value as wide string, if possible.

The only value that cannot be interpreted as string is an empty value. If the variant is an object, its AsString method is called, and the result is converted into a wide string. For Boolean value, its string representations are numeric: 1 or 0.

Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
MWideString MVariant::AsWideString ( unsigned  mask) const

Interpret the variant value as wide string, if possible, using mask that specifies the conversions to make.

The only value that cannot be interpreted as string is an empty value. If the variant is an object, its AsString method is called, and the result is converted into a wide string. For Boolean value, its string representations are numeric: 1 or 0.

Parameters
maskThe mask of type MStr::Mask
Precondition
If the value of the variant is not initialized, the No Value exception is thrown.
int MVariant::FindIndexOf ( const MVariant ,
bool  reverse = false 
) const

Find index of the given element in the indexed variant.

If there is no such item, -1 is returned.

If this variant is a map, this method returns ordinal index of the given key.

If this variant is a collection of any kind, index of element is returned.

MVariant MVariant::GetAllMapKeys ( ) const
inline

Return a variant vector of keys in this map.

Keys are unique in the result collection.

Precondition
The object should be of map type, or an error is thrown.
Returns
Variant of type collection of objects, possibly empty.
See also
GetAllMapValues
MVariant MVariant::GetAllMapValues ( ) const
inline

Return a variant vector of values in this map.

Values are not necessarily unique, and therefore the count of values returned is the same as the count of keys of the same map.

Precondition
The object should be of map type, or an error is thrown.
Returns
Variant of type collection of objects, possibly empty.
See also
GetAllMapKeys
int MVariant::GetCount ( ) const

Count of elements in the variant, if they can be indexed.

Precondition
IsIndexed should be true, or the attempt to use this operation will cause an exception to be thrown.

When the count value is assigned, the indexed variant can either shrink or grow. Depending on the type:

MVariant MVariant::GetItem ( const MVariant index) const

Get element by index. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name Item. Otherwise the conversion exception is thrown.
MVariant MVariant::GetItem ( int  index) const

Get element by index. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name Item. Otherwise the conversion exception is thrown.
MVariant MVariant::GetItem ( unsigned  index) const
inline

Get element by index. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name Item. Otherwise the conversion exception is thrown.
const MVariant& MVariant::GetMapKeyByIndex ( int  i) const
inline

Return the value of a key in the map by its index.

Parameters
iIndex in range 0 .. GetCount.
Returns
Key with the given index.
const MVariant& MVariant::GetMapValueByIndex ( int  i) const
inline

Return the value of a key in the map by its index.

Parameters
iIndex in range 0 .. GetCount.
Returns
Value with the given index.
MVariant MVariant::GetSlice ( int  from,
int  to 
) const

Return the slice of values for types that support subscripts.

One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name SetItem. Otherwise the conversion exception is thrown.
bool MVariant::IsCollection ( ) const
inline

Whether the variant is a collection, array, or a map (which is a key-indexed collection).

This is a subset of all indexed types that holds other variants:

All the other types are not collections.

See also
IsIndexed for checking if the type is a collection, string or byte string.
bool MVariant::IsEmpty ( ) const
inline

Tells whether the variant has no value.

Empty variant is one of the following:

bool MVariant::IsIndexed ( ) const
inline

Whether the variant can be indexed.

This means that GetCount(), GetItem and SetItem are callable, subjects of valid array ranges. The following types are indexed:

All the other types are not indexed.

See also
IsCollection for checking if the type is a collection
bool MVariant::IsNumeric ( ) const
inline

Whether the variant is of numeric type, so the arithmetic operations can be performed with it.

The following types are arithmetic:

All the other types are not numeric.

bool MVariant::IsObject ( ) const
inline

Whether the variant is of object or embedded object type.

Formally, these are variants of these types:

bool MVariant::IsPresent ( const MVariant it) const

Returns true if the given item is in the variant.

If this variant is a map, this method checks if the given key is present.

If this variant is a collection of any kind, true will mean the parameter is contained it in.

It does not matter how many duplicate items are present in either of the values.

void MVariant::MoveFrom ( MVariant other)

Fast method that moves the value to another variant, and sets the other variant type to Empty.

This is possible only because variant values can always be moved.

MVariant MVariant::operator! ( ) const

Unary operator NOT.

Note that there is no difference between logical NOT and bitwise NOT. Logical NOT is applied for bool operands, and the resulting value is bool. For all the other numeric values the bitwise NOT is performed.

Precondition
The type should be convertible to either bool or unsigned integer. Otherwise a bad conversion exception is raised. If any of the values are not initialized, the No Value exception is thrown.
bool MVariant::operator!= ( const MVariant other) const
inline

Inequality operator.

Standard conversions apply.

Precondition
If any of the values are not initialized, the No Value exception is thrown.
MVariant MVariant::operator% ( const MVariant ) const

Binary modulus operator.

Applicable for numerics only. Modulus produces a reminder value from the division operator if both arguments are positive.

First the conversion is applied. Preconditions apply for the conversion. The converted values should be of numeric type.

Precondition
The type should be compatible with the operation (be numeric). Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown. If the second argument is zero, the Division By Zero exception is thrown.
MVariant& MVariant::operator%= ( const MVariant )

Binary operator modulus self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator& ( const MVariant ) const

Operator AND.

Standard conversions apply. Note that there is no difference between logical AND and bitwise AND. Logical AND is applied for bool operands, and the resulting value is bool. For all the other numeric values the bitwise AND is performed.

Precondition
The operand types should be convertible to BOOL or numeric. Otherwise a bad conversion exception is raised. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator&= ( const MVariant )

Binary operator, binary or logical 'and' of self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator* ( const MVariant ) const

Binary multiplication operator.

Applicable for numerics or sets only.

First the conversion is applied. Preconditions apply for the conversion. The converted values should be of numeric type.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator*= ( const MVariant )

Binary operator multiply self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator+ ( const MVariant ) const

Binary operator plus.

The interpretation depends on the context.

First the conversion is applied. Preconditions apply for the conversion. If the converted values are of type TYPE_STRING, then the strings are concatenated. If the converted values are of the numeric type, the values are added. The result value is returned, and this object is not changed.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator++ ( )

Prefix increment operator.

It never attempts to change the type of this variant.

Precondition
The type should allow incrementing, which means it is numeric. Otherwise the exception is thrown.
MVariant& MVariant::operator+= ( const MVariant )

Binary operator increment self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator- ( ) const

Unary operator minus.

Please note that the unary operator plus is not defined for MVariant.

Precondition
The type should be compatible with the operation. It should be arithmetic. Otherwise a bad conversion exception is raised. If any of the values are not initialized, the No Value exception is thrown.
MVariant MVariant::operator- ( const MVariant ) const

Binary operator minus.

Applicable for numerics or sets only.

First the conversion is applied. Preconditions apply for the conversion. The converted values should be of numeric type.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator-- ( )

Prefix decrement operator.

It never attempts to change the type of this variant.

Precondition
The type should allow incrementing, which means it is numeric. Otherwise the exception is thrown.
MVariant& MVariant::operator-= ( const MVariant )

Binary operator decrement self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator/ ( const MVariant ) const

Binary division operator.

Applicable for numerics only.

First the conversion is applied. Preconditions apply for the conversion. The converted values should be of numeric type.

Precondition
The type should be compatible with the operation, which means to be convertible to numeric type. Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown. If the second argument is zero, the Division By Zero exception is thrown.
MVariant& MVariant::operator/= ( const MVariant )

Binary operator divide self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
bool MVariant::operator< ( const MVariant ) const

Less-than operator.

Standard conversions apply.

Precondition
If any of the values are not initialized, the No Value exception is thrown.
MVariant MVariant::operator<< ( const MVariant ) const

Bitwise left shift operator.

Standard conversions apply.

Precondition
The type should be compatible with the operation, which means to be numeric. Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator<<= ( const MVariant )

Binary operator left shift self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
bool MVariant::operator<= ( const MVariant v) const
inline

Less-or-equal-than operator.

Standard conversions apply.

Precondition
If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator= ( wchar_t  c)
inline

Assignment operator that takes variable of type char.

The result type of the variant will depend on the given value as follows:

  • If c is an ASCII character, range 0 to 127, the result variant will be MVariant::VAR_CHAR.
  • Otherwise, for non-ASCII character the result will be a string, MVariant::VAR_STRING. The method will work correctly only if the current code page is UTF-8, which correstonds to M_UNICODE = 1.
Parameters
cCharacter value.
MVariant& MVariant::operator= ( const wchar_t *  s)

Assignment operator that takes variable of type constant pointer to zero terminated wide character string.

The result type of the variant will be a string.

MVariant& MVariant::operator= ( const MWideString s)

Assignment operator that takes variable of type to wide string.

The result type of the variant will be a string.

MVariant& MVariant::operator= ( const MObject v)

Assignment operator that takes variable of type MObject.

Note that the variant does not own the object, and it is the responsibility of the application to ensure that the object is not discarded before its reference.

bool MVariant::operator== ( const MVariant ) const

Equality operator.

Standard conversions apply.

Precondition
If any of the values are not initialized, the No Value exception is thrown.
bool MVariant::operator> ( const MVariant ) const

Greater-than operator.

Standard conversions apply.

Precondition
If any of the values are not initialized, the No Value exception is thrown.
bool MVariant::operator>= ( const MVariant v) const
inline

Greater-or-equal-than operator.

Standard conversions apply.

Precondition
If any of the values are not initialized, the No Value exception is thrown.
MVariant MVariant::operator>> ( const MVariant ) const

Bitwise right shift operator.

Standard conversions apply.

Precondition
The type should be compatible with the operation, which means to be numeric. Otherwise the conversion exception is thrown. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator>>= ( const MVariant )

Binary operator right shift self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator^ ( const MVariant ) const

Operator XOR.

Standard conversions apply. Note that there is no difference between logical XOR and bitwise XOR. Logical XOR is applied for bool operands, and the resulting value is bool. For all the other numeric values the bitwise XOR is performed.

Precondition
The operand types should be convertible to BOOL or numeric. Otherwise a bad conversion exception is raised. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator^= ( const MVariant )

Binary operator, binary or logical 'xor' of self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::operator| ( const MVariant ) const

Operator OR.

Standard conversions apply.

Note that there is no difference between logical OR and bitwise OR. Logical OR is applied for bool operands, and the resulting value is bool. For all the other numeric values the bitwise OR is performed.

Precondition
The operand types should be convertible to BOOL or numeric. Otherwise a bad conversion exception is raised. If any of the values are not initialized, the No Value exception is thrown.
MVariant& MVariant::operator|= ( const MVariant )

Binary operator, binary or logical 'or' of self by value.

Precondition
The type should be compatible with the operation. Otherwise the conversion exception is thrown.
MVariant MVariant::Pow ( const MVariant ) const

Return this object with the power of the object given.

The power type returned is always DOUBLE.

Precondition
The type should be compatible with the power operation. The compatible types are those that can be cast to DOUBLE. If not, the bad conversion is thrown. If any of the values are not initialized, the No Value exception is thrown.
void MVariant::ReserveElements ( int  count)

Reserve the number of elements in the variant when variant is indexed.

Parameters
countThe number of elements to reserve.
Precondition
The variant type should be indexed.
void MVariant::SetCount ( int  )

Count of elements in the variant, if they can be indexed.

Precondition
IsIndexed should be true, or the attempt to use this operation will cause an exception to be thrown.

When the count value is assigned, the indexed variant can either shrink or grow. Depending on the type:

void MVariant::SetEmptyWithObjectDelete ( )

Discard the value of the variant type, and if it is an object, delete it.

This corresponds to a concept of owned variant.

void MVariant::SetItem ( const MVariant index,
const MVariant value 
)

Set element by index. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name SetItem. Otherwise the conversion exception is thrown.
void MVariant::SetItem ( int  index,
const MVariant value 
)

Set element by index. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name SetItem. Otherwise the conversion exception is thrown.
void MVariant::SetItem ( unsigned  index,
const MVariant value 
)
inline

Set element by index. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name SetItem. Otherwise the conversion exception is thrown.
void MVariant::SetSlice ( int  from,
int  to,
const MVariant values 
)

Set the slice of values for types that support subscripts.

Shrink or grow the number of items if necessary. One can check IsIndexed property to know if the variant can be indexed. Also there is a GetCount, which is callable only for IsIndexed, and will return the number of items in the variant.

Precondition
The type should allow subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. If an item is an object, it shall have a reflected service with the name SetItem. Otherwise the conversion exception is thrown.
void MVariant::SetToNull ( MVariant::Type  type)

Discard the value of the variant type, and set it to null, either empty or zero value depending on the given type.

The null value will depend on the given type. For string it is an empty string, and for an integer it is zero. If no parameter is given, the type is preserved while its value becomes NULL.

Parameters
typeThe type to use to set the value to null, where the type determines whether that is an empty or zero value.
static bool MVariant::StaticIsObject ( const MVariant var)
static

Whether the pointer to variant is an object reference.

Different from just var->IsObject, this static method checks if the variable is not NULL. The call that mentions reference avoids a problem when newer C++ compilers assume that object reference is never NULL.

Usage example:

M_ASSERT(MVariant::StaticIsObject(variantPtr)); // will not generate access violation if variantPtr is NULL
static bool MVariant::StaticIsObject ( const MVariant var)
inlinestatic

Whether the pointer to variant is an object reference.

Different from just var->IsObject, this static method checks if the variable is not NULL. The call that mentions reference avoids a problem when newer C++ compilers assume that object reference is never NULL.

Usage example:

M_ASSERT(MVariant::StaticIsObject(variantPtr)); // will not generate access violation if variantPtr is NULL
void MVariant::SwapItems ( int  index1,
int  index2 
)

Swap two indexed items in the array or collection.

As the result of the operation, this variant will have two items with such indexes swapped. Index adjustments are performed according to standard rules, such as -1 will mean the last element.

Parameters
index1Index of the first item with which to perform a swap.
index2Index of the second item with which to perform a swap.
Precondition
The type should allow integer subscripting, such as VAR_STRING, VAR_BYTE_STRING or VAR_STRING_COLLECTION. Otherwise the conversion exception is thrown.