# PIP: PIVariant Class Reference

PIVariant Class Reference

Variant type. More...

## Public Types

enum | Type { Bool, Char, Short, Int, Long, LLong, UChar, UShort, UInt, ULong, ULLong, Float, Double, LDouble, String, StringList, Invalid = 0, Bool, Char, UChar, Short, UShort, Int, UInt, Long, ULong, LLong, ULLong, Float, Double, LDouble, Complexd, Complexld, BitArray, ByteArray, String, StringList, Time, Date, DateTime, SystemTime, Custom = 0xFF }
enum | Type { Bool, Char, Short, Int, Long, LLong, UChar, UShort, UInt, ULong, ULLong, Float, Double, LDouble, String, StringList, Invalid = 0, Bool, Char, UChar, Short, UShort, Int, UInt, Long, ULong, LLong, ULLong, Float, Double, LDouble, Complexd, Complexld, BitArray, ByteArray, String, StringList, Time, Date, DateTime, SystemTime, Custom = 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 long &v)
| Constructs variant from integer.
| PIVariant (const ulong &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.
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 long &v)
| Set variant content and type to integer.
void | setValue (const ulong &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.
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...
template<typename T >
T | toValue () 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 long &v)
| Assign operator.
PIVariant & | operator= (const ulong &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.
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

enum PIVariant::Type

Enumerator
Bool | bool
Char | char
Short | short
Int | int
Long | long
LLong | llong
UChar | uchar
UShort | ushort
UInt | uint
ULong | ulong
ULLong | ullong
Float | float
Double | double
LDouble | ldouble
String | PIString
StringList | PIStringList
Invalid | Invalid type , default type of empty contructor
Bool | bool
Char | char
UChar | uchar
Short | short
UShort | ushort
Int | int
UInt | uint
Long | long
ULong | ulong
LLong | llong
ULLong | ullong
Float | float
Double | double
LDouble | ldouble
Complexd | complexd
Complexld | complexld
BitArray | PIBitArray
ByteArray | PIByteArray
String | PIString
StringList | PIStringList
Time | PITime
Date | PIDate
DateTime | PIDateTime
SystemTime | PISystemTime
Custom | Custom

enum PIVariant::Type

Type of PIVariant content.

Enumerator
Bool | bool
Char | char
Short | short
Int | int
Long | long
LLong | llong
UChar | uchar
UShort | ushort
UInt | uint
ULong | ulong
ULLong | ullong
Float | float
Double | double
LDouble | ldouble
String | PIString
StringList | PIStringList
Invalid | Invalid type , default type of empty contructor
Bool | bool
Char | char
UChar | uchar
Short | short
UShort | ushort
Int | int
UInt | uint
Long | long
ULong | ulong
LLong | llong
ULLong | ullong
Float | float
Double | double
LDouble | ldouble
Complexd | complexd
Complexld | complexld
BitArray | PIBitArray
ByteArray | PIByteArray
String | PIString
StringList | PIStringList
Time | PITime
Date | PIDate
DateTime | PIDateTime
SystemTime | PISystemTime
Custom | Custom

## Member Function Documentation

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

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

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

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 other types returns PISystemTime::fromSeconds() from double value of variant content.

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

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.

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.

template<typename T >

T PIVariant::toValue | ( |  | ) | 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.

template<typename T >

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

inlinestatic

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.