C12Adapter Opensource C++ Interface
|
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< MVariant > | VariantVector |
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... | |
MVariant & | operator= (bool b) |
Assignment operator that takes variable of type bool. | |
MVariant & | operator= (char c) |
Assignment operator that takes variable of type char. | |
MVariant & | operator= (wchar_t c) |
Assignment operator that takes variable of type char. More... | |
MVariant & | operator= (Muint8 b) |
Assignment operator that takes variable of type byte. | |
MVariant & | operator= (int n) |
Assignment operator that takes variable of type int. | |
MVariant & | operator= (unsigned n) |
Assignment operator that takes variable of type unsigned int. | |
MVariant & | operator= (long n) |
Assignment operator that takes variable of type long. | |
MVariant & | operator= (unsigned long n) |
Assignment operator that takes variable of type unsigned long. | |
MVariant & | operator= (Mint64 v) |
Assignment operator that takes variable of 64-bit integer type. | |
MVariant & | operator= (Muint64 v) |
Assignment operator that takes variable of 64-bit unsigned integer type. | |
MVariant & | operator= (double f) |
Assignment operator that takes variable of type double. | |
MVariant & | operator= (MConstChars p) |
Assignment operator that takes variable of type pointer to the constant zero terminated string. | |
MVariant & | operator= (const MStdString &s) |
Assignment operator that takes variable of type string. | |
MVariant & | operator= (const wchar_t *s) |
Assignment operator that takes variable of type constant pointer to zero terminated wide character string. More... | |
MVariant & | operator= (const MWideString &s) |
Assignment operator that takes variable of type to wide string. More... | |
MVariant & | operator= (const MStdStringVector &s) |
Assignment operator that takes variable of type string collection. | |
MVariant & | operator= (const VariantVector &s) |
Assignment operator that takes variable of type variant vector. | |
MVariant & | operator= (const MVariant &v) |
Assignment operator that takes variable of type MVariant. | |
MVariant & | operator= (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... | |
MVariant & | operator= (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 MVariant & | GetMapKeyByIndex (int i) const |
Return the value of a key in the map by its index. More... | |
const MVariant & | GetMapValueByIndex (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... | |
MVariant & | operator++ () |
Prefix increment operator. More... | |
MVariant & | operator-- () |
Prefix decrement operator. More... | |
MVariant & | operator+= (const MVariant &) |
Binary operator increment self by value. More... | |
MVariant & | operator-= (const MVariant &) |
Binary operator decrement self by value. More... | |
MVariant & | operator*= (const MVariant &) |
Binary operator multiply self by value. More... | |
MVariant & | operator/= (const MVariant &) |
Binary operator divide self by value. More... | |
MVariant & | operator%= (const MVariant &) |
Binary operator modulus self by value. More... | |
MVariant & | operator>>= (const MVariant &) |
Binary operator right shift self by value. More... | |
MVariant & | operator<<= (const MVariant &) |
Binary operator left shift self by value. More... | |
MVariant & | operator|= (const MVariant &) |
Binary operator, binary or logical 'or' of self by value. More... | |
MVariant & | operator&= (const MVariant &) |
Binary operator, binary or logical 'and' of self by value. More... | |
MVariant & | operator^= (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) |
MObject * | AsObject () |
MObject * | AsObject () const |
MObject * | AsExistingObject () |
MObject * | AsExistingObject () 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) |
MVariant & | AccessItem (const MVariant &index) |
MVariant & | AccessItem (int index) |
MVariant & | AccessItem (unsigned index) |
const MVariant & | AccessItem (const MVariant &index) const |
const MVariant & | AccessItem (int index) const |
const MVariant & | AccessItem (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. | |
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.
enum MVariant::Type |
Possible value types, sorted in the order of their promotional conversion.
|
inline |
Default constructor.
The result type of the variant is MVariant::VAR_EMPTY.
|
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:
type | Type of the variant |
|
inline |
Construct the value of type bool.
The result type of the variant is MVariant::VAR_BOOL.
n | Boolean value, true or false. |
|
inline |
Construct the value of type char with the value specified.
The result type of the variant is MVariant::VAR_CHAR.
c | Character value. |
|
inline |
Construct the variant from a wide character.
The result type of the variant will depend on the given value as follows:
c | Character value. |
|
inline |
Construct the variant of byte type with the value specified.
The result type of the variant is MVariant::VAR_BYTE.
b | Byte unsigned value, 0 to 255. |
|
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.
n | Integer value. |
|
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.
n | Unsigned integer value. |
|
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.
n | Long integer value. |
|
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.
n | Unsigned long integer value. |
|
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.
n | 64-bit integer value. |
|
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.
n | 64-bit integer value. |
|
inline |
Construct the variant of type double.
This will produce a variant of type MVariant::VAR_DOUBLE.
n | Double precision floating point value. |
|
inline |
Construct the variant of type string.
This will produce a variant of type MVariant::VAR_STRING.
s | Zero terminated constant character string given as pointer to the first character. |
|
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.
s | Constant character string given as pointer to the first character. |
len | Explicitly given length of the character string. |
tag | The only accepted value is 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:
s | Zero terminated constant wide character string given as pointer to the first wide character. |
|
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:
s | Constant wide character string given as pointer to the first wide character. |
len | Explicitly given length of the character string. |
tag | The only accepted value is MVariant::ACCEPT_STRING, and it can be ommitted since there is no clash with the byte string version. |
|
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:
s | Wide character string value. |
|
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.
s | Character string value. |
|
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.
p | Constant pointer to the first byte of the byte string. |
len | Length of the byte string. |
|
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.
p | Constant pointer to the first byte of the byte string. |
len | Length of the byte string. |
|
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.
s | Byte string value. |
tag | The only accepted value is MVariant::ACCEPT_BYTE_STRING. |
|
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.
v | Vector (collection) of byte strings. |
tag | The only accepted value is MVariant::ACCEPT_BYTE_STRING_COLLECTION. |
|
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.
v | Vector (collection) of strings. |
|
inline |
Construct the variant of type varaint collection.
This will produce a variant of type MVariant::VAR_VARIANT_COLLECTION.
v | Vector (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).
o | Object value, possibly NULL. |
|
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*).
o | Embedded object value. There is a debug check to verify that the given object is not NULL, and it is indeed an embedded object. |
tag | The only accepted value is MVariant::ACCEPT_OBJECT_EMBEDDED. The tag is necessary to distinguis this constructor from MVariant(MObject*). |
|
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.
other | Variant from which to copy the value. |
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.
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.
|
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.
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.
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.
|
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.
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.
|
static |
Adjust a given index so the negative index will mean counting from the end of the array.
|
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.
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.
Muint8 MVariant::AsByte | ( | ) | const |
Interpret the variant value as byte, if possible.
The type of the value should fit within one byte.
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.
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.
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.
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:
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.
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.
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.
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.
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.
|
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.
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.
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.
|
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.
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.
|
inline |
Interpret the variant value as object reference, if possible.
The only value that can be interpreted as object is an object itself.
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.
|
inline |
Assign the byte embedded object to the variant type.
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.
|
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.
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.
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.
mask | The mask of type MStr::Mask |
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.
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.
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.
|
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.
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.
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.
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.
mask | The mask of type MStr::Mask |
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.
|
inline |
Return a variant vector of keys in this map.
Keys are unique in the result collection.
|
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.
int MVariant::GetCount | ( | ) | const |
Count of elements in the variant, if they can be indexed.
When the count value is assigned, the indexed variant can either shrink or grow. Depending on the type:
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.
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.
|
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.
|
inline |
Return the value of a key in the map by its index.
i | Index in range 0 .. GetCount. |
|
inline |
Return the value of a key in the map by its index.
i | Index in range 0 .. GetCount. |
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.
|
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.
|
inline |
Tells whether the variant has no value.
Empty variant is one of the following:
|
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.
|
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.
|
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.
|
inline |
Inequality operator.
Standard conversions apply.
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.
Binary operator modulus self by value.
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.
Binary operator, binary or logical 'and' of self by value.
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.
Binary operator multiply self by value.
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.
MVariant& MVariant::operator++ | ( | ) |
Prefix increment operator.
It never attempts to change the type of this variant.
Binary operator increment self by value.
MVariant MVariant::operator- | ( | ) | const |
Unary operator minus.
Please note that the unary operator plus is not defined for MVariant.
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.
MVariant& MVariant::operator-- | ( | ) |
Prefix decrement operator.
It never attempts to change the type of this variant.
Binary operator decrement self by value.
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.
Binary operator divide self by value.
bool MVariant::operator< | ( | const MVariant & | ) | const |
Less-than operator.
Standard conversions apply.
Bitwise left shift operator.
Standard conversions apply.
Binary operator left shift self by value.
|
inline |
Less-or-equal-than operator.
Standard conversions apply.
|
inline |
Assignment operator that takes variable of type char.
The result type of the variant will depend on the given value as follows:
c | Character 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.
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.
bool MVariant::operator> | ( | const MVariant & | ) | const |
Greater-than operator.
Standard conversions apply.
|
inline |
Greater-or-equal-than operator.
Standard conversions apply.
Bitwise right shift operator.
Standard conversions apply.
Binary operator right shift self by value.
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.
Binary operator, binary or logical 'xor' of self by value.
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.
Binary operator, binary or logical 'or' of self by value.
Return this object with the power of the object given.
The power type returned is always DOUBLE.
void MVariant::ReserveElements | ( | int | count | ) |
Reserve the number of elements in the variant when variant is indexed.
count | The number of elements to reserve. |
void MVariant::SetCount | ( | int | ) |
Count of elements in the variant, if they can be indexed.
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.
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.
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.
|
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.
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.
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.
type | The type to use to set the value to null, where the type determines whether that is an empty or zero value. |
|
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:
|
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:
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.
index1 | Index of the first item with which to perform a swap. |
index2 | Index of the second item with which to perform a swap. |