61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
/*! \file piunits_value.h
|
|
* \ingroup Core
|
|
* \~\brief
|
|
* \~english Unit value
|
|
* \~russian Единица измерения
|
|
*/
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
Unit value
|
|
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_VALUE_H
|
|
#define PIUNITS_VALUE_H
|
|
|
|
#include "piunits_base.h"
|
|
|
|
|
|
namespace PIUnits {
|
|
|
|
class PIP_EXPORT Value {
|
|
public:
|
|
Value(double v = 0., int t = Class::Invalid);
|
|
|
|
bool isValid() const { return m_type >= 0 && m_class; }
|
|
bool isNotValid() const { return m_type < 0 || !m_class; }
|
|
|
|
double value() const { return m_value; }
|
|
PIString toString(char format = 'g', int prec = 5) const;
|
|
|
|
bool convert(int type_to);
|
|
Value converted(int type_to);
|
|
|
|
private:
|
|
double m_value = 0.;
|
|
int m_type = -1;
|
|
Class::Internal::ClassBase * m_class = nullptr;
|
|
};
|
|
|
|
}; // namespace PIUnits
|
|
|
|
inline PICout operator<<(PICout s, const PIUnits::Value & v) {
|
|
s << v.toString();
|
|
return s;
|
|
}
|
|
|
|
#endif
|