PIP 0.7.1 Platform-Independent Primitives

Public Types | Public Member Functions | Static Public Member Functions | List of all members
PIVariant Class Reference

Variant type. More...

## 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, pivCustom = 0xFF }
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, pivCustom = 0xFF }
| Type of PIVariant content. More...

## Public Member Functions
| PIVariant ()
| Empty constructor, type() will be set to Invalid.
| PIVariant (const char *v)
| Constructs variant from string.
| PIVariant (const bool v)
| Constructs variant from boolean.
| PIVariant (const char v)
| Constructs variant from char.
| PIVariant (const uchar v)
| Constructs variant from integer.
| PIVariant (const short v)
| Constructs variant from integer.
| PIVariant (const ushort v)
| Constructs variant from integer.
| PIVariant (const int &v)
| Constructs variant from integer.
| PIVariant (const uint &v)
| Constructs variant from integer.
| PIVariant (const llong &v)
| Constructs variant from integer.
| PIVariant (const ullong &v)
| Constructs variant from integer.
| PIVariant (const float &v)
| Constructs variant from float.
| PIVariant (const double &v)
| Constructs variant from double.
| PIVariant (const ldouble &v)
| Constructs variant from long double.
| PIVariant (const complexd &v)
| Constructs variant from complex.
| PIVariant (const complexld &v)
| Constructs variant from complex.
| PIVariant (const PIBitArray &v)
| Constructs variant from bit array.
| PIVariant (const PIByteArray &v)
| Constructs variant from byte array.
| PIVariant (const PIString &v)
| Constructs variant from string.
| PIVariant (const PIStringList &v)
| Constructs variant from strings list.
| PIVariant (const PITime &v)
| Constructs variant from time.
| PIVariant (const PIDate &v)
| Constructs variant from date.
| PIVariant (const PIDateTime &v)
| Constructs variant from date and time.
| PIVariant (const PISystemTime &v)
| Constructs variant from system time.
| PIVariant (const PIVariantTypes::Enum &v)
| Constructs variant from enum.
| PIVariant (const PIVariantTypes::File &v)
| Constructs variant from file.
| PIVariant (const PIVariantTypes::Dir &v)
| Constructs variant from dir.
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 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.
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...
complexd | toComplexd () const
| Returns variant content as complex. More...
complexld | toComplexld () const
| Returns variant content as long complex. 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...
template<typename T >
T | value () const
| Returns variant content as custom type. More...
PIVariant & | operator= (const 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 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.
bool | operator== (const PIVariant &v) const
| Compare operator.
bool | operator!= (const PIVariant &v) const
| Compare operator.
PIVariant::Type | type () const
| Returns type of variant content.
PIString | typeName () const
| Returns type name of variant content.
bool | isValid () const
| Returns true if type is not Invalid.

## Static Public Member Functions
template<typename T >
static PIVariant | fromValue (const T &v)
| Returns new variant from custom type. More...
static PIVariant::Type | typeFromName (const PIString &tname)
| Returns type from name.
static PIString | typeName (PIVariant::Type type)
| Returns type name.

## Detailed Description

Variant type.

# Synopsis

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.

# Usage

PIVariant useful if you want pass many variables with different types in single array, e.g.:

PIVector<PIVariant> array;
array << PIVariant(10) << PIVariant(1.61) << PIVariant(true) << PIVariant("0xFF");
piCout << array;
piForeachC (PIVariant & i, array)
piCout << i.toInt();

Result:

{PIVariant(Int, 10), PIVariant(Double, 1,61), PIVariant(Bool, true), PIVariant(String, 0xFF)}
10
1
1
255

## Member Enumeration Documentation

## ◆ Type [1/2]

enum PIVariant::Type

Enumerator
pivInvalid | Invalid type , default type of empty contructor
pivBool | bool
pivChar | char
pivUChar | uchar
pivShort | short
pivUShort | ushort
pivInt | int
pivUInt | uint
pivLLong | llong
pivULLong | ullong
pivFloat | float
pivDouble | double
pivLDouble | ldouble
pivComplexd | complexd
pivComplexld | complexld
pivBitArray | PIBitArray
pivByteArray | PIByteArray
pivString | PIString
pivStringList | PIStringList
pivTime | PITime
pivDate | PIDate
pivDateTime | PIDateTime
pivSystemTime | PISystemTime
pivEnum | PIVariantTypes::Enum
pivFile | PIVariantTypes::File
pivDir | PIVariantTypes::Dir
pivCustom | Custom

## ◆ Type [2/2]

enum PIVariant::Type

Type of PIVariant content.

Enumerator
pivInvalid | Invalid type , default type of empty contructor
pivBool | bool
pivChar | char
pivUChar | uchar
pivShort | short
pivUShort | ushort
pivInt | int
pivUInt | uint
pivLLong | llong
pivULLong | ullong
pivFloat | float
pivDouble | double
pivLDouble | ldouble
pivComplexd | complexd
pivComplexld | complexld
pivBitArray | PIBitArray
pivByteArray | PIByteArray
pivString | PIString
pivStringList | PIStringList
pivTime | PITime
pivDate | PIDate
pivDateTime | PIDateTime
pivSystemTime | PISystemTime
pivEnum | PIVariantTypes::Enum
pivFile | PIVariantTypes::File
pivDir | PIVariantTypes::Dir
pivCustom | Custom

## Member Function Documentation

## ◆ toBool()

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.

## ◆ toInt()

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.

## ◆ toLLong()

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.

## ◆ toFloat()

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.

## ◆ toDouble()

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

## ◆ toLDouble()

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

## ◆ toComplexd()

complexd PIVariant::toComplexd | ( |  | ) | const

Returns variant content as complex.

In case of numeric types returns complex 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..

## ◆ toComplexld()

complexld PIVariant::toComplexld | ( |  | ) | const

Returns variant content as long complex.

In case of numeric types returns long complex 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..

## ◆ toTime()

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().

## ◆ toDate()

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().

## ◆ toDateTime()

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().

## ◆ toSystemTime()

PISystemTime PIVariant::toSystemTime | ( |  | ) | const

Returns variant content as system time.

In case of SystemTime type returns system time.
In case of other types returns PISystemTime::fromSeconds() from double value of variant content.

## ◆ toString()

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 second and nanoseconds of time ("(PISystemTime::seconds s, PISystemTime::nanoseconds ns)").
In case of other types returns "".

## ◆ toStringList()

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 value of variant content.

## ◆ toBitArray()

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.

## ◆ toByteArray()

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.

## ◆ toEnum()

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.

## ◆ toFile()

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

## ◆ toDir()

PIVariantTypes::Dir PIVariant::toDir | ( |  | ) | const

Returns variant content as dir.

In case of Dir type returns dir value.
In case of Dir returns Dir with string value path.
In case of other types returns empty Enum.

## ◆ value()

template<typename T >

T PIVariant::value | ( |  | ) | const
| inline

Returns variant content as custom type.

In case of known types this function equivalent to<Type> function.
Otherwise returns content as type T.

## ◆ fromValue()

template<typename T >

static PIVariant PIVariant::fromValue | ( | const T & | v | ) |
| inline static

Returns new variant from custom type.

In case of known types this function equivalent PIVariant(T) constructors.
Otherwise returns variant with content v and type Custom.