117 lines
3.7 KiB
C++
117 lines
3.7 KiB
C++
//! \~english Unit prefixes
|
||
//! \~russian Префиксы единиц измерения
|
||
/*
|
||
PIP - Platform Independent Primitives
|
||
Unit prefix
|
||
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_PREFIX_H
|
||
#define PIUNITS_PREFIX_H
|
||
|
||
#include "pistring.h"
|
||
|
||
namespace PIUnits {
|
||
|
||
//! \~english Unit prefix class
|
||
//! \~russian Класс префикса единиц
|
||
class PIP_EXPORT Prefix {
|
||
friend class Value;
|
||
|
||
public:
|
||
//! \~english Prefix values
|
||
//! \~russian Значения префиксов
|
||
enum {
|
||
None, //!< No prefix
|
||
|
||
Deca = 0x100, //!< da 10^1 10
|
||
Hecto, //!< h 10^2 100
|
||
Kilo, //!< k 10^3 1000
|
||
Mega, //!< M 10^6 1000000
|
||
Giga, //!< G 10^9 1000000000
|
||
Tera, //!< T 10^12 1000000000000
|
||
Peta, //!< P 10^15 1000000000000000
|
||
Exa, //!< E 10^18 1000000000000000000
|
||
Zetta, //!< Z 10^21 1000000000000000000000
|
||
Yotta, //!< Y 10^24 1000000000000000000000000
|
||
Ronna, //!< R 10^27 1000000000000000000000000000
|
||
Quetta, //!< Q 10^30 1000000000000000000000000000000
|
||
|
||
Deci = 0x200, //!< d 10^−1 0.1
|
||
Centi, //!< c 10^−2 0.01
|
||
Milli, //!< m 10^−3 0.001
|
||
Micro, //!< μ 10^−6 0.000001
|
||
Nano, //!< n 10^−9 0.000000001
|
||
Pico, //!< p 10^−12 0.000000000001
|
||
Femto, //!< f 10^−15 0.000000000000001
|
||
Atto, //!< a 10^−18 0.000000000000000001
|
||
Zepto, //!< z 10^−21 0.000000000000000000001
|
||
Yocto, //!< y 10^−24 0.000000000000000000000001
|
||
Ronto, //!< r 10^−27 0.000000000000000000000000001
|
||
};
|
||
|
||
//! \~english Get prefix name
|
||
//! \~russian Получить имя префикса
|
||
//! \param prefix Prefix value
|
||
//! \return Prefix name
|
||
static PIString name(int prefix);
|
||
|
||
//! \~english Get prefix symbol
|
||
//! \~russian Получить символ префикса
|
||
//! \param prefix Prefix value
|
||
//! \return Prefix symbol
|
||
static PIString prefix(int prefix);
|
||
|
||
//! \~english Get multiplier for prefix
|
||
//! \~russian Получить множитель для префикса
|
||
//! \param prefix Prefix value
|
||
//! \return Multiplier value
|
||
static double multiplier(int prefix);
|
||
|
||
private:
|
||
Prefix();
|
||
NO_COPY_CLASS(Prefix);
|
||
static Prefix & instance();
|
||
static PIString valueToString(double v, void * type_class, int type, char format = 'g', int prec = 5);
|
||
|
||
//! \~english Prefix data structure
|
||
//! \~russian Структура данных префикса
|
||
struct P {
|
||
PIString name;
|
||
PIString prefix;
|
||
int pow;
|
||
double divider;
|
||
bool non3;
|
||
};
|
||
|
||
//! \~english Get prefix by value
|
||
//! \~russian Получить префикс по значению
|
||
const P getPrefix(int p) const;
|
||
|
||
//! \~english Get prefix for value
|
||
//! \~russian Получить префикс для значения
|
||
const P getPrefixForValue(double v, bool use_non3, bool use_greater, bool use_smaller) const;
|
||
|
||
PIMap<int, P> prefixes;
|
||
PIMap<int, P *> prefixes_by_pow;
|
||
P def_prefix;
|
||
};
|
||
|
||
} // namespace PIUnits
|
||
|
||
|
||
#endif
|