PIP  1.8.0
Platform-Independent Primitives
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, pivColor, pivPoint,
  pivRect, 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, pivColor, pivPoint,
  pivRect, 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 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.
 
 PIVariant (const PIVariantTypes::Color &v)
 Constructs variant from color.
 
 PIVariant (const PIPointd &v)
 Constructs variant from point.
 
 PIVariant (const PIRectd &v)
 Constructs variant from rect.
 
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 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 PIPointd &v)
 Set variant content and type to point.
 
void setValue (const PIRectd &v)
 Set variant content and type to rect.
 
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...
 
PIPointd toPoint () const
 Returns variant content as point. More...
 
PIRectd toRect () const
 Returns variant content as rect. More...
 
template<typename T >
value () const
 Returns variant content as custom type. More...
 
PIVariantoperator= (const PIVariant &v)
 Assign operator.
 
PIVariantoperator= (const char *v)
 Assign operator.
 
PIVariantoperator= (const bool v)
 Assign operator.
 
PIVariantoperator= (const char v)
 Assign operator.
 
PIVariantoperator= (const uchar v)
 Assign operator.
 
PIVariantoperator= (const short v)
 Assign operator.
 
PIVariantoperator= (const ushort v)
 Assign operator.
 
PIVariantoperator= (const int &v)
 Assign operator.
 
PIVariantoperator= (const uint &v)
 Assign operator.
 
PIVariantoperator= (const llong &v)
 Assign operator.
 
PIVariantoperator= (const ullong &v)
 Assign operator.
 
PIVariantoperator= (const float &v)
 Assign operator.
 
PIVariantoperator= (const double &v)
 Assign operator.
 
PIVariantoperator= (const ldouble &v)
 Assign operator.
 
PIVariantoperator= (const PIBitArray &v)
 Assign operator.
 
PIVariantoperator= (const PIByteArray &v)
 Assign operator.
 
PIVariantoperator= (const PIString &v)
 Assign operator.
 
PIVariantoperator= (const PIStringList &v)
 Assign operator.
 
PIVariantoperator= (const PITime &v)
 Assign operator.
 
PIVariantoperator= (const PIDate &v)
 Assign operator.
 
PIVariantoperator= (const PIDateTime &v)
 Assign operator.
 
PIVariantoperator= (const PISystemTime &v)
 Assign operator.
 
PIVariantoperator= (const PIVariantTypes::Enum &v)
 Assign operator.
 
PIVariantoperator= (const PIVariantTypes::File &v)
 Assign operator.
 
PIVariantoperator= (const PIVariantTypes::Dir &v)
 Assign operator.
 
PIVariantoperator= (const PIVariantTypes::Color &v)
 Assign operator.
 
PIVariantoperator= (const PIPointd &v)
 Assign operator.
 
PIVariantoperator= (const PIRectd &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.:

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]

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

pivColor 

PIVariantTypes::Color

pivPoint 

PIPoint

pivRect 

PIRect

pivCustom 

Custom

◆ Type [2/2]

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

pivColor 

PIVariantTypes::Color

pivPoint 

PIPoint

pivRect 

PIRect

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

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

◆ toDir()

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.

◆ toColor()

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.

◆ toPoint()

PIPointd PIVariant::toPoint ( ) const

Returns variant content as point.

In case of PIPointd type returns point value.
In case of other types returns empty PIPointd.

◆ toRect()

PIRectd PIVariant::toRect ( ) const

Returns variant content as rect.

In case of PIRectd type returns rect value.
In case of other types returns empty PIRectd.

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