![]() |
PIP 5.5.3
Platform-Independent Primitives
|
Variant type. More...
#include <pivariant.h>
Public Types | |
| enum | Type { pivInvalid = 0 , pivBool , pivChar , pivUChar , pivShort , pivUShort , pivInt , pivUInt , pivLLong , pivULLong , pivFloat , pivDouble , pivLDouble , pivComplexd , pivComplexld , pivBitArray , pivByteArray , pivString , pivStringList , pivTime , pivDate , pivDateTime , pivSystemTime , pivEnum , pivFile , pivDir , pivColor , pivPoint , pivRect , pivIODevice , pivMathVector , pivMathMatrix , pivLine , pivNetworkAddress , pivComplexf , pivCustom = 0xFF } |
| Type of PIVariant content. More... | |
Public Member Functions | |
| PIVariant () | |
| Construct pivInvalid PIVariant. | |
| PIVariant (const PIVariant &v) | |
| Contructs a copy of PIVariant. | |
| PIVariant (PIVariant &&v) | |
| Move constructor. | |
| PIVariant (const char *v) | |
| Constructs PIVariant from string. | |
| PIVariant (const bool v) | |
| Constructs PIVariant from boolean. | |
| PIVariant (const char v) | |
| Constructs PIVariant from char. | |
| PIVariant (const uchar v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const short v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const ushort v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const int &v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const uint &v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const llong &v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const ullong &v) | |
| Constructs PIVariant from integer. | |
| PIVariant (const float &v) | |
| Constructs PIVariant from float. | |
| PIVariant (const double &v) | |
| Constructs PIVariant from double. | |
| PIVariant (const ldouble &v) | |
| Constructs PIVariant from long double. | |
| PIVariant (const complexf &v) | |
| Constructs PIVariant from complex number. | |
| PIVariant (const complexd &v) | |
| Constructs PIVariant from complex number. | |
| PIVariant (const complexld &v) | |
| Constructs PIVariant from complex number. | |
| PIVariant (const PIBitArray &v) | |
| Constructs PIVariant from bit array. | |
| PIVariant (const PIByteArray &v) | |
| Constructs PIVariant from byte array. | |
| PIVariant (const PIString &v) | |
| Constructs PIVariant from string. | |
| PIVariant (const PIStringList &v) | |
| Constructs PIVariant from strings list. | |
| PIVariant (const PITime &v) | |
| Constructs PIVariant from time. | |
| PIVariant (const PIDate &v) | |
| Constructs PIVariant from date. | |
| PIVariant (const PIDateTime &v) | |
| Constructs PIVariant from date and time. | |
| PIVariant (const PISystemTime &v) | |
| Constructs PIVariant from system time. | |
| PIVariant (const PIVariantTypes::Enum &v) | |
| Constructs PIVariant from enum. | |
| PIVariant (const PIVariantTypes::File &v) | |
| Constructs PIVariant from file. | |
| PIVariant (const PIVariantTypes::Dir &v) | |
| Constructs PIVariant from dir. | |
| PIVariant (const PIVariantTypes::Color &v) | |
| Constructs PIVariant from color. | |
| PIVariant (const PIVariantTypes::IODevice &v) | |
| Constructs PIVariant from IODevice. | |
| PIVariant (const PIPointd &v) | |
| Constructs PIVariant from point. | |
| PIVariant (const PIRectd &v) | |
| Constructs PIVariant from rect. | |
| PIVariant (const PILined &v) | |
| Constructs PIVariant from line. | |
| PIVariant (const PINetworkAddress &v) | |
| Constructs PIVariant from PINetworkAddress. | |
| PIVariant (const PIMathVectord &v) | |
| Constructs PIVariant from MathVector. | |
| PIVariant (const PIMathMatrixd &v) | |
| Constructs PIVariant from MathMatrix. | |
| void | setValue (const char *v) |
| Set variant content and type to string. | |
| void | setValue (const bool v) |
| Set variant content and type to boolean. | |
| void | setValue (const char v) |
| Set variant content and type to char. | |
| void | setValue (const uchar v) |
| Set variant content and type to integer. | |
| void | setValue (const short v) |
| Set variant content and type to integer. | |
| void | setValue (const ushort v) |
| Set variant content and type to integer. | |
| void | setValue (const int &v) |
| Set variant content and type to integer. | |
| void | setValue (const uint &v) |
| Set variant content and type to integer. | |
| void | setValue (const llong &v) |
| Set variant content and type to integer. | |
| void | setValue (const ullong &v) |
| Set variant content and type to integer. | |
| void | setValue (const float &v) |
| Set variant content and type to float. | |
| void | setValue (const double &v) |
| Set variant content and type to double. | |
| void | setValue (const ldouble &v) |
| Set variant content and type to long double. | |
| void | setValue (const complexf &v) |
| Set variant content and type to complex. | |
| void | setValue (const complexd &v) |
| Set variant content and type to complex. | |
| void | setValue (const complexld &v) |
| Set variant content and type to complex. | |
| void | setValue (const PIBitArray &v) |
| Set variant content and type to bit array. | |
| void | setValue (const PIByteArray &v) |
| Set variant content and type to byte array. | |
| void | setValue (const PIString &v) |
| Set variant content and type to string. | |
| void | setValue (const PIStringList &v) |
| Set variant content and type to strings list. | |
| void | setValue (const PITime &v) |
| Set variant content and type to time. | |
| void | setValue (const PIDate &v) |
| Set variant content and type to date. | |
| void | setValue (const PIDateTime &v) |
| Set variant content and type to date and time. | |
| void | setValue (const PISystemTime &v) |
| Set variant content and type to system time. | |
| void | setValue (const PIVariantTypes::Enum &v) |
| Set variant content and type to enum. | |
| void | setValue (const PIVariantTypes::File &v) |
| Set variant content and type to file. | |
| void | setValue (const PIVariantTypes::Dir &v) |
| Set variant content and type to dir. | |
| void | setValue (const PIVariantTypes::Color &v) |
| Set variant content and type to color. | |
| void | setValue (const PIVariantTypes::IODevice &v) |
| Set variant content and type to IODevice. | |
| void | setValue (const PIPointd &v) |
| Set variant content and type to point. | |
| void | setValue (const PIRectd &v) |
| Set variant content and type to rect. | |
| void | setValue (const PILined &v) |
| Set variant content and type to line. | |
| void | setValue (const PIMathVectord &v) |
| Set variant content and type to math vector. | |
| void | setValue (const PINetworkAddress &v) |
| Set variant content and type to PINetworkAddress. | |
| void | setValue (const PIMathMatrixd &v) |
| Set variant content and type to math matrix. | |
| void | setValueFromString (const PIString &v) |
| Set current value from string without change type. | |
| bool | toBool () const |
| Returns variant content as boolean. More... | |
| int | toInt () const |
| Returns variant content as int. More... | |
| llong | toLLong () const |
| Returns variant content as long long. More... | |
| float | toFloat () const |
| Returns variant content as float. More... | |
| double | toDouble () const |
| Returns variant content as double. More... | |
| ldouble | toLDouble () const |
| Returns variant content as long double. More... | |
| PITime | toTime () const |
| Returns variant content as time. More... | |
| PIDate | toDate () const |
| Returns variant content as date. More... | |
| PIDateTime | toDateTime () const |
| Returns variant content as date and time. More... | |
| PISystemTime | toSystemTime () const |
| Returns variant content as system time. More... | |
| PIString | toString () const |
| Returns variant content as string. More... | |
| PIStringList | toStringList () const |
| Returns variant content as strings list. More... | |
| PIBitArray | toBitArray () const |
| Returns variant content as bit array. More... | |
| PIByteArray | toByteArray () const |
| Returns variant content as byte array. More... | |
| PIVariantTypes::Enum | toEnum () const |
| Returns variant content as enum. More... | |
| PIVariantTypes::File | toFile () const |
| Returns variant content as file. More... | |
| PIVariantTypes::Dir | toDir () const |
| Returns variant content as dir. More... | |
| PIVariantTypes::Color | toColor () const |
| Returns variant content as color. More... | |
| PIVariantTypes::IODevice | toIODevice () const |
| Returns variant content as IODevice. More... | |
| PIPointd | toPoint () const |
| Returns variant content as point. More... | |
| PIRectd | toRect () const |
| Returns variant content as rect. More... | |
| PILined | toLine () const |
| Returns variant content as line. More... | |
| PINetworkAddress | toNetworkAddress () const |
| Returns variant content as PINetworkAddress. More... | |
| PIMathVectord | toMathVector () const |
| Returns variant content as math vector. More... | |
| PIMathMatrixd | toMathMatrix () const |
| Returns variant content as math matrix. More... | |
| template<typename T > | |
| T | value () const |
| Returns variant content as custom type. More... | |
| PIVariant & | operator= (const PIVariant &v) |
| Assign operator. | |
| PIVariant & | operator= (PIVariant &&v) |
| Assign operator. | |
| PIVariant & | operator= (const char *v) |
| Assign operator. | |
| PIVariant & | operator= (const bool v) |
| Assign operator. | |
| PIVariant & | operator= (const char v) |
| Assign operator. | |
| PIVariant & | operator= (const uchar v) |
| Assign operator. | |
| PIVariant & | operator= (const short v) |
| Assign operator. | |
| PIVariant & | operator= (const ushort v) |
| Assign operator. | |
| PIVariant & | operator= (const int &v) |
| Assign operator. | |
| PIVariant & | operator= (const uint &v) |
| Assign operator. | |
| PIVariant & | operator= (const llong &v) |
| Assign operator. | |
| PIVariant & | operator= (const ullong &v) |
| Assign operator. | |
| PIVariant & | operator= (const float &v) |
| Assign operator. | |
| PIVariant & | operator= (const double &v) |
| Assign operator. | |
| PIVariant & | operator= (const ldouble &v) |
| Assign operator. | |
| PIVariant & | operator= (const complexf &v) |
| Assign operator. | |
| PIVariant & | operator= (const complexd &v) |
| Assign operator. | |
| PIVariant & | operator= (const complexld &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIBitArray &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIByteArray &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIString &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIStringList &v) |
| Assign operator. | |
| PIVariant & | operator= (const PITime &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIDate &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIDateTime &v) |
| Assign operator. | |
| PIVariant & | operator= (const PISystemTime &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIVariantTypes::Enum &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIVariantTypes::File &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIVariantTypes::Dir &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIVariantTypes::Color &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIVariantTypes::IODevice &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIPointd &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIRectd &v) |
| Assign operator. | |
| PIVariant & | operator= (const PILined &v) |
| Assign operator. | |
| PIVariant & | operator= (const PINetworkAddress &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIMathVectord &v) |
| Assign operator. | |
| PIVariant & | operator= (const PIMathMatrixd &v) |
| Assign operator. | |
| bool | operator== (const PIVariant &v) const |
| Compare operator. Check type and content. | |
| bool | operator!= (const PIVariant &v) const |
| Compare operator. Check type and content. | |
| PIVariant::Type | type () const |
| Returns type of variant content. | |
| uint | typeID () const |
| Returns type ID of variant content. | |
| PIString | typeName () const |
| Returns type name of variant content. | |
| bool | isValid () const |
| Returns if type is not pivInvalid. | |
| void | swap (PIVariant &v) |
| Swaps with other PIVariant. | |
Static Public Member Functions | |
| template<typename T > | |
| static PIVariant | fromValue (const T &v) |
| Returns new PIVariant from custom type value. More... | |
| static PIVariant | fromType (const PIString &type) |
| Returns new PIVariant from default-constructed type with name "type". | |
| static PIVariant | fromType (uint type_id) |
| Returns new PIVariant from default-constructed type with type ID "type_id". | |
| static PIVariant::Type | typeFromName (const PIString &tname) |
| Returns type from its name. | |
| static PIVariant::Type | typeFromID (uint type_id) |
| Returns type from its ID. | |
| static uint | typeIDFromName (const PIString &tname) |
| Returns type from its name. | |
| static uint | typeIDFromType (PIVariant::Type type) |
| Returns type ID from standard type. | |
| static PIString | typeName (PIVariant::Type type) |
| Returns type name. | |
| template<typename T > | |
| static PIString | typeName () |
| Returns type name. | |
| static PIString | typeNameFromID (uint type_id) |
| Returns type name from its ID. | |
| static PIVector< uint > | knownTypeIDs () |
| Returns all registered type ID. | |
Variant type.
This class provides general type that can contains all standard types, some PIP types or custom type. In case of standard types this class also provides convertions between them.
PIVariant useful if you want pass many variables with different types in single array, or type may vary from case to case, e.g.:
Result:
| enum PIVariant::Type |
Type of PIVariant content.
| bool PIVariant::toBool | ( | ) | const |
Returns variant content as boolean.
In case of numeric types returns true if value != 0.
In case of String type returns PIString::toBool().
In case of StringList type returns false if string list is empty, otherwise returns PIString::toBool() of first string.
In case of other types returns false.
| int PIVariant::toInt | ( | ) | const |
Returns variant content as int.
In case of numeric types returns integer value.
In case of String type returns PIString::toInt().
In case of StringList type returns 0 if string list is empty, otherwise returns PIString::toInt() of first string.
In case of other types returns 0.
| llong PIVariant::toLLong | ( | ) | const |
Returns variant content as long long.
In case of numeric types returns integer value.
In case of String type returns PIString::toLLong().
In case of StringList type returns 0L if string list is empty, otherwise returns PIString::toLLong() of first string.
In case of other types returns 0L.
| float PIVariant::toFloat | ( | ) | const |
Returns variant content as float.
In case of numeric types returns float value.
In case of String type returns PIString::toFloat().
In case of StringList type returns 0.f if string list is empty, otherwise returns PIString::toFloat() of first string.
In case of other types returns 0.f .
| double PIVariant::toDouble | ( | ) | const |
Returns variant content as double.
In case of numeric types returns double value.
In case of String type returns PIString::toDouble().
In case of StringList type returns 0. if string list is empty, otherwise returns PIString::toDouble() of first string.
In case of other types returns 0. .
| ldouble PIVariant::toLDouble | ( | ) | const |
Returns variant content as long double.
In case of numeric types returns long double value.
In case of String type returns PIString::toLDouble().
In case of StringList type returns 0. if string list is empty, otherwise returns PIString::toLDouble() of first string.
In case of other types returns 0. .
| PITime PIVariant::toTime | ( | ) | const |
Returns variant content as time.
In case of Time type returns time value.
In case of DateTime type returns time part of value.
In case of other types returns PITime().
| PIDate PIVariant::toDate | ( | ) | const |
Returns variant content as date.
In case of Date type returns date value.
In case of DateTime type returns date part of value.
In case of other types returns PIDate().
| PIDateTime PIVariant::toDateTime | ( | ) | const |
Returns variant content as date and time.
In case of Time type returns time value with null date.
In case of Date type returns date value with null time.
In case of DateTime type returns date and time.
In case of other types returns PIDateTime().
| PISystemTime PIVariant::toSystemTime | ( | ) | const |
Returns variant content as system time.
In case of SystemTime type returns system time.
In case of String type returns PISystemTime::fromString().
In case of DateTime type returns PIDateTime::toSystemTime().
In case of other types returns PISystemTime::fromSeconds() from toDouble().
| PIString PIVariant::toString | ( | ) | const |
Returns variant content as string.
In case of numeric types returns PIString::fromNumber().
In case of String type returns string value.
In case of StringList type returns joined string ("(" + PIStringList::join("; ") + ")").
In case of BitArray or ByteArray types returns number of bits/bytes.
In case of Time, Date or DateTime types returns toString() of this values.
In case of SystemTime types returns PISystemTime::toString().
In case of NetworkAddress types returns "i.i.i.i:p".
("(PISystemTime::seconds s, PISystemTime::nanoseconds ns)").
In case of other types returns "".
| PIStringList PIVariant::toStringList | ( | ) | const |
Returns variant content as strings list.
In case of StringList type returns strings list value.
In case of other types returns PIStringList with one string toString().
| PIBitArray PIVariant::toBitArray | ( | ) | const |
Returns variant content as bit array.
In case of BitArray type returns bit array value.
In case of other types returns PIBitArray from toLLong() value.
| PIByteArray PIVariant::toByteArray | ( | ) | const |
Returns variant content as byte array.
In case of ByteArray type returns byte array value.
In case of other types returns empty PIByteArray.
| PIVariantTypes::Enum PIVariant::toEnum | ( | ) | const |
Returns variant content as enum.
In case of Enum type returns enum value.
In case of String returns Enum with one member.
In case of StringList returns Enum with corresponding members.
In case of other types returns empty Enum.
| PIVariantTypes::File PIVariant::toFile | ( | ) | const |
Returns variant content as file.
In case of File type returns file value.
In case of String returns File with string value path.
In case of other types returns empty File.
| PIVariantTypes::Dir PIVariant::toDir | ( | ) | const |
Returns variant content as dir.
In case of Dir type returns dir value.
In case of String returns Dir with string value path.
In case of other types returns empty Dir.
| PIVariantTypes::Color PIVariant::toColor | ( | ) | const |
Returns variant content as color.
In case of Color type returns color value.
In case of Int returns color with int value.
In case of other types returns empty Color.
| PIVariantTypes::IODevice PIVariant::toIODevice | ( | ) | const |
Returns variant content as IODevice.
In case of IODevice type returns IODevice value.
In case of other types returns empty IODevice.
| PIPointd PIVariant::toPoint | ( | ) | const |
Returns variant content as point.
In case of Point type returns point value.
In case of other types returns empty PIPointd.
| PIRectd PIVariant::toRect | ( | ) | const |
Returns variant content as rect.
In case of Rect type returns rect value.
In case of other types returns empty PIRectd.
| PILined PIVariant::toLine | ( | ) | const |
Returns variant content as line.
In case of Line type returns line value.
In case of other types returns empty PILined.
| PINetworkAddress PIVariant::toNetworkAddress | ( | ) | const |
Returns variant content as PINetworkAddress.
In case of NetworkAddress type returns address.
In case of String type returns address from "i.i.i.i:p".
In case of other types returns empty PINetworkAddress.
| PIMathVectord PIVariant::toMathVector | ( | ) | const |
Returns variant content as math vector.
In case of MathVector type returns rect value.
In case of other types returns empty PIMathVectord.
| PIMathMatrixd PIVariant::toMathMatrix | ( | ) | const |
Returns variant content as math matrix.
In case of MathMatrix type returns rect value.
In case of other types returns empty PIMathMatrixd.
|
inline |
Returns variant content as custom type.
In case of known types this function equivalent to<Type> function.
Otherwise returns content as type T only if this type was set earlier.
|
inlinestatic |
Returns new PIVariant from custom type value.
In case of known types this function equivalent PIVariant() constructors.
Otherwise returns variant with content "v" and type pivCustom.