Compare commits
4 Commits
978e350722
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 34bc322b9b | |||
| 6c3c763934 | |||
| 4d841787fc | |||
| 790246afea |
@@ -6,7 +6,7 @@ endif()
|
|||||||
project(PIP)
|
project(PIP)
|
||||||
set(PIP_MAJOR 5)
|
set(PIP_MAJOR 5)
|
||||||
set(PIP_MINOR 5)
|
set(PIP_MINOR 5)
|
||||||
set(PIP_REVISION 1)
|
set(PIP_REVISION 3)
|
||||||
set(PIP_SUFFIX )
|
set(PIP_SUFFIX )
|
||||||
set(PIP_COMPANY SHS)
|
set(PIP_COMPANY SHS)
|
||||||
set(PIP_DOMAIN org.SHS)
|
set(PIP_DOMAIN org.SHS)
|
||||||
|
|||||||
BIN
lang/pip_ru.btf
BIN
lang/pip_ru.btf
Binary file not shown.
@@ -622,6 +622,39 @@
|
|||||||
<translation>Ошибка: Режим ReadWrite не поддерживается, используйте WriteOnly или ReadOnly</translation>
|
<translation>Ошибка: Режим ReadWrite не поддерживается, используйте WriteOnly или ReadOnly</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>PIUnitsMass</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_mass.cpp" line="35"/>
|
||||||
|
<source>g</source>
|
||||||
|
<translation>г</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_mass.cpp" line="37"/>
|
||||||
|
<source>℥</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_mass.cpp" line="36"/>
|
||||||
|
<source>lb</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_mass.cpp" line="25"/>
|
||||||
|
<source>gram</source>
|
||||||
|
<translation>грамм</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_mass.cpp" line="27"/>
|
||||||
|
<source>ounce</source>
|
||||||
|
<translation>унция</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_mass.cpp" line="26"/>
|
||||||
|
<source>pound</source>
|
||||||
|
<translation>фунт</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>PIUnitsTime</name>
|
<name>PIUnitsTime</name>
|
||||||
<message>
|
<message>
|
||||||
@@ -815,15 +848,75 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>PIUnitsDistance</name>
|
<name>PIUnitsDistance</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../libs/main/units/piunits_class_distance.cpp" line="33"/>
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="40"/>
|
||||||
|
<source>"</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="44"/>
|
||||||
|
<source>Å</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="39"/>
|
||||||
<source>m</source>
|
<source>m</source>
|
||||||
<translation>м</translation>
|
<translation>м</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="45"/>
|
||||||
|
<source>au</source>
|
||||||
|
<translation>а. е.</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="42"/>
|
||||||
|
<source>ft</source>
|
||||||
|
<translation>фут</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="43"/>
|
||||||
|
<source>yd</source>
|
||||||
|
<translation>ярд</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="27"/>
|
||||||
|
<source>mil</source>
|
||||||
|
<translation>мил</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="28"/>
|
||||||
|
<source>foot</source>
|
||||||
|
<translation>фут</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="26"/>
|
||||||
|
<source>inch</source>
|
||||||
|
<translation>дюйм</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="41"/>
|
||||||
|
<source>thou</source>
|
||||||
|
<translation>мил</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="29"/>
|
||||||
|
<source>yard</source>
|
||||||
|
<translation>ярд</translation>
|
||||||
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../libs/main/units/piunits_class_distance.cpp" line="25"/>
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="25"/>
|
||||||
<source>meter</source>
|
<source>meter</source>
|
||||||
<translation>метр</translation>
|
<translation>метр</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="30"/>
|
||||||
|
<source>angstrom</source>
|
||||||
|
<translation>ангстрем</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../libs/main/units/piunits_class_distance.cpp" line="31"/>
|
||||||
|
<source>astronomical unit</source>
|
||||||
|
<translation>астрономическая единица</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>PIUnitsPressure</name>
|
<name>PIUnitsPressure</name>
|
||||||
|
|||||||
58
libs/main/digest/pidigest_siphash_p.cpp
Normal file
58
libs/main/digest/pidigest_siphash_p.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Digest algorithms
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pidigest_siphash_p.h"
|
||||||
|
|
||||||
|
#include "3rd/SipHash/halfsiphash.h"
|
||||||
|
#include "3rd/SipHash/siphash.h"
|
||||||
|
#include "3rd/SipHash/vectors.h"
|
||||||
|
|
||||||
|
|
||||||
|
PIByteArray SipHash::siphash(const PIByteArray & in, const PIByteArray & key, int out_bytes) {
|
||||||
|
PIByteArray ret(out_bytes);
|
||||||
|
static PIByteArray empty_key(16, 0);
|
||||||
|
if (key.isEmpty())
|
||||||
|
::siphash(in.data(), in.size(), empty_key.data(), ret.data(), ret.size());
|
||||||
|
else {
|
||||||
|
if (key.size() >= 16)
|
||||||
|
::siphash(in.data(), in.size(), key.data(), ret.data(), ret.size());
|
||||||
|
else {
|
||||||
|
auto skey = key.resized(16);
|
||||||
|
::siphash(in.data(), in.size(), skey.data(), ret.data(), ret.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIByteArray SipHash::halfsiphash(const PIByteArray & in, const PIByteArray & key, int out_bytes) {
|
||||||
|
PIByteArray ret(out_bytes);
|
||||||
|
static PIByteArray empty_key(8, 0);
|
||||||
|
if (key.isEmpty())
|
||||||
|
::halfsiphash(in.data(), in.size(), empty_key.data(), ret.data(), ret.size());
|
||||||
|
else {
|
||||||
|
if (key.size() >= 8)
|
||||||
|
::halfsiphash(in.data(), in.size(), key.data(), ret.data(), ret.size());
|
||||||
|
else {
|
||||||
|
auto skey = key.resized(8);
|
||||||
|
::halfsiphash(in.data(), in.size(), skey.data(), ret.data(), ret.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
31
libs/main/digest/pidigest_siphash_p.h
Normal file
31
libs/main/digest/pidigest_siphash_p.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Digest algorithms
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef pidigest_siphash_h
|
||||||
|
#define pidigest_siphash_h
|
||||||
|
|
||||||
|
#include "pibytearray.h"
|
||||||
|
|
||||||
|
class SipHash {
|
||||||
|
public:
|
||||||
|
static PIByteArray siphash(const PIByteArray & in, const PIByteArray & key, int out_bytes);
|
||||||
|
static PIByteArray halfsiphash(const PIByteArray & in, const PIByteArray & key, int out_bytes);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#else
|
#else
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
# undef _WIN32_WINNT
|
||||||
|
# define _WIN32_WINNT 0x0600
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <setupapi.h>
|
# include <setupapi.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -206,7 +206,10 @@ PIString PIString::dtos(const double num, char format, int precision) {
|
|||||||
if (wr > 4) wr = 4;
|
if (wr > 4) wr = 4;
|
||||||
f[2 + wr] = format;
|
f[2 + wr] = format;
|
||||||
f[3 + wr] = 0;
|
f[3 + wr] = 0;
|
||||||
pisprintf(f, num);
|
char ch[256];
|
||||||
|
piZeroMemory(ch, 256);
|
||||||
|
snprintf(ch, 256, f, num);
|
||||||
|
return PIStringAscii(ch).replaceAll(',', '.');
|
||||||
}
|
}
|
||||||
#undef pisprintf
|
#undef pisprintf
|
||||||
|
|
||||||
|
|||||||
@@ -130,6 +130,18 @@ void PIVariant::setValueFromString(const PIString & v) {
|
|||||||
case PIVariant::pivLDouble: {
|
case PIVariant::pivLDouble: {
|
||||||
setValue(v.toLDouble());
|
setValue(v.toLDouble());
|
||||||
} break;
|
} 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: {
|
case PIVariant::pivTime: {
|
||||||
setValue(PITime::fromString(v));
|
setValue(PITime::fromString(v));
|
||||||
} break;
|
} break;
|
||||||
@@ -242,6 +254,7 @@ PIVariant::Type PIVariant::typeFromName(const PIString & tname) {
|
|||||||
if (s == "float") return PIVariant::pivFloat;
|
if (s == "float") return PIVariant::pivFloat;
|
||||||
if (s == "double" || s == "real") return PIVariant::pivDouble;
|
if (s == "double" || s == "real") return PIVariant::pivDouble;
|
||||||
if (s == "ldouble" || s == "longdouble") return PIVariant::pivLDouble;
|
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 == "complexd" || s == "complex<double>") return PIVariant::pivComplexd;
|
||||||
if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::pivComplexld;
|
if (s == "complexld" || s == "complex<ldouble>" || s == "complex<longdouble>") return PIVariant::pivComplexld;
|
||||||
if (s == "pibitarray" || s == "bitarray") return PIVariant::pivBitArray;
|
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<float>()) return PIVariant::pivFloat;
|
||||||
if (type_id == typeID<double>()) return PIVariant::pivDouble;
|
if (type_id == typeID<double>()) return PIVariant::pivDouble;
|
||||||
if (type_id == typeID<ldouble>()) return PIVariant::pivLDouble;
|
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<complexd>()) return PIVariant::pivComplexd;
|
||||||
if (type_id == typeID<complexld>()) return PIVariant::pivComplexld;
|
if (type_id == typeID<complexld>()) return PIVariant::pivComplexld;
|
||||||
if (type_id == typeID<PIBitArray>()) return PIVariant::pivBitArray;
|
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::pivFloat ): return typeID<float >();
|
||||||
case (PIVariant::pivDouble ): return typeID<double >();
|
case (PIVariant::pivDouble ): return typeID<double >();
|
||||||
case (PIVariant::pivLDouble ): return typeID<ldouble >();
|
case (PIVariant::pivLDouble ): return typeID<ldouble >();
|
||||||
|
case (PIVariant::pivComplexf ): return typeID<complexf >();
|
||||||
case (PIVariant::pivComplexd ): return typeID<complexd >();
|
case (PIVariant::pivComplexd ): return typeID<complexd >();
|
||||||
case (PIVariant::pivComplexld ): return typeID<complexld >();
|
case (PIVariant::pivComplexld ): return typeID<complexld >();
|
||||||
case (PIVariant::pivBitArray ): return typeID<PIBitArray >();
|
case (PIVariant::pivBitArray ): return typeID<PIBitArray >();
|
||||||
@@ -451,6 +466,7 @@ PIString PIVariant::typeName(PIVariant::Type type) {
|
|||||||
case PIVariant::pivFloat: return "Float";
|
case PIVariant::pivFloat: return "Float";
|
||||||
case PIVariant::pivDouble: return "Double";
|
case PIVariant::pivDouble: return "Double";
|
||||||
case PIVariant::pivLDouble: return "LDouble";
|
case PIVariant::pivLDouble: return "LDouble";
|
||||||
|
case PIVariant::pivComplexf: return "Complexf";
|
||||||
case PIVariant::pivComplexd: return "Complexd";
|
case PIVariant::pivComplexd: return "Complexd";
|
||||||
case PIVariant::pivComplexld: return "Complexld";
|
case PIVariant::pivComplexld: return "Complexld";
|
||||||
case PIVariant::pivBitArray: return "BitArray";
|
case PIVariant::pivBitArray: return "BitArray";
|
||||||
@@ -691,6 +707,21 @@ int PIVariant::toInt() const {
|
|||||||
ba >> r;
|
ba >> r;
|
||||||
return 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: {
|
case PIVariant::pivString: {
|
||||||
PIString r;
|
PIString r;
|
||||||
ba >> r;
|
ba >> r;
|
||||||
@@ -806,6 +837,21 @@ llong PIVariant::toLLong() const {
|
|||||||
ba >> r;
|
ba >> r;
|
||||||
return 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: {
|
case PIVariant::pivString: {
|
||||||
PIString r;
|
PIString r;
|
||||||
ba >> r;
|
ba >> r;
|
||||||
@@ -916,6 +962,21 @@ float PIVariant::toFloat() const {
|
|||||||
ba >> r;
|
ba >> r;
|
||||||
return 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: {
|
case PIVariant::pivString: {
|
||||||
PIString r;
|
PIString r;
|
||||||
ba >> r;
|
ba >> r;
|
||||||
@@ -1026,6 +1087,21 @@ double PIVariant::toDouble() const {
|
|||||||
ba >> r;
|
ba >> r;
|
||||||
return 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: {
|
case PIVariant::pivString: {
|
||||||
PIString r;
|
PIString r;
|
||||||
ba >> r;
|
ba >> r;
|
||||||
@@ -1136,6 +1212,21 @@ ldouble PIVariant::toLDouble() const {
|
|||||||
ba >> r;
|
ba >> r;
|
||||||
return 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: {
|
case PIVariant::pivString: {
|
||||||
PIString r;
|
PIString r;
|
||||||
ba >> 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
|
//! \~\brief
|
||||||
//! \~english Returns variant content as time
|
//! \~english Returns variant content as time
|
||||||
//! \~russian Возвращает содержимое как время
|
//! \~russian Возвращает содержимое как время
|
||||||
@@ -1418,6 +1599,21 @@ PIString PIVariant::toString() const {
|
|||||||
ba >> r;
|
ba >> r;
|
||||||
return PIString::fromNumber(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: {
|
case PIVariant::pivTime: {
|
||||||
PITime r;
|
PITime r;
|
||||||
ba >> r;
|
ba >> r;
|
||||||
@@ -1910,21 +2106,45 @@ PINetworkAddress PIVariant::toNetworkAddress() const {
|
|||||||
//! Для остальных типов возвращает пустой PIMathVectord.
|
//! Для остальных типов возвращает пустой PIMathVectord.
|
||||||
//!
|
//!
|
||||||
PIMathVectord PIVariant::toMathVector() const {
|
PIMathVectord PIVariant::toMathVector() const {
|
||||||
|
PIMathVectord ret;
|
||||||
PIByteArray ba(_content);
|
PIByteArray ba(_content);
|
||||||
if (_type == PIVariant::pivMathVector) {
|
if (_type == PIVariant::pivComplexf) {
|
||||||
PIMathVectord r;
|
complexf r;
|
||||||
ba >> 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) {
|
if (_type == PIVariant::pivPoint) {
|
||||||
PIPointd r;
|
PIPointd r;
|
||||||
ba >> r;
|
ba >> r;
|
||||||
PIMathVectord ret(2);
|
ret.resize(2);
|
||||||
ret[0] = r.x;
|
ret[0] = r.x;
|
||||||
ret[1] = r.y;
|
ret[1] = r.y;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return PIMathVectord();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ public:
|
|||||||
pivMathMatrix /** PIMathMatrix<double> */,
|
pivMathMatrix /** PIMathMatrix<double> */,
|
||||||
pivLine /** PILine<double> */,
|
pivLine /** PILine<double> */,
|
||||||
pivNetworkAddress /** PINetworkAddress */,
|
pivNetworkAddress /** PINetworkAddress */,
|
||||||
|
pivComplexf /** complexf */,
|
||||||
pivCustom /** \~english Custom \~russian Свой тип */ = 0xFF
|
pivCustom /** \~english Custom \~russian Свой тип */ = 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -327,6 +328,18 @@ public:
|
|||||||
//! \~russian Создает %PIVariant из вещественного числа.
|
//! \~russian Создает %PIVariant из вещественного числа.
|
||||||
PIVariant(const ldouble & v) { initType(v); }
|
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.
|
//! \~english Constructs %PIVariant from bit array.
|
||||||
//! \~russian Создает %PIVariant из массива битов.
|
//! \~russian Создает %PIVariant из массива битов.
|
||||||
PIVariant(const PIBitArray & v) { initType(v); }
|
PIVariant(const PIBitArray & v) { initType(v); }
|
||||||
@@ -456,6 +469,18 @@ public:
|
|||||||
//! \~russian Устанавливает значение и тип из вещественного числа
|
//! \~russian Устанавливает значение и тип из вещественного числа
|
||||||
void setValue(const ldouble & v) { initType(v); }
|
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
|
//! \~english Set variant content and type to bit array
|
||||||
//! \~russian Устанавливает значение и тип из массива битов
|
//! \~russian Устанавливает значение и тип из массива битов
|
||||||
void setValue(const PIBitArray & v) { initType(v); }
|
void setValue(const PIBitArray & v) { initType(v); }
|
||||||
@@ -545,6 +570,9 @@ public:
|
|||||||
float toFloat() const;
|
float toFloat() const;
|
||||||
double toDouble() const;
|
double toDouble() const;
|
||||||
ldouble toLDouble() const;
|
ldouble toLDouble() const;
|
||||||
|
complexf toComplexF() const;
|
||||||
|
complexd toComplexD() const;
|
||||||
|
complexld toComplexLD() const;
|
||||||
PITime toTime() const;
|
PITime toTime() const;
|
||||||
PIDate toDate() const;
|
PIDate toDate() const;
|
||||||
PIDateTime toDateTime() const;
|
PIDateTime toDateTime() const;
|
||||||
@@ -680,6 +708,27 @@ public:
|
|||||||
return *this;
|
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.
|
//! \~english Assign operator.
|
||||||
//! \~russian Оператор присваивания.
|
//! \~russian Оператор присваивания.
|
||||||
PIVariant & operator=(const PIBitArray & v) {
|
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 float PIVariant::value() const {return toFloat();}
|
||||||
template<> inline double PIVariant::value() const {return toDouble();}
|
template<> inline double PIVariant::value() const {return toDouble();}
|
||||||
template<> inline ldouble PIVariant::value() const {return toLDouble();}
|
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 void* PIVariant::value() const {return (void*)toLLong();}
|
||||||
template<> inline const char* PIVariant::value() const {return toString().data();}
|
template<> inline const char* PIVariant::value() const {return toString().data();}
|
||||||
template<> inline PITime PIVariant::value() const {return toTime();}
|
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 float & v) {return PIVariant(v);}
|
||||||
template<> inline PIVariant PIVariant::fromValue(const double & 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 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 PIBitArray & v) {return PIVariant(v);}
|
||||||
template<> inline PIVariant PIVariant::fromValue(const PIByteArray & 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);}
|
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<float>() {return PIVariant::pivFloat;}
|
||||||
template<> inline PIVariant::Type PIVariant::getType<double>() {return PIVariant::pivDouble;}
|
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<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<PIBitArray>() {return PIVariant::pivBitArray;}
|
||||||
template<> inline PIVariant::Type PIVariant::getType<PIByteArray>() {return PIVariant::pivByteArray;}
|
template<> inline PIVariant::Type PIVariant::getType<PIByteArray>() {return PIVariant::pivByteArray;}
|
||||||
template<> inline PIVariant::Type PIVariant::getType<PIString>() {return PIVariant::pivString;}
|
template<> inline PIVariant::Type PIVariant::getType<PIString>() {return PIVariant::pivString;}
|
||||||
@@ -1093,6 +1151,9 @@ REGISTER_VARIANT(ullong)
|
|||||||
REGISTER_VARIANT(float)
|
REGISTER_VARIANT(float)
|
||||||
REGISTER_VARIANT(double)
|
REGISTER_VARIANT(double)
|
||||||
REGISTER_VARIANT(ldouble)
|
REGISTER_VARIANT(ldouble)
|
||||||
|
REGISTER_VARIANT(complexf)
|
||||||
|
REGISTER_VARIANT(complexd)
|
||||||
|
REGISTER_VARIANT(complexld)
|
||||||
REGISTER_VARIANT(PIBitArray)
|
REGISTER_VARIANT(PIBitArray)
|
||||||
REGISTER_VARIANT(PIByteArray)
|
REGISTER_VARIANT(PIByteArray)
|
||||||
REGISTER_VARIANT(PIString)
|
REGISTER_VARIANT(PIString)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "piunits_class_angle.h"
|
#include "piunits_class_angle.h"
|
||||||
#include "piunits_class_distance.h"
|
#include "piunits_class_distance.h"
|
||||||
#include "piunits_class_information.h"
|
#include "piunits_class_information.h"
|
||||||
|
#include "piunits_class_mass.h"
|
||||||
#include "piunits_class_pressure.h"
|
#include "piunits_class_pressure.h"
|
||||||
#include "piunits_class_temperature.h"
|
#include "piunits_class_temperature.h"
|
||||||
#include "piunits_class_time.h"
|
#include "piunits_class_time.h"
|
||||||
|
|||||||
@@ -23,6 +23,12 @@
|
|||||||
PIString PIUnits::Class::Distance::name(int type) const {
|
PIString PIUnits::Class::Distance::name(int type) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Meter: return "meter"_tr("PIUnitsDistance");
|
case Meter: return "meter"_tr("PIUnitsDistance");
|
||||||
|
case Inch: return "inch"_tr("PIUnitsDistance");
|
||||||
|
case Mil: return "mil"_tr("PIUnitsDistance");
|
||||||
|
case Foot: return "foot"_tr("PIUnitsDistance");
|
||||||
|
case Yard: return "yard"_tr("PIUnitsDistance");
|
||||||
|
case Angstrom: return "angstrom"_tr("PIUnitsDistance");
|
||||||
|
case AstronomicalUnit: return "astronomical unit"_tr("PIUnitsDistance");
|
||||||
}
|
}
|
||||||
return Class::Internal::unknown;
|
return Class::Internal::unknown;
|
||||||
}
|
}
|
||||||
@@ -31,16 +37,42 @@ PIString PIUnits::Class::Distance::name(int type) const {
|
|||||||
PIString PIUnits::Class::Distance::unit(int type) const {
|
PIString PIUnits::Class::Distance::unit(int type) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Meter: return "m"_tr("PIUnitsDistance");
|
case Meter: return "m"_tr("PIUnitsDistance");
|
||||||
|
case Inch: return "\""_tr("PIUnitsDistance");
|
||||||
|
case Mil: return "thou"_tr("PIUnitsDistance");
|
||||||
|
case Foot: return "ft"_tr("PIUnitsDistance");
|
||||||
|
case Yard: return "yd"_tr("PIUnitsDistance");
|
||||||
|
case Angstrom: return "Å"_tr("PIUnitsDistance");
|
||||||
|
case AstronomicalUnit: return "au"_tr("PIUnitsDistance");
|
||||||
}
|
}
|
||||||
return Class::Internal::unknown;
|
return Class::Internal::unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double PIUnits::Class::Distance::convert(double v, int from, int to) const {
|
double PIUnits::Class::Distance::convert(double v, int from, int to) const {
|
||||||
switch (to) {
|
static constexpr double inch_to_m = 0.254;
|
||||||
case Meter: return v;
|
static constexpr double mil_to_m = 0.254 * 1E-3;
|
||||||
|
static constexpr double foot_to_m = 0.3048;
|
||||||
|
static constexpr double yard_to_m = 0.9144;
|
||||||
|
static constexpr double angstrom_to_m = 1E-10;
|
||||||
|
static constexpr double astronomical_unit_to_m = 149597870700.;
|
||||||
|
double m = v;
|
||||||
|
switch (from) {
|
||||||
|
case Inch: m *= inch_to_m; break;
|
||||||
|
case Mil: m *= mil_to_m; break;
|
||||||
|
case Foot: m *= foot_to_m; break;
|
||||||
|
case Yard: m *= yard_to_m; break;
|
||||||
|
case Angstrom: m *= angstrom_to_m; break;
|
||||||
|
case AstronomicalUnit: m *= astronomical_unit_to_m; break;
|
||||||
}
|
}
|
||||||
return v;
|
switch (to) {
|
||||||
|
case Inch: m /= inch_to_m; break;
|
||||||
|
case Mil: m /= mil_to_m; break;
|
||||||
|
case Foot: m /= foot_to_m; break;
|
||||||
|
case Yard: m /= yard_to_m; break;
|
||||||
|
case Angstrom: m /= angstrom_to_m; break;
|
||||||
|
case AstronomicalUnit: m /= astronomical_unit_to_m; break;
|
||||||
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -50,12 +82,12 @@ PIString PIUnits::Class::Distance::valueToString(double v, char format, int prec
|
|||||||
|
|
||||||
|
|
||||||
bool PIUnits::Class::Distance::supportPrefixes(int type) const {
|
bool PIUnits::Class::Distance::supportPrefixes(int type) const {
|
||||||
return true;
|
return type == Meter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIUnits::Class::Distance::supportPrefixesNon3(int type) const {
|
bool PIUnits::Class::Distance::supportPrefixesNon3(int type) const {
|
||||||
return true;
|
return type == Meter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,14 @@
|
|||||||
DECLARE_UNIT_CLASS_BEGIN(Distance, 0x600)
|
DECLARE_UNIT_CLASS_BEGIN(Distance, 0x600)
|
||||||
enum {
|
enum {
|
||||||
Meter = typeStart,
|
Meter = typeStart,
|
||||||
|
Inch,
|
||||||
|
Mil,
|
||||||
|
Foot,
|
||||||
|
Yard,
|
||||||
|
|
||||||
|
Angstrom,
|
||||||
|
AstronomicalUnit,
|
||||||
|
|
||||||
_LastType,
|
_LastType,
|
||||||
};
|
};
|
||||||
DECLARE_UNIT_CLASS_END(Distance)
|
DECLARE_UNIT_CLASS_END(Distance)
|
||||||
|
|||||||
81
libs/main/units/piunits_class_mass.cpp
Normal file
81
libs/main/units/piunits_class_mass.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Mass units
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "piunits_class_mass.h"
|
||||||
|
|
||||||
|
|
||||||
|
PIString PIUnits::Class::Mass::name(int type) const {
|
||||||
|
switch (type) {
|
||||||
|
case Gram: return "gram"_tr("PIUnitsMass");
|
||||||
|
case Pound: return "pound"_tr("PIUnitsMass");
|
||||||
|
case Ounce: return "ounce"_tr("PIUnitsMass");
|
||||||
|
}
|
||||||
|
return Class::Internal::unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString PIUnits::Class::Mass::unit(int type) const {
|
||||||
|
switch (type) {
|
||||||
|
case Gram: return "g"_tr("PIUnitsMass");
|
||||||
|
case Pound: return "lb"_tr("PIUnitsMass");
|
||||||
|
case Ounce: return "℥"_tr("PIUnitsMass");
|
||||||
|
}
|
||||||
|
return Class::Internal::unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double PIUnits::Class::Mass::convert(double v, int from, int to) const {
|
||||||
|
static constexpr double pound_to_g = 453.59237;
|
||||||
|
static constexpr double ounce_to_g = 28.349523125;
|
||||||
|
double g = v;
|
||||||
|
switch (from) {
|
||||||
|
case Pound: g *= pound_to_g; break;
|
||||||
|
case Ounce: g *= ounce_to_g; break;
|
||||||
|
}
|
||||||
|
switch (to) {
|
||||||
|
case Pound: g /= pound_to_g; break;
|
||||||
|
case Ounce: g /= ounce_to_g; break;
|
||||||
|
}
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString PIUnits::Class::Mass::valueToString(double v, char format, int prec) const {
|
||||||
|
return PIString::fromNumber(v, format, prec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIUnits::Class::Mass::supportPrefixes(int type) const {
|
||||||
|
return type == Gram;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIUnits::Class::Mass::supportPrefixesNon3(int type) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIUnits::Class::Mass::supportPrefixesGreater(int type) const {
|
||||||
|
return ClassBase::supportPrefixesGreater(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIUnits::Class::Mass::supportPrefixesSmaller(int type) const {
|
||||||
|
return ClassBase::supportPrefixesSmaller(type);
|
||||||
|
}
|
||||||
40
libs/main/units/piunits_class_mass.h
Normal file
40
libs/main/units/piunits_class_mass.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*! \file piunits_class_distance.h
|
||||||
|
* \ingroup Core
|
||||||
|
* \~\brief
|
||||||
|
* \~english Mass units
|
||||||
|
* \~russian Единицы измерения массы
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Mass units
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PIUNITS_CLASS_MASS_H
|
||||||
|
#define PIUNITS_CLASS_MASS_H
|
||||||
|
|
||||||
|
#include "piunits_base.h"
|
||||||
|
|
||||||
|
DECLARE_UNIT_CLASS_BEGIN(Mass, 0x700)
|
||||||
|
enum {
|
||||||
|
Gram = typeStart,
|
||||||
|
Pound,
|
||||||
|
Ounce,
|
||||||
|
_LastType,
|
||||||
|
};
|
||||||
|
DECLARE_UNIT_CLASS_END(Mass)
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user