add miss files, add PIUnits::Distance and PIUnits::Mass
This commit is contained in:
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
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "piunits_class_angle.h"
|
||||
#include "piunits_class_distance.h"
|
||||
#include "piunits_class_information.h"
|
||||
#include "piunits_class_mass.h"
|
||||
#include "piunits_class_pressure.h"
|
||||
#include "piunits_class_temperature.h"
|
||||
#include "piunits_class_time.h"
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
PIString PIUnits::Class::Distance::name(int type) const {
|
||||
switch (type) {
|
||||
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;
|
||||
}
|
||||
@@ -31,16 +37,42 @@ PIString PIUnits::Class::Distance::name(int type) const {
|
||||
PIString PIUnits::Class::Distance::unit(int type) const {
|
||||
switch (type) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
double PIUnits::Class::Distance::convert(double v, int from, int to) const {
|
||||
switch (to) {
|
||||
case Meter: return v;
|
||||
static constexpr double inch_to_m = 0.254;
|
||||
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 {
|
||||
return true;
|
||||
return type == Meter;
|
||||
}
|
||||
|
||||
|
||||
bool PIUnits::Class::Distance::supportPrefixesNon3(int type) const {
|
||||
return true;
|
||||
return type == Meter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,14 @@
|
||||
DECLARE_UNIT_CLASS_BEGIN(Distance, 0x600)
|
||||
enum {
|
||||
Meter = typeStart,
|
||||
Inch,
|
||||
Mil,
|
||||
Foot,
|
||||
Yard,
|
||||
|
||||
Angstrom,
|
||||
AstronomicalUnit,
|
||||
|
||||
_LastType,
|
||||
};
|
||||
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