git-svn-id: svn://db.shs.com.ru/pip@182 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Variant type
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
PIP - Platform Independent Primitives
|
||||
Variant type
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pivariant.h"
|
||||
@@ -27,7 +27,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* \section PIVariant_sec1 Usage
|
||||
* %PIVariant useful if you want pass many variables with different types in
|
||||
* single array, e.g.:
|
||||
@@ -40,7 +40,7 @@
|
||||
* \endcode
|
||||
* Result:
|
||||
* \code{cpp}
|
||||
* {PIVariant(int, 10), PIVariant(double, 1,61), PIVariant(bool, true), PIVariant(PIString, 0xFF)}
|
||||
* {PIVariant(Int, 10), PIVariant(Double, 1,61), PIVariant(Bool, true), PIVariant(String, 0xFF)}
|
||||
* 10
|
||||
* 1
|
||||
* 1
|
||||
@@ -48,240 +48,487 @@
|
||||
* \endcode
|
||||
* */
|
||||
|
||||
PIMap<PIString, __PIVariantInfo__ * > * __PIVariantInfoStorage__::map = 0;
|
||||
|
||||
REGISTER_VARIANT_CPP(bool)
|
||||
REGISTER_VARIANT_CPP(char)
|
||||
REGISTER_VARIANT_CPP(uchar)
|
||||
REGISTER_VARIANT_CPP(short)
|
||||
REGISTER_VARIANT_CPP(ushort)
|
||||
REGISTER_VARIANT_CPP(int)
|
||||
REGISTER_VARIANT_CPP(uint)
|
||||
REGISTER_VARIANT_CPP(llong)
|
||||
REGISTER_VARIANT_CPP(ullong)
|
||||
REGISTER_VARIANT_CPP(float)
|
||||
REGISTER_VARIANT_CPP(double)
|
||||
REGISTER_VARIANT_CPP(ldouble)
|
||||
REGISTER_VARIANT_CPP(complexf)
|
||||
REGISTER_VARIANT_CPP(complexd)
|
||||
REGISTER_VARIANT_CPP(complexld)
|
||||
REGISTER_VARIANT_CPP(PIChar)
|
||||
REGISTER_VARIANT_CPP(PIString)
|
||||
REGISTER_VARIANT_CPP(PIStringList)
|
||||
REGISTER_VARIANT_CPP(PIByteArray)
|
||||
REGISTER_VARIANT_CPP(PISystemTime)
|
||||
REGISTER_VARIANT_CPP(PITime)
|
||||
REGISTER_VARIANT_CPP(PIDate)
|
||||
REGISTER_VARIANT_CPP(PIDateTime)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(bool, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(char, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uchar, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(short, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ushort, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(int, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(uint, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(llong, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ullong, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, double)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(float, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(double, ldouble)
|
||||
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, bool)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, char)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, uchar)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, short)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, ushort)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, int)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, uint)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, llong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, ullong)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, float)
|
||||
REGISTER_VARIANT_CAST_SIMPLE_CPP(ldouble, double)
|
||||
|
||||
REGISTER_VARIANT_CAST_CPP(bool, PIString) {return PIString::fromBool(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(char, PIString) {return PIString(PIChar(v));}
|
||||
REGISTER_VARIANT_CAST_CPP(uchar, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(short, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(ushort, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(int, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(uint, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(llong, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(ullong, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(float, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(double, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(ldouble, PIString) {return PIString::fromNumber(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(complexf, PIString) {return "(" + PIString::fromNumber(v.real()) + " + " + PIString::fromNumber(v.imag()) + "i)";}
|
||||
REGISTER_VARIANT_CAST_CPP(complexd, PIString) {return "(" + PIString::fromNumber(v.real()) + " + " + PIString::fromNumber(v.imag()) + "i)";}
|
||||
REGISTER_VARIANT_CAST_CPP(complexld, PIString) {return "(" + PIString::fromNumber(v.real()) + " + " + PIString::fromNumber(v.imag()) + "i)";}
|
||||
REGISTER_VARIANT_CAST_CPP(PIChar, PIString) {return PIString(v);}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, PIString) {return v;}
|
||||
REGISTER_VARIANT_CAST_CPP(PIStringList, PIString) {return v.join(", ");}
|
||||
REGISTER_VARIANT_CAST_CPP(PIByteArray, PIString) {return v.toString();}
|
||||
REGISTER_VARIANT_CAST_CPP(PISystemTime, PIString) {return PIString::fromNumber(v.seconds) + " s, " + PIString::fromNumber(v.nanoseconds) + " ns";}
|
||||
REGISTER_VARIANT_CAST_CPP(PITime, PIString) {return v.toString();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIDate, PIString) {return v.toString();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIDateTime, PIString) {return v.toString();}
|
||||
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, bool) {return v.toBool();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, char) {return v.toChar();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, uchar) {return v.toChar();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, short) {return v.toShort();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, ushort) {return v.toUShort();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, int) {return v.toInt();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, uint) {return v.toUInt();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, llong) {return v.toLLong();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, ullong) {return v.toULLong();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, float) {return v.toFloat();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, double) {return v.toDouble();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, ldouble) {return v.toLDouble();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, PIByteArray) {return v.toByteArray();}
|
||||
REGISTER_VARIANT_CAST_CPP(PIString, PIStringList) {return PIStringList(v);}
|
||||
|
||||
void __PIVariantInitBuiltin__() {
|
||||
static bool first = true;
|
||||
if (!first) return;
|
||||
first = false;
|
||||
INIT_VARIANT(bool)
|
||||
INIT_VARIANT(char)
|
||||
INIT_VARIANT(uchar)
|
||||
INIT_VARIANT(short)
|
||||
INIT_VARIANT(ushort)
|
||||
INIT_VARIANT(int)
|
||||
INIT_VARIANT(uint)
|
||||
INIT_VARIANT(llong)
|
||||
INIT_VARIANT(ullong)
|
||||
INIT_VARIANT(float)
|
||||
INIT_VARIANT(double)
|
||||
INIT_VARIANT(ldouble)
|
||||
INIT_VARIANT(complexf)
|
||||
INIT_VARIANT(complexd)
|
||||
INIT_VARIANT(complexld)
|
||||
INIT_VARIANT(PIChar)
|
||||
INIT_VARIANT(PIString)
|
||||
INIT_VARIANT(PIStringList)
|
||||
INIT_VARIANT(PIByteArray)
|
||||
INIT_VARIANT(PISystemTime)
|
||||
INIT_VARIANT(PITime)
|
||||
INIT_VARIANT(PIDate)
|
||||
INIT_VARIANT(PIDateTime)
|
||||
PIVariant::PIVariant() {
|
||||
type_ = PIVariant::Invalid;
|
||||
memset(_vraw, 0, __PIVARIANT_UNION_SIZE__);
|
||||
}
|
||||
|
||||
|
||||
PIVariant & PIVariant::operator =(const PIVariant & v) {
|
||||
type_ = v.type_;
|
||||
memcpy(_vraw, v._vraw, __PIVARIANT_UNION_SIZE__);
|
||||
_vbytearray = v._vbytearray;
|
||||
_vbitarray = v._vbitarray;
|
||||
_vstring = v._vstring;
|
||||
_vstringlist = v._vstringlist;
|
||||
_vcustom = v._vcustom;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool PIVariant::operator ==(const PIVariant & v) const {
|
||||
if (type_ != v.type_) return false;
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint == v._vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong == v._vllong;
|
||||
case PIVariant::Float: return _vfloat == v._vfloat;
|
||||
case PIVariant::Double: return _vdouble == v._vdouble;
|
||||
case PIVariant::LDouble: return _vldouble == v._vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd == _vvcomplexd(v);
|
||||
case PIVariant::Complexld: return _vcomplexld == _vvcomplexld(v);
|
||||
case PIVariant::BitArray: return _vbitarray == v._vbitarray;
|
||||
case PIVariant::ByteArray: return _vbytearray == v._vbytearray;
|
||||
case PIVariant::String: return _vstring == v._vstring;
|
||||
case PIVariant::StringList: return _vstringlist == v._vstringlist;
|
||||
case PIVariant::Time: return _vtime == _vvtime(v);
|
||||
case PIVariant::Date: return _vdate == _vvdate(v);
|
||||
case PIVariant::DateTime: return _vdatetime == _vvdatetime(v);
|
||||
case PIVariant::SystemTime: return _vsystime == _vvsystime(v);
|
||||
default: break;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
||||
PIString s = tname.trimmed().toLowerCase().replaceAll(" ", "");
|
||||
if (s == "bool" || s == "boolean") return PIVariant::Bool;
|
||||
if (s == "char" || s == "sbyte") return PIVariant::Char;
|
||||
if (s == "short" || s == "shortint" || s == "signedshort" || s == "signedshortint" || s == "sword") return PIVariant::Short;
|
||||
if (s == "int" || s == "signed" || s == "signedint") return PIVariant::Int;
|
||||
if (s == "long" || s == "longint" || s == "signedlong" || s == "signedlongint" || s == "sdword") return PIVariant::Long;
|
||||
if (s == "llong" || s == "longlong" || s == "longlongint" || s == "signedlonglong" || s == "signedlonglongint" || s == "sqword") return PIVariant::LLong;
|
||||
if (s == "uchar" || s == "byte") return PIVariant::UChar;
|
||||
if (s == "ushort" || s == "unsignedshort" || s == "unsignedshortint" || s == "word") return PIVariant::UShort;
|
||||
if (s == "uint" || s == "unsigned" || s == "unsignedint") return PIVariant::UInt;
|
||||
if (s == "ulong" || s == "unsignedlong" || s == "unsignedlongint" || s == "dword") return PIVariant::ULong;
|
||||
if (s == "ullong" || s == "unsignedlonglong" || s == "unsignedlonglongint" || s == "qword") return PIVariant::ULLong;
|
||||
if (s == "float") return PIVariant::Float;
|
||||
if (s == "double" || s == "real") return PIVariant::Double;
|
||||
if (s == "ldouble" || s == "longdouble") return PIVariant::LDouble;
|
||||
if (s == "complexd" || s == "complex<double>") return PIVariant::Complexd;
|
||||
if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::Complexld;
|
||||
if (s == "pibitarray" || s == "bitarray") return PIVariant::BitArray;
|
||||
if (s == "pibytearray" || s == "bytearray" || s == "vector<uchar>" || s == "pivector<uchar>" || s == "vector<unsignedchar>" || s == "pivector<unsignedchar>" ||
|
||||
s == "vector<char>" || s == "pivector<char>") return PIVariant::ByteArray;
|
||||
if (s == "pistring" || s == "string") return PIVariant::String;
|
||||
if (s == "pistringlist" || s == "stringlist" || s == "vector<string>" || s == "vector<pistring>" || s == "pivector<string>" || s == "pivector<pistring>") return PIVariant::StringList;
|
||||
if (s == "pitime" || s == "time") return PIVariant::Time;
|
||||
if (s == "pidate" || s == "date") return PIVariant::Date;
|
||||
if (s == "pidatetime" || s == "datetime") return PIVariant::DateTime;
|
||||
if (s == "pisystemtime" || s == "systemtime") return PIVariant::SystemTime;
|
||||
return PIVariant::Invalid;
|
||||
}
|
||||
|
||||
|
||||
PIString PIVariant::typeName(PIVariant::Type type) {
|
||||
switch (type) {
|
||||
case PIVariant::Bool: return "Bool";
|
||||
case PIVariant::Char: return "Char";
|
||||
case PIVariant::UChar: return "UChar";
|
||||
case PIVariant::Short: return "Short";
|
||||
case PIVariant::UShort: return "UShort";
|
||||
case PIVariant::Int: return "Int";
|
||||
case PIVariant::UInt: return "UInt";
|
||||
case PIVariant::Long: return "Long";
|
||||
case PIVariant::ULong: return "ULong";
|
||||
case PIVariant::LLong: return "LLong";
|
||||
case PIVariant::ULLong: return "ULLong";
|
||||
case PIVariant::Float: return "Float";
|
||||
case PIVariant::Double: return "Double";
|
||||
case PIVariant::LDouble: return "LDouble";
|
||||
case PIVariant::Complexd: return "Complexd";
|
||||
case PIVariant::Complexld: return "Complexld";
|
||||
case PIVariant::BitArray: return "BitArray";
|
||||
case PIVariant::ByteArray: return "ByteArray";
|
||||
case PIVariant::String: return "String";
|
||||
case PIVariant::StringList: return "StringList";
|
||||
case PIVariant::Time: return "Time";
|
||||
case PIVariant::Date: return "Date";
|
||||
case PIVariant::DateTime: return "DateTime";
|
||||
case PIVariant::SystemTime: return "SystemTime";
|
||||
case PIVariant::Custom: return "Custom";
|
||||
default: break;
|
||||
}
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as boolean
|
||||
* \details In case of numeric types returns \b true if value != 0. \n
|
||||
* In case of String type returns \a PIString::toBool(). \n
|
||||
* In case of StringList type returns \b false if string list is empty,
|
||||
* otherwise returns \a PIString::toBool() of first string. \n
|
||||
* In case of other types returns \b false. */
|
||||
bool PIVariant::toBool() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint != 0;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong != 0;
|
||||
case PIVariant::Float: return _vfloat != 0;
|
||||
case PIVariant::Double: return _vdouble != 0;
|
||||
case PIVariant::LDouble: return _vldouble != 0;
|
||||
case PIVariant::Complexd: return _vcomplexd.real() != 0;
|
||||
case PIVariant::Complexld: return _vcomplexld.real() != 0;
|
||||
case PIVariant::String: return _vstring.toBool();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return false; return _vstringlist.front().toBool();
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** \brief Returns variant content as int
|
||||
* \details In case of numeric types returns integer value. \n
|
||||
* In case of String type returns \a PIString::toInt(). \n
|
||||
* In case of StringList type returns \b 0 if string list is empty,
|
||||
* otherwise returns \a PIString::toInt() of first string. \n
|
||||
* In case of other types returns \b 0. */
|
||||
int PIVariant::toInt() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toInt();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return 0; return _vstringlist.front().toInt();
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as long long
|
||||
* \details In case of numeric types returns integer value. \n
|
||||
* In case of String type returns \a PIString::toLLong(). \n
|
||||
* In case of StringList type returns \b 0L if string list is empty,
|
||||
* otherwise returns \a PIString::toLLong() of first string. \n
|
||||
* In case of other types returns \b 0L. */
|
||||
llong PIVariant::toLLong() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toLLong();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return 0L; return _vstringlist.front().toLLong();
|
||||
default: break;
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as float
|
||||
* \details In case of numeric types returns float value. \n
|
||||
* In case of String type returns \a PIString::toFloat(). \n
|
||||
* In case of StringList type returns \b 0.f if string list is empty,
|
||||
* otherwise returns \a PIString::toFloat() of first string. \n
|
||||
* In case of other types returns \b 0.f. */
|
||||
float PIVariant::toFloat() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toFloat();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return 0.f; return _vstringlist.front().toFloat();
|
||||
default: break;
|
||||
}
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as double
|
||||
* \details In case of numeric types returns double value. \n
|
||||
* In case of String type returns \a PIString::toDouble(). \n
|
||||
* In case of StringList type returns \b 0. if string list is empty,
|
||||
* otherwise returns \a PIString::toDouble() of first string. \n
|
||||
* In case of other types returns \b 0.. */
|
||||
double PIVariant::toDouble() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toDouble();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return 0.; return _vstringlist.front().toDouble();
|
||||
default: break;
|
||||
}
|
||||
return 0.;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as long double
|
||||
* \details In case of numeric types returns long double value. \n
|
||||
* In case of String type returns \a PIString::toLDouble(). \n
|
||||
* In case of StringList type returns \b 0. if string list is empty,
|
||||
* otherwise returns \a PIString::toLDouble() of first string. \n
|
||||
* In case of other types returns \b 0.. */
|
||||
ldouble PIVariant::toLDouble() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toLDouble();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return 0.; return _vstringlist.front().toLDouble();
|
||||
default: break;
|
||||
}
|
||||
return 0.;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as complex
|
||||
* \details In case of numeric types returns complex value. \n
|
||||
* In case of String type returns \a PIString::toDouble(). \n
|
||||
* In case of StringList type returns \b 0. if string list is empty,
|
||||
* otherwise returns \a PIString::toDouble() of first string. \n
|
||||
* In case of other types returns \b 0.. */
|
||||
complexd PIVariant::toComplexd() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toDouble();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return complexd_0; return _vstringlist.front().toDouble();
|
||||
default: break;
|
||||
}
|
||||
return complexd_0;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as long complex
|
||||
* \details In case of numeric types returns long complex value. \n
|
||||
* In case of String type returns \a PIString::toLDouble(). \n
|
||||
* In case of StringList type returns \b 0. if string list is empty,
|
||||
* otherwise returns \a PIString::toLDouble() of first string. \n
|
||||
* In case of other types returns \b 0.. */
|
||||
complexld PIVariant::toComplexld() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool:
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return _vint;
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return _vllong;
|
||||
case PIVariant::Float: return _vfloat;
|
||||
case PIVariant::Double: return _vdouble;
|
||||
case PIVariant::LDouble: return _vldouble;
|
||||
case PIVariant::Complexd: return _vcomplexd.real();
|
||||
case PIVariant::Complexld: return _vcomplexld.real();
|
||||
case PIVariant::String: return _vstring.toLDouble();
|
||||
case PIVariant::StringList: if (_vstringlist.isEmpty()) return complexld_0; return _vstringlist.front().toLDouble();
|
||||
default: break;
|
||||
}
|
||||
return complexld_0;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as time
|
||||
* \details In case of Time type returns time value. \n
|
||||
* In case of DateTime type returns time part of value. \n
|
||||
* In case of other types returns \a PITime(). */
|
||||
PITime PIVariant::toTime() const {
|
||||
if (type_ == PIVariant::Time) return _vtime;
|
||||
if (type_ == PIVariant::DateTime) return _vtime;
|
||||
return PITime();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as date
|
||||
* \details In case of Date type returns date value. \n
|
||||
* In case of DateTime type returns date part of value. \n
|
||||
* In case of other types returns \a PIDate(). */
|
||||
PIDate PIVariant::toDate() const {
|
||||
if (type_ == PIVariant::Date) return _vdate;
|
||||
if (type_ == PIVariant::DateTime) return *((PIDate*)(&(_vdatetime.day)));
|
||||
return PIDate();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as date and time
|
||||
* \details In case of Time type returns time value with null date. \n
|
||||
* In case of Date type returns date value with null time. \n
|
||||
* In case of DateTime type returns date and time. \n
|
||||
* In case of other types returns \a PIDateTime(). */
|
||||
PIDateTime PIVariant::toDateTime() const {
|
||||
if (type_ == PIVariant::DateTime) return _vdatetime;
|
||||
if (type_ == PIVariant::Time) return PIDateTime(_vtime);
|
||||
if (type_ == PIVariant::Date) return PIDateTime(_vdate);
|
||||
return PIDateTime();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as system time
|
||||
* \details In case of SystemTime type returns system time. \n
|
||||
* In case of other types returns \a PISystemTime::fromSeconds() from
|
||||
* double value of variant content. */
|
||||
PISystemTime PIVariant::toSystemTime() const {
|
||||
if (type_ == PIVariant::SystemTime) return _vsystime;
|
||||
return PISystemTime::fromSeconds(toDouble());
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as string
|
||||
* \details In case of numeric types returns \a PIString::fromNumber(). \n
|
||||
* In case of String type returns string value. \n
|
||||
* In case of StringList type returns joined string ("(" + PIStringList::join("; ") + ")"). \n
|
||||
* In case of BitArray or ByteArray types returns number of bits/bytes. \n
|
||||
* In case of Time, Date or DateTime types returns toString() of this values. \n
|
||||
* In case of SystemTime types returns second and nanoseconds of time
|
||||
* ("(PISystemTime::seconds s, PISystemTime::nanoseconds ns)"). \n
|
||||
* In case of other types returns \b "". */
|
||||
PIString PIVariant::toString() const {
|
||||
switch (type_) {
|
||||
case PIVariant::Bool: return _vint == 0 ? "false" : "true";
|
||||
case PIVariant::Char:
|
||||
case PIVariant::UChar:
|
||||
case PIVariant::Short:
|
||||
case PIVariant::UShort:
|
||||
case PIVariant::Int:
|
||||
case PIVariant::UInt:
|
||||
case PIVariant::Long:
|
||||
case PIVariant::ULong: return PIString::fromNumber(_vint);
|
||||
case PIVariant::LLong:
|
||||
case PIVariant::ULLong: return PIString::fromNumber(_vllong);
|
||||
case PIVariant::Float: return PIString::fromNumber(_vfloat);
|
||||
case PIVariant::Double: return PIString::fromNumber(_vdouble);
|
||||
case PIVariant::LDouble: return PIString::fromNumber(_vldouble);
|
||||
case PIVariant::Complexd: return "(" + PIString::fromNumber(_vcomplexd.real()) + "; " + PIString::fromNumber(_vcomplexd.imag()) + ")";
|
||||
case PIVariant::Complexld: return "(" + PIString::fromNumber(_vcomplexld.real()) + "; " + PIString::fromNumber(_vcomplexld.imag()) + ")";
|
||||
case PIVariant::BitArray: return PIString::fromNumber(_vbitarray.bitSize()) + " bits";
|
||||
case PIVariant::ByteArray: return _vbytearray.toString();
|
||||
case PIVariant::String: return _vstring;
|
||||
case PIVariant::StringList: return "(" + _vstringlist.join("; ") + ")";
|
||||
case PIVariant::Time: return _vtime.toString();
|
||||
case PIVariant::Date: return _vdate.toString();
|
||||
case PIVariant::DateTime: return _vdatetime.toString();
|
||||
case PIVariant::SystemTime: return "(" + PIString::fromNumber(_vsystime.seconds) + " s, " + PIString::fromNumber(_vsystime.nanoseconds) + " ns)";
|
||||
default: break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as strings list
|
||||
* \details In case of StringList type returns strings list value. \n
|
||||
* In case of other types returns \a PIStringList with one string value of variant content. */
|
||||
PIStringList PIVariant::toStringList() const {
|
||||
if (type_ == PIVariant::StringList) return _vstringlist;
|
||||
return PIStringList(toString());
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as bit array
|
||||
* \details In case of BitArray type returns bit array value. \n
|
||||
* In case of other types returns \a PIBitArray from \a toLLong() value. */
|
||||
PIBitArray PIVariant::toBitArray() const {
|
||||
if (type_ == PIVariant::BitArray) return _vbitarray;
|
||||
return PIBitArray(ullong(toLLong()));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as byte array
|
||||
* \details In case of ByteArray type returns byte array value. \n
|
||||
* In case of other types returns empty \a PIByteArray. */
|
||||
PIByteArray PIVariant::toByteArray() const {
|
||||
if (type_ == PIVariant::ByteArray) return _vbytearray;
|
||||
return PIByteArray();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user