add doxygen via opencode
This commit is contained in:
@@ -23,82 +23,171 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//! \~english Units base classes
|
||||
//! \~russian Базовые классы единиц измерения
|
||||
//! \defgroup Units Units
|
||||
//! \~\brief
|
||||
//! \~english Unit conversions
|
||||
//! \~russian Преобразование единиц измерения
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english \section cmake_module_Units Building with CMake
|
||||
//! \~russian \section cmake_module_Units Сборка с использованием CMake
|
||||
//!
|
||||
//! \~\code
|
||||
//! find_package(PIP REQUIRED)
|
||||
//! target_link_libraries([target] PIP)
|
||||
//! \endcode
|
||||
//!
|
||||
//! \~english \par Common
|
||||
//! \~russian \par Общее
|
||||
//!
|
||||
//! \~english
|
||||
//! These files provides unit conversion framework.
|
||||
//!
|
||||
//! \~russian
|
||||
//! Эти файлы обеспечивают фреймворк преобразования единиц.
|
||||
//!
|
||||
//! \~\authors
|
||||
//! \~english
|
||||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||
//! \~russian
|
||||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||
//! Андрей Бычков work.a.b@yandex.ru;
|
||||
//!
|
||||
|
||||
#ifndef PIUNITS_BASE_H
|
||||
#define PIUNITS_BASE_H
|
||||
|
||||
#include "pitranslator.h"
|
||||
|
||||
#define DECLARE_UNIT_CLASS_BEGIN(Name, StartIndex) \
|
||||
namespace PIUnits { \
|
||||
namespace Class { \
|
||||
class PIP_EXPORT Name \
|
||||
: public Internal::ClassBase \
|
||||
, public Internal::Registrator<Name> { \
|
||||
private: \
|
||||
friend class Internal::Registrator<Name>; \
|
||||
constexpr static int typeStart = StartIndex; \
|
||||
PIString name(int type) const override; \
|
||||
PIString unit(int type) const override; \
|
||||
PIString valueToString(double v, char format, int prec) const override; \
|
||||
double convert(double v, int from, int to) const override; \
|
||||
bool supportPrefixes(int type) const override; \
|
||||
bool supportPrefixesNon3(int type) const override; \
|
||||
bool supportPrefixesGreater(int type) const override; \
|
||||
bool supportPrefixesSmaller(int type) const override; \
|
||||
\
|
||||
public: \
|
||||
PIString className() const override { \
|
||||
return piTr(#Name, "PIUnits"); \
|
||||
} \
|
||||
uint classID() const override { \
|
||||
static uint ret = PIStringAscii(#Name).hash(); \
|
||||
return ret; \
|
||||
}
|
||||
//! \~english Macro to declare unit class beginning
|
||||
//! \~russian Макрос для объявления начала класса единиц
|
||||
#define DECLARE_UNIT_CLASS_BEGIN(Name, StartIndex) \
|
||||
namespace PIUnits { \
|
||||
namespace Class { \
|
||||
class PIP_EXPORT Name \
|
||||
: public Internal::ClassBase \
|
||||
, public Internal::Registrator<Name> { \
|
||||
private: \
|
||||
friend class Internal::Registrator<Name>; \
|
||||
constexpr static int typeStart = StartIndex; \
|
||||
PIString name(int type) const override; \
|
||||
PIString unit(int type) const override; \
|
||||
PIString valueToString(double v, char format, int prec) const override; \
|
||||
double convert(double v, int from, int to) const override; \
|
||||
bool supportPrefixes(int type) const override; \
|
||||
bool supportPrefixesNon3(int type) const override; \
|
||||
bool supportPrefixesGreater(int type) const override; \
|
||||
bool supportPrefixesSmaller(int type) const override; \
|
||||
\
|
||||
public: \
|
||||
PIString className() const override { return piTr(#Name, "PIUnits"); } \
|
||||
uint classID() const override { \
|
||||
static uint ret = PIStringAscii(#Name).hash(); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
#define DECLARE_UNIT_CLASS_END(Name) \
|
||||
} \
|
||||
; \
|
||||
} \
|
||||
} \
|
||||
STATIC_INITIALIZER_BEGIN \
|
||||
PIUnits::Class::Name::registerSelf(); \
|
||||
STATIC_INITIALIZER_END
|
||||
//! \~english Macro to declare unit class end
|
||||
//! \~russian Макрос для объявления конца класса единиц
|
||||
#define DECLARE_UNIT_CLASS_END(Name) \
|
||||
} \
|
||||
; \
|
||||
} \
|
||||
} \
|
||||
STATIC_INITIALIZER_BEGIN \
|
||||
PIUnits::Class::Name::registerSelf(); \
|
||||
STATIC_INITIALIZER_END
|
||||
|
||||
namespace PIUnits {
|
||||
|
||||
//! \~english Get class name for type
|
||||
//! \~russian Получить имя класса для типа
|
||||
PIP_EXPORT PIString className(int type);
|
||||
|
||||
//! \~english Get unit name for type
|
||||
//! \~russian Получить имя единицы для типа
|
||||
PIP_EXPORT PIString name(int type);
|
||||
|
||||
//! \~english Get unit symbol for type
|
||||
//! \~russian Получить символ единицы для типа
|
||||
PIP_EXPORT PIString unit(int type);
|
||||
|
||||
namespace Class {
|
||||
|
||||
//! \~english Invalid type marker
|
||||
//! \~russian Маркер недопустимого типа
|
||||
enum {
|
||||
Invalid = -1
|
||||
};
|
||||
|
||||
//! \~english Internal namespace for unit classes implementation
|
||||
//! \~russian Внутреннее пространство имен для реализации классов единиц
|
||||
class PIP_EXPORT Internal {
|
||||
public:
|
||||
//! \~english Base class for all unit classes
|
||||
//! \~russian Базовый класс для всех классов единиц
|
||||
class PIP_EXPORT ClassBase {
|
||||
public:
|
||||
//! \~english Get class ID
|
||||
//! \~russian Получить ID класса
|
||||
virtual uint classID() const = 0;
|
||||
|
||||
//! \~english Get class name
|
||||
//! \~russian Получить имя класса
|
||||
virtual PIString className() const = 0;
|
||||
|
||||
//! \~english Get name for unit type
|
||||
//! \~russian Получить имя для типа единицы
|
||||
virtual PIString name(int type) const = 0;
|
||||
|
||||
//! \~english Get unit symbol for type
|
||||
//! \~russian Получить символ единицы для типа
|
||||
virtual PIString unit(int type) const = 0;
|
||||
|
||||
//! \~english Convert value to string
|
||||
//! \~russian Преобразовать значение в строку
|
||||
virtual PIString valueToString(double v, char format = 'g', int prec = 5) const = 0;
|
||||
|
||||
//! \~english Convert value between units
|
||||
//! \~russian Преобразовать значение между единицами
|
||||
virtual double convert(double v, int from, int to) const = 0;
|
||||
|
||||
//! \~english Check if prefixes are supported
|
||||
//! \~russian Проверить поддерживаются ли префиксы
|
||||
virtual bool supportPrefixes(int type) const { return true; }
|
||||
|
||||
//! \~english Check if non-3 prefixes are supported
|
||||
//! \~russian Проверить поддерживаются ли не-3 префиксы
|
||||
virtual bool supportPrefixesNon3(int type) const { return false; }
|
||||
|
||||
//! \~english Check if greater prefixes are supported
|
||||
//! \~russian Проверить поддерживаются ли большие префиксы
|
||||
virtual bool supportPrefixesGreater(int type) const { return true; }
|
||||
|
||||
//! \~english Check if smaller prefixes are supported
|
||||
//! \~russian Проверить поддерживаются ли меньшие префиксы
|
||||
virtual bool supportPrefixesSmaller(int type) const { return true; }
|
||||
|
||||
//! \~english Get all available types
|
||||
//! \~russian Получить все доступные типы
|
||||
const PIVector<int> & allTypes() const { return types; }
|
||||
|
||||
protected:
|
||||
//! \~english List of types
|
||||
//! \~russian Список типов
|
||||
PIVector<int> types;
|
||||
};
|
||||
|
||||
//! \~english Template for self-registration of unit classes
|
||||
//! \~russian Шаблон для саморегистрации классов единиц
|
||||
template<typename P>
|
||||
class Registrator {
|
||||
public:
|
||||
//! \~english Register unit class
|
||||
//! \~russian Зарегистрировать класс единиц
|
||||
static void registerSelf() {
|
||||
auto * uc = new P();
|
||||
for (int t = P::typeStart; t < P::_LastType; ++t) {
|
||||
@@ -108,14 +197,25 @@ public:
|
||||
if (!Internal::allTypeClasses.contains(uc)) Internal::allTypeClasses << uc;
|
||||
}
|
||||
};
|
||||
|
||||
//! \~english Map of type to class instance
|
||||
//! \~russian Карта типа к экземпляру класса
|
||||
static PIMap<int, ClassBase *> typeClasses;
|
||||
|
||||
//! \~english List of all registered classes
|
||||
//! \~russian Список всех зарегистрированных классов
|
||||
static PIVector<ClassBase *> allTypeClasses;
|
||||
|
||||
//! \~english Unknown name placeholder
|
||||
//! \~russian Заполнитель для неизвестного имени
|
||||
static const PIString unknown;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Class
|
||||
|
||||
//! \~english Get all registered unit classes
|
||||
//! \~russian Получить все зарегистрированные классы единиц
|
||||
PIP_EXPORT PIVector<Class::Internal::ClassBase *> allClasses();
|
||||
|
||||
} // namespace PIUnits
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
/*! \file piunits_prefix.h
|
||||
* \ingroup Core
|
||||
* \~\brief
|
||||
* \~english Unit prefixes
|
||||
* \~russian Префиксы единиц измерения
|
||||
*/
|
||||
//! \~english Unit prefixes
|
||||
//! \~russian Префиксы единиц измерения
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Unit prefix
|
||||
@@ -30,41 +26,59 @@
|
||||
|
||||
namespace PIUnits {
|
||||
|
||||
//! \~english Unit prefix class
|
||||
//! \~russian Класс префикса единиц
|
||||
class PIP_EXPORT Prefix {
|
||||
friend class Value;
|
||||
|
||||
public:
|
||||
//! \~english Prefix values
|
||||
//! \~russian Значения префиксов
|
||||
enum {
|
||||
None,
|
||||
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
|
||||
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
|
||||
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:
|
||||
@@ -73,6 +87,8 @@ private:
|
||||
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;
|
||||
@@ -81,7 +97,12 @@ private:
|
||||
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;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
/*! \file piunits_value.h
|
||||
* \ingroup Core
|
||||
* \~\brief
|
||||
* \~english Unit value
|
||||
* \~russian Единица измерения
|
||||
*/
|
||||
//! \~english Unit value class
|
||||
//! \~russian Класс значения единицы
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Unit value
|
||||
@@ -31,27 +27,67 @@
|
||||
|
||||
namespace PIUnits {
|
||||
|
||||
//! \~english Unit value representation
|
||||
//! \~russian Представление значения единицы
|
||||
class PIP_EXPORT Value {
|
||||
public:
|
||||
//! \~english Constructor
|
||||
//! \~russian Конструктор
|
||||
//! \param v Value
|
||||
//! \param t Unit type
|
||||
Value(double v = 0., int t = Class::Invalid);
|
||||
|
||||
//! \~english Check if value is valid
|
||||
//! \~russian Проверить значение на корректность
|
||||
//! \return true if valid
|
||||
bool isValid() const { return m_type >= 0 && m_class; }
|
||||
|
||||
//! \~english Check if value is not valid
|
||||
//! \~russian Проверить значение на некорректность
|
||||
//! \return true if not valid
|
||||
bool isNotValid() const { return m_type < 0 || !m_class; }
|
||||
|
||||
//! \~english Get raw value
|
||||
//! \~russian Получить сырое значение
|
||||
double value() const { return m_value; }
|
||||
|
||||
//! \~english Convert to string
|
||||
//! \~russian Преобразовать в строку
|
||||
//! \param format Format specifier
|
||||
//! \param prec Precision
|
||||
//! \return String representation
|
||||
PIString toString(char format = 'g', int prec = 5) const;
|
||||
|
||||
//! \~english Convert to different unit type
|
||||
//! \~russian Преобразовать в другой тип единицы
|
||||
//! \param type_to Target unit type
|
||||
//! \return true if successful
|
||||
bool convert(int type_to);
|
||||
|
||||
//! \~english Get converted value
|
||||
//! \~russian Получить преобразованное значение
|
||||
//! \param type_to Target unit type
|
||||
//! \return Converted value
|
||||
Value converted(int type_to);
|
||||
|
||||
private:
|
||||
double m_value = 0.;
|
||||
int m_type = -1;
|
||||
Class::Internal::ClassBase * m_class = nullptr;
|
||||
//! \~english Numeric value
|
||||
//! \~russian Числовое значение
|
||||
double m_value;
|
||||
|
||||
//! \~english Unit type
|
||||
//! \~russian Тип единицы
|
||||
int m_type;
|
||||
|
||||
//! \~english Class pointer
|
||||
//! \~russian Указатель на класс
|
||||
Class::Internal::ClassBase * m_class;
|
||||
};
|
||||
|
||||
}; // namespace PIUnits
|
||||
|
||||
//! \~english Output stream operator
|
||||
//! \~russian Оператор вывода в поток
|
||||
inline PICout operator<<(PICout s, const PIUnits::Value & v) {
|
||||
s << v.toString();
|
||||
return s;
|
||||
|
||||
Reference in New Issue
Block a user