version 5.5.2
PIVariant complex(f,d,ld) full support
This commit is contained in:
@@ -6,7 +6,7 @@ endif()
|
||||
project(PIP)
|
||||
set(PIP_MAJOR 5)
|
||||
set(PIP_MINOR 5)
|
||||
set(PIP_REVISION 1)
|
||||
set(PIP_REVISION 2)
|
||||
set(PIP_SUFFIX )
|
||||
set(PIP_COMPANY SHS)
|
||||
set(PIP_DOMAIN org.SHS)
|
||||
|
||||
@@ -130,6 +130,18 @@ void PIVariant::setValueFromString(const PIString & v) {
|
||||
case PIVariant::pivLDouble: {
|
||||
setValue(v.toLDouble());
|
||||
} break;
|
||||
case PIVariant::pivComplexf: {
|
||||
PIStringList sl = v.mid(1, v.size_s() - 2).split(';');
|
||||
setValue(complexf(sl.size() > 0 ? sl[0].toFloat() : 0.f, sl.size() > 1 ? sl[1].toFloat() : 0.f));
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
PIStringList sl = v.mid(1, v.size_s() - 2).split(';');
|
||||
setValue(complexd(sl.size() > 0 ? sl[0].toDouble() : 0., sl.size() > 1 ? sl[1].toDouble() : 0.));
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
PIStringList sl = v.mid(1, v.size_s() - 2).split(';');
|
||||
setValue(complexld(sl.size() > 0 ? sl[0].toLDouble() : 0.L, sl.size() > 1 ? sl[1].toLDouble() : 0.L));
|
||||
}
|
||||
case PIVariant::pivTime: {
|
||||
setValue(PITime::fromString(v));
|
||||
} break;
|
||||
@@ -242,6 +254,7 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
||||
if (s == "float") return PIVariant::pivFloat;
|
||||
if (s == "double" || s == "real") return PIVariant::pivDouble;
|
||||
if (s == "ldouble" || s == "longdouble") return PIVariant::pivLDouble;
|
||||
if (s == "complexf" || s == "complex<float>") return PIVariant::pivComplexf;
|
||||
if (s == "complexd" || s == "complex<double>") return PIVariant::pivComplexd;
|
||||
if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::pivComplexld;
|
||||
if (s == "pibitarray" || s == "bitarray") return PIVariant::pivBitArray;
|
||||
@@ -286,6 +299,7 @@ PIVariant::Type PIVariant::typeFromID(uint type_id) {
|
||||
if (type_id == typeID<float>()) return PIVariant::pivFloat;
|
||||
if (type_id == typeID<double>()) return PIVariant::pivDouble;
|
||||
if (type_id == typeID<ldouble>()) return PIVariant::pivLDouble;
|
||||
if (type_id == typeID<complexf>()) return PIVariant::pivComplexf;
|
||||
if (type_id == typeID<complexd>()) return PIVariant::pivComplexd;
|
||||
if (type_id == typeID<complexld>()) return PIVariant::pivComplexld;
|
||||
if (type_id == typeID<PIBitArray>()) return PIVariant::pivBitArray;
|
||||
@@ -336,6 +350,7 @@ uint PIVariant::typeIDFromType(Type type) {
|
||||
case (PIVariant::pivFloat ): return typeID<float >();
|
||||
case (PIVariant::pivDouble ): return typeID<double >();
|
||||
case (PIVariant::pivLDouble ): return typeID<ldouble >();
|
||||
case (PIVariant::pivComplexf ): return typeID<complexf >();
|
||||
case (PIVariant::pivComplexd ): return typeID<complexd >();
|
||||
case (PIVariant::pivComplexld ): return typeID<complexld >();
|
||||
case (PIVariant::pivBitArray ): return typeID<PIBitArray >();
|
||||
@@ -451,6 +466,7 @@ PIString PIVariant::typeName(PIVariant::Type type) {
|
||||
case PIVariant::pivFloat: return "Float";
|
||||
case PIVariant::pivDouble: return "Double";
|
||||
case PIVariant::pivLDouble: return "LDouble";
|
||||
case PIVariant::pivComplexf: return "Complexf";
|
||||
case PIVariant::pivComplexd: return "Complexd";
|
||||
case PIVariant::pivComplexld: return "Complexld";
|
||||
case PIVariant::pivBitArray: return "BitArray";
|
||||
@@ -691,6 +707,21 @@ int PIVariant::toInt() const {
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
@@ -806,6 +837,21 @@ llong PIVariant::toLLong() const {
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
@@ -916,6 +962,21 @@ float PIVariant::toFloat() const {
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
@@ -1026,6 +1087,21 @@ double PIVariant::toDouble() const {
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
@@ -1136,6 +1212,21 @@ ldouble PIVariant::toLDouble() const {
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return r.real();
|
||||
}
|
||||
case PIVariant::pivString: {
|
||||
PIString r;
|
||||
ba >> r;
|
||||
@@ -1164,6 +1255,96 @@ ldouble PIVariant::toLDouble() const {
|
||||
}
|
||||
|
||||
|
||||
complexf PIVariant::toComplexF() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return complexf(r.real(), r.imag());
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return complexf(r.real(), r.imag());
|
||||
}
|
||||
case PIVariant::pivMathVector: {
|
||||
PIMathVectord r;
|
||||
ba >> r;
|
||||
return complexf(r.size() > 0 ? r[0] : 0., r.size() > 1 ? r[1] : 0.);
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<complexf>(*this);
|
||||
default: return complexf(toFloat(), 0.f);
|
||||
}
|
||||
return complexf();
|
||||
}
|
||||
|
||||
|
||||
complexd PIVariant::toComplexD() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return complexd(r.real(), r.imag());
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return complexd(r.real(), r.imag());
|
||||
}
|
||||
case PIVariant::pivMathVector: {
|
||||
PIMathVectord r;
|
||||
ba >> r;
|
||||
return complexd(r.size() > 0 ? r[0] : 0., r.size() > 1 ? r[1] : 0.);
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<complexd>(*this);
|
||||
default: return complexd(toDouble(), 0.f);
|
||||
}
|
||||
return complexd();
|
||||
}
|
||||
|
||||
|
||||
complexld PIVariant::toComplexLD() const {
|
||||
PIByteArray ba(_content);
|
||||
switch (_type) {
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
return complexld(r.real(), r.imag());
|
||||
ba >> r;
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return complexld(r.real(), r.imag());
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return r;
|
||||
}
|
||||
case PIVariant::pivMathVector: {
|
||||
PIMathVectord r;
|
||||
ba >> r;
|
||||
return complexld(r.size() > 0 ? r[0] : 0., r.size() > 1 ? r[1] : 0.);
|
||||
}
|
||||
case PIVariant::pivCustom: return getAsValue<complexld>(*this);
|
||||
default: return complexld(toLDouble(), 0.f);
|
||||
}
|
||||
return complexld();
|
||||
}
|
||||
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Returns variant content as time
|
||||
//! \~russian Возвращает содержимое как время
|
||||
@@ -1418,6 +1599,21 @@ PIString PIVariant::toString() const {
|
||||
ba >> r;
|
||||
return PIString::fromNumber(r);
|
||||
}
|
||||
case PIVariant::pivComplexf: {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return "(" + PIString::fromNumber(r.real()) + ";" + PIString::fromNumber(r.imag()) + ")";
|
||||
}
|
||||
case PIVariant::pivComplexd: {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
return "(" + PIString::fromNumber(r.real()) + ";" + PIString::fromNumber(r.imag()) + ")";
|
||||
}
|
||||
case PIVariant::pivComplexld: {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
return "(" + PIString::fromNumber(r.real()) + ";" + PIString::fromNumber(r.imag()) + ")";
|
||||
}
|
||||
case PIVariant::pivTime: {
|
||||
PITime r;
|
||||
ba >> r;
|
||||
@@ -1910,21 +2106,45 @@ PINetworkAddress PIVariant::toNetworkAddress() const {
|
||||
//! Для остальных типов возвращает пустой PIMathVectord.
|
||||
//!
|
||||
PIMathVectord PIVariant::toMathVector() const {
|
||||
PIMathVectord ret;
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivMathVector) {
|
||||
PIMathVectord r;
|
||||
if (_type == PIVariant::pivComplexf) {
|
||||
complexf r;
|
||||
ba >> r;
|
||||
return r;
|
||||
ret.resize(2);
|
||||
ret[0] = r.real();
|
||||
ret[1] = r.imag();
|
||||
return ret;
|
||||
}
|
||||
if (_type == PIVariant::pivComplexd) {
|
||||
complexd r;
|
||||
ba >> r;
|
||||
ret.resize(2);
|
||||
ret[0] = r.real();
|
||||
ret[1] = r.imag();
|
||||
return ret;
|
||||
}
|
||||
if (_type == PIVariant::pivComplexld) {
|
||||
complexld r;
|
||||
ba >> r;
|
||||
ret.resize(2);
|
||||
ret[0] = r.real();
|
||||
ret[1] = r.imag();
|
||||
return ret;
|
||||
}
|
||||
if (_type == PIVariant::pivMathVector) {
|
||||
ba >> ret;
|
||||
return ret;
|
||||
}
|
||||
if (_type == PIVariant::pivPoint) {
|
||||
PIPointd r;
|
||||
ba >> r;
|
||||
PIMathVectord ret(2);
|
||||
ret.resize(2);
|
||||
ret[0] = r.x;
|
||||
ret[1] = r.y;
|
||||
return ret;
|
||||
}
|
||||
return PIMathVectord();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -260,6 +260,7 @@ public:
|
||||
pivMathMatrix /** PIMathMatrix<double> */,
|
||||
pivLine /** PILine<double> */,
|
||||
pivNetworkAddress /** PINetworkAddress */,
|
||||
pivComplexf /** complexf */,
|
||||
pivCustom /** \~english Custom \~russian Свой тип */ = 0xFF
|
||||
};
|
||||
|
||||
@@ -327,6 +328,18 @@ public:
|
||||
//! \~russian Создает %PIVariant из вещественного числа.
|
||||
PIVariant(const ldouble & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from complex number.
|
||||
//! \~russian Создает %PIVariant из комплексного числа.
|
||||
PIVariant(const complexf & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from complex number.
|
||||
//! \~russian Создает %PIVariant из комплексного числа.
|
||||
PIVariant(const complexd & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from complex number.
|
||||
//! \~russian Создает %PIVariant из комплексного числа.
|
||||
PIVariant(const complexld & v) { initType(v); }
|
||||
|
||||
//! \~english Constructs %PIVariant from bit array.
|
||||
//! \~russian Создает %PIVariant из массива битов.
|
||||
PIVariant(const PIBitArray & v) { initType(v); }
|
||||
@@ -456,6 +469,18 @@ public:
|
||||
//! \~russian Устанавливает значение и тип из вещественного числа
|
||||
void setValue(const ldouble & v) { initType(v); }
|
||||
|
||||
//! \~english Set variant content and type to complex
|
||||
//! \~russian Устанавливает значение и тип из комплексного числа
|
||||
void setValue(const complexf & v) { initType(v); }
|
||||
|
||||
//! \~english Set variant content and type to complex
|
||||
//! \~russian Устанавливает значение и тип из комплексного числа
|
||||
void setValue(const complexd & v) { initType(v); }
|
||||
|
||||
//! \~english Set variant content and type to complex
|
||||
//! \~russian Устанавливает значение и тип из комплексного числа
|
||||
void setValue(const complexld & v) { initType(v); }
|
||||
|
||||
//! \~english Set variant content and type to bit array
|
||||
//! \~russian Устанавливает значение и тип из массива битов
|
||||
void setValue(const PIBitArray & v) { initType(v); }
|
||||
@@ -545,6 +570,9 @@ public:
|
||||
float toFloat() const;
|
||||
double toDouble() const;
|
||||
ldouble toLDouble() const;
|
||||
complexf toComplexF() const;
|
||||
complexd toComplexD() const;
|
||||
complexld toComplexLD() const;
|
||||
PITime toTime() const;
|
||||
PIDate toDate() const;
|
||||
PIDateTime toDateTime() const;
|
||||
@@ -680,6 +708,27 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator=(const complexf & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator=(const complexd & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator=(const complexld & v) {
|
||||
setValue(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
PIVariant & operator=(const PIBitArray & v) {
|
||||
@@ -994,6 +1043,9 @@ template<> inline ullong PIVariant::value() const {return (ullong)toLLong();}
|
||||
template<> inline float PIVariant::value() const {return toFloat();}
|
||||
template<> inline double PIVariant::value() const {return toDouble();}
|
||||
template<> inline ldouble PIVariant::value() const {return toLDouble();}
|
||||
template<> inline complexf PIVariant::value() const {return toComplexF();}
|
||||
template<> inline complexd PIVariant::value() const {return toComplexD();}
|
||||
template<> inline complexld PIVariant::value() const {return toComplexLD();}
|
||||
template<> inline void* PIVariant::value() const {return (void*)toLLong();}
|
||||
template<> inline const char* PIVariant::value() const {return toString().data();}
|
||||
template<> inline PITime PIVariant::value() const {return toTime();}
|
||||
@@ -1027,6 +1079,9 @@ template<> inline PIVariant PIVariant::fromValue(const ullong & v) {return PIVar
|
||||
template<> inline PIVariant PIVariant::fromValue(const float & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const double & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const ldouble & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const complexf & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const complexd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const complexld & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIBitArray & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIByteArray & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIString & v) {return PIVariant(v);}
|
||||
@@ -1060,6 +1115,9 @@ template<> inline PIVariant::Type PIVariant::getType<ullong>() {return PIVariant
|
||||
template<> inline PIVariant::Type PIVariant::getType<float>() {return PIVariant::pivFloat;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<double>() {return PIVariant::pivDouble;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<ldouble>() {return PIVariant::pivLDouble;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<complexf>() {return PIVariant:: pivComplexf;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<complexd>() {return PIVariant:: pivComplexd;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<complexld>() {return PIVariant::pivComplexld;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIBitArray>() {return PIVariant::pivBitArray;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIByteArray>() {return PIVariant::pivByteArray;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIString>() {return PIVariant::pivString;}
|
||||
@@ -1093,6 +1151,9 @@ REGISTER_VARIANT(ullong)
|
||||
REGISTER_VARIANT(float)
|
||||
REGISTER_VARIANT(double)
|
||||
REGISTER_VARIANT(ldouble)
|
||||
REGISTER_VARIANT(complexf)
|
||||
REGISTER_VARIANT(complexd)
|
||||
REGISTER_VARIANT(complexld)
|
||||
REGISTER_VARIANT(PIBitArray)
|
||||
REGISTER_VARIANT(PIByteArray)
|
||||
REGISTER_VARIANT(PIString)
|
||||
|
||||
Reference in New Issue
Block a user