Base: fix/ignore some clang-tidy warnings
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
# ifdef FC_OS_WIN32
|
||||
# define _USE_MATH_DEFINES
|
||||
# endif // FC_OS_WIN32
|
||||
# include <array>
|
||||
#endif
|
||||
|
||||
#include "Quantity.h"
|
||||
@@ -72,50 +73,44 @@ QuantityFormat::QuantityFormat(QuantityFormat::NumberFormat format, int decimals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Quantity::Quantity()
|
||||
: _Value{0.0}
|
||||
{
|
||||
}
|
||||
|
||||
Quantity::Quantity(const Quantity& that)
|
||||
: _Value{that._Value}
|
||||
, _Unit{that._Unit}
|
||||
: myValue{0.0}
|
||||
{
|
||||
}
|
||||
|
||||
Quantity::Quantity(double value, const Unit& unit)
|
||||
: _Value{value}
|
||||
, _Unit{unit}
|
||||
: myValue{value}
|
||||
, myUnit{unit}
|
||||
{
|
||||
}
|
||||
|
||||
Quantity::Quantity(double value, const QString& unit)
|
||||
: _Value{0.0}
|
||||
: myValue{0.0}
|
||||
{
|
||||
if (unit.isEmpty()) {
|
||||
this->_Value = value;
|
||||
this->_Unit = Unit();
|
||||
this->myValue = value;
|
||||
this->myUnit = Unit();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
auto tmpQty = parse(unit);
|
||||
this->_Unit = tmpQty.getUnit();
|
||||
this->_Value = value * tmpQty.getValue();
|
||||
this->myUnit = tmpQty.getUnit();
|
||||
this->myValue = value * tmpQty.getValue();
|
||||
}
|
||||
catch (const Base::ParserError&) {
|
||||
this->_Value = 0.0;
|
||||
this->_Unit = Unit();
|
||||
this->myValue = 0.0;
|
||||
this->myUnit = Unit();
|
||||
}
|
||||
}
|
||||
|
||||
double Quantity::getValueAs(const Quantity& other)const
|
||||
{
|
||||
return _Value / other.getValue();
|
||||
return myValue / other.getValue();
|
||||
}
|
||||
|
||||
bool Quantity::operator ==(const Quantity& that) const
|
||||
{
|
||||
return (this->_Value == that._Value) && (this->_Unit == that._Unit);
|
||||
return (this->myValue == that.myValue) && (this->myUnit == that.myUnit);
|
||||
}
|
||||
|
||||
bool Quantity::operator !=(const Quantity& that) const
|
||||
@@ -125,131 +120,123 @@ bool Quantity::operator !=(const Quantity& that) const
|
||||
|
||||
bool Quantity::operator <(const Quantity& that) const
|
||||
{
|
||||
if (this->_Unit != that._Unit) {
|
||||
if (this->myUnit != that.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator <(): quantities need to have same unit to compare");
|
||||
}
|
||||
|
||||
return (this->_Value < that._Value) ;
|
||||
return (this->myValue < that.myValue) ;
|
||||
}
|
||||
|
||||
bool Quantity::operator >(const Quantity& that) const
|
||||
{
|
||||
if (this->_Unit != that._Unit) {
|
||||
if (this->myUnit != that.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator >(): quantities need to have same unit to compare");
|
||||
}
|
||||
|
||||
return (this->_Value > that._Value) ;
|
||||
return (this->myValue > that.myValue) ;
|
||||
}
|
||||
|
||||
bool Quantity::operator <=(const Quantity& that) const
|
||||
{
|
||||
if (this->_Unit != that._Unit) {
|
||||
if (this->myUnit != that.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator <=(): quantities need to have same unit to compare");
|
||||
}
|
||||
|
||||
return (this->_Value <= that._Value) ;
|
||||
return (this->myValue <= that.myValue) ;
|
||||
}
|
||||
|
||||
bool Quantity::operator >=(const Quantity& that) const
|
||||
{
|
||||
if (this->_Unit != that._Unit) {
|
||||
if (this->myUnit != that.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator >=(): quantities need to have same unit to compare");
|
||||
}
|
||||
|
||||
return (this->_Value >= that._Value) ;
|
||||
return (this->myValue >= that.myValue) ;
|
||||
}
|
||||
|
||||
Quantity Quantity::operator *(const Quantity& other) const
|
||||
{
|
||||
return Quantity(this->_Value * other._Value, this->_Unit * other._Unit);
|
||||
return Quantity(this->myValue * other.myValue, this->myUnit * other.myUnit);
|
||||
}
|
||||
|
||||
Quantity Quantity::operator *(double factor) const
|
||||
{
|
||||
return Quantity(this->_Value * factor, this->_Unit);
|
||||
return Quantity(this->myValue * factor, this->myUnit);
|
||||
}
|
||||
|
||||
Quantity Quantity::operator /(const Quantity& other) const
|
||||
{
|
||||
return Quantity(this->_Value / other._Value, this->_Unit / other._Unit);
|
||||
return Quantity(this->myValue / other.myValue, this->myUnit / other.myUnit);
|
||||
}
|
||||
|
||||
Quantity Quantity::operator /(double factor) const
|
||||
{
|
||||
return Quantity(this->_Value / factor, this->_Unit);
|
||||
return Quantity(this->myValue / factor, this->myUnit);
|
||||
}
|
||||
|
||||
Quantity Quantity::pow(const Quantity& other) const
|
||||
{
|
||||
if (!other._Unit.isEmpty()) {
|
||||
if (!other.myUnit.isEmpty()) {
|
||||
throw Base::UnitsMismatchError("Quantity::pow(): exponent must not have a unit");
|
||||
}
|
||||
|
||||
return Quantity(
|
||||
std::pow(this->_Value, other._Value),
|
||||
this->_Unit.pow(static_cast<signed char>(other._Value))
|
||||
std::pow(this->myValue, other.myValue),
|
||||
this->myUnit.pow(static_cast<signed char>(other.myValue))
|
||||
);
|
||||
}
|
||||
|
||||
Quantity Quantity::pow(double exp) const
|
||||
{
|
||||
return Quantity(
|
||||
std::pow(this->_Value, exp),
|
||||
this->_Unit.pow(exp)
|
||||
std::pow(this->myValue, exp),
|
||||
this->myUnit.pow(exp)
|
||||
);
|
||||
}
|
||||
|
||||
Quantity Quantity::operator +(const Quantity& other) const
|
||||
{
|
||||
if (this->_Unit != other._Unit) {
|
||||
if (this->myUnit != other.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator +(): Unit mismatch in plus operation");
|
||||
}
|
||||
|
||||
return Quantity(this->_Value + other._Value, this->_Unit);
|
||||
return Quantity(this->myValue + other.myValue, this->myUnit);
|
||||
}
|
||||
|
||||
Quantity& Quantity::operator +=(const Quantity& other)
|
||||
{
|
||||
if (this->_Unit != other._Unit) {
|
||||
if (this->myUnit != other.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator +=(): Unit mismatch in plus operation");
|
||||
}
|
||||
|
||||
_Value += other._Value;
|
||||
myValue += other.myValue;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quantity Quantity::operator -(const Quantity& other) const
|
||||
{
|
||||
if (this->_Unit != other._Unit) {
|
||||
if (this->myUnit != other.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator -(): Unit mismatch in minus operation");
|
||||
}
|
||||
|
||||
return Quantity(this->_Value - other._Value,this->_Unit);
|
||||
return Quantity(this->myValue - other.myValue,this->myUnit);
|
||||
}
|
||||
|
||||
Quantity& Quantity::operator -=(const Quantity& other)
|
||||
{
|
||||
if (this->_Unit != other._Unit) {
|
||||
if (this->myUnit != other.myUnit) {
|
||||
throw Base::UnitsMismatchError("Quantity::operator -=(): Unit mismatch in minus operation");
|
||||
}
|
||||
|
||||
_Value -= other._Value;
|
||||
myValue -= other.myValue;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quantity Quantity::operator -() const
|
||||
{
|
||||
return Quantity(-(this->_Value), this->_Unit);
|
||||
}
|
||||
|
||||
Quantity& Quantity::operator = (const Quantity &New)
|
||||
{
|
||||
this->_Value = New._Value;
|
||||
this->_Unit = New._Unit;
|
||||
this->_Format = New._Format;
|
||||
return *this;
|
||||
return Quantity(-(this->myValue), this->myUnit);
|
||||
}
|
||||
|
||||
QString Quantity::getUserString(double& factor, QString& unitString) const
|
||||
@@ -265,13 +252,13 @@ QString Quantity::getUserString(UnitsSchema* schema, double &factor, QString &un
|
||||
QString Quantity::getSafeUserString() const
|
||||
{
|
||||
auto retString = getUserString();
|
||||
if(Q_LIKELY(this->_Value != 0))
|
||||
if(Q_LIKELY(this->myValue != 0))
|
||||
{
|
||||
auto feedbackQty = parse(retString);
|
||||
auto feedbackVal = feedbackQty.getValue();
|
||||
if (feedbackVal == 0) {
|
||||
retString = QStringLiteral("%1 %2")
|
||||
.arg(this->_Value)
|
||||
.arg(this->myValue)
|
||||
.arg(this->getUnit().getString());
|
||||
}
|
||||
}
|
||||
@@ -281,24 +268,24 @@ QString Quantity::getSafeUserString() const
|
||||
/// true if it has a number without a unit
|
||||
bool Quantity::isDimensionless() const
|
||||
{
|
||||
return isValid() && _Unit.isEmpty();
|
||||
return isValid() && myUnit.isEmpty();
|
||||
}
|
||||
|
||||
// true if it has a number and a valid unit
|
||||
bool Quantity::isQuantity() const
|
||||
{
|
||||
return isValid() && !_Unit.isEmpty();
|
||||
return isValid() && !myUnit.isEmpty();
|
||||
}
|
||||
|
||||
// true if it has a number with or without a unit
|
||||
bool Quantity::isValid() const
|
||||
{
|
||||
return !boost::math::isnan(_Value);
|
||||
return !boost::math::isnan(myValue);
|
||||
}
|
||||
|
||||
void Quantity::setInvalid()
|
||||
{
|
||||
_Value = std::numeric_limits<double>::quiet_NaN();
|
||||
myValue = std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
// === Predefined types =====================================================
|
||||
@@ -457,31 +444,39 @@ const Quantity Quantity::Gon (360.0/400.0 ,Unit(0,0,0,0,0,0,0,1))
|
||||
|
||||
// include the Scanner and the Parser for the 'Quantity's
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
Quantity QuantResult;
|
||||
|
||||
/* helper function for tuning number strings with groups in a locale agnostic way... */
|
||||
double num_change(char* yytext,char dez_delim,char grp_delim)
|
||||
// NOLINTBEGIN
|
||||
double num_change(char* yytext, char dez_delim, char grp_delim)
|
||||
{
|
||||
double ret_val;
|
||||
char temp[40];
|
||||
int i = 0;
|
||||
for (char* c=yytext;*c!='\0';c++) {
|
||||
double ret_val{};
|
||||
const int num = 40;
|
||||
std::array<char, num> temp{};
|
||||
int iter = 0;
|
||||
for (char* ch = yytext; *ch != '\0'; ch++) {
|
||||
// skip group delimiter
|
||||
if (*c==grp_delim) continue;
|
||||
if (*ch == grp_delim)
|
||||
continue;
|
||||
// check for a dez delimiter other then dot
|
||||
if (*c==dez_delim && dez_delim !='.')
|
||||
temp[i++] = '.';
|
||||
else
|
||||
temp[i++] = *c;
|
||||
if (*ch == dez_delim && dez_delim != '.') {
|
||||
temp[iter++] = '.';
|
||||
}
|
||||
else {
|
||||
temp[iter++] = *ch;
|
||||
}
|
||||
// check buffer overflow
|
||||
if (i>39)
|
||||
if (iter >= num)
|
||||
return 0.0;
|
||||
}
|
||||
temp[i] = '\0';
|
||||
|
||||
ret_val = atof( temp );
|
||||
temp[iter] = '\0';
|
||||
|
||||
ret_val = atof(temp.data());
|
||||
return ret_val;
|
||||
}
|
||||
// NOLINTEND
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
@@ -511,16 +506,19 @@ void Quantity_yyerror(char *errorinfo)
|
||||
|
||||
namespace QuantityParser {
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
#define YYINITDEPTH 20
|
||||
// show parser the lexer method
|
||||
#define yylex QuantityLexer
|
||||
int QuantityLexer();
|
||||
|
||||
// Parser, defined in QuantityParser.y
|
||||
// NOLINTNEXTLINE
|
||||
#include "QuantityParser.c"
|
||||
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
// Scanner, defined in QuantityParser.l
|
||||
// NOLINTNEXTLINE
|
||||
#include "QuantityLexer.c"
|
||||
#endif // DOXYGEN_SHOULD_SKIP_THIS
|
||||
}
|
||||
|
||||
@@ -27,12 +27,14 @@
|
||||
#include "Unit.h"
|
||||
#include <QString>
|
||||
|
||||
// NOLINTBEGIN
|
||||
#ifndef DOUBLE_MAX
|
||||
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
|
||||
#endif
|
||||
#ifndef DOUBLE_MIN
|
||||
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
|
||||
#endif
|
||||
// NOLINTEND
|
||||
|
||||
namespace Base {
|
||||
class UnitsSchema;
|
||||
@@ -57,6 +59,7 @@ struct BaseExport QuantityFormat {
|
||||
|
||||
// Default denominator of minimum fractional inch. Only used in certain
|
||||
// schemas.
|
||||
// NOLINTNEXTLINE
|
||||
static int defaultDenominator; // i.e 8 for 1/8"
|
||||
|
||||
static inline int getDefaultDenominator() {
|
||||
@@ -86,10 +89,11 @@ struct BaseExport QuantityFormat {
|
||||
return 'g';
|
||||
}
|
||||
}
|
||||
static inline NumberFormat toFormat(char c, bool* ok = nullptr) {
|
||||
if (ok)
|
||||
static inline NumberFormat toFormat(char ch, bool* ok = nullptr) {
|
||||
if (ok) {
|
||||
*ok = true;
|
||||
switch (c) {
|
||||
}
|
||||
switch (ch) {
|
||||
case 'f':
|
||||
return Fixed;
|
||||
case 'e':
|
||||
@@ -97,8 +101,9 @@ struct BaseExport QuantityFormat {
|
||||
case 'g':
|
||||
return Default;
|
||||
default:
|
||||
if (ok)
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
}
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
@@ -112,7 +117,8 @@ class BaseExport Quantity
|
||||
public:
|
||||
/// default constructor
|
||||
Quantity();
|
||||
Quantity(const Quantity&);
|
||||
Quantity(const Quantity&) = default;
|
||||
Quantity(Quantity&&) = default;
|
||||
explicit Quantity(double value, const Unit& unit=Unit());
|
||||
explicit Quantity(double value, const QString& unit);
|
||||
/// Destruction
|
||||
@@ -120,38 +126,39 @@ public:
|
||||
|
||||
/** Operators. */
|
||||
//@{
|
||||
Quantity operator *(const Quantity &p) const;
|
||||
Quantity operator *(double p) const;
|
||||
Quantity operator +(const Quantity &p) const;
|
||||
Quantity& operator +=(const Quantity &p);
|
||||
Quantity operator -(const Quantity &p) const;
|
||||
Quantity& operator -=(const Quantity &p);
|
||||
Quantity operator *(const Quantity &other) const;
|
||||
Quantity operator *(double factor) const;
|
||||
Quantity operator +(const Quantity &other) const;
|
||||
Quantity& operator +=(const Quantity &other);
|
||||
Quantity operator -(const Quantity &other) const;
|
||||
Quantity& operator -=(const Quantity &other);
|
||||
Quantity operator -() const;
|
||||
Quantity operator /(const Quantity &p) const;
|
||||
Quantity operator /(double p) const;
|
||||
Quantity operator /(const Quantity &other) const;
|
||||
Quantity operator /(double factor) const;
|
||||
bool operator ==(const Quantity&) const;
|
||||
bool operator !=(const Quantity&) const;
|
||||
bool operator < (const Quantity&) const;
|
||||
bool operator > (const Quantity&) const;
|
||||
bool operator <= (const Quantity&) const;
|
||||
bool operator >= (const Quantity&) const;
|
||||
Quantity& operator =(const Quantity&);
|
||||
Quantity& operator =(const Quantity&) = default;
|
||||
Quantity& operator =(Quantity&&) = default;
|
||||
Quantity pow(const Quantity&)const;
|
||||
Quantity pow(double)const;
|
||||
//@}
|
||||
|
||||
const QuantityFormat& getFormat() const {
|
||||
return _Format;
|
||||
return myFormat;
|
||||
}
|
||||
void setFormat(const QuantityFormat& f) {
|
||||
_Format = f;
|
||||
void setFormat(const QuantityFormat& fmt) {
|
||||
myFormat = fmt;
|
||||
}
|
||||
/// transfer to user preferred unit/potence
|
||||
QString getUserString(double &factor, QString &unitString) const;
|
||||
QString getUserString() const { // to satisfy GCC
|
||||
double dummy1;
|
||||
QString dummy2;
|
||||
return getUserString(dummy1,dummy2);
|
||||
double dummy1{};
|
||||
QString dummy2{};
|
||||
return getUserString(dummy1, dummy2);
|
||||
}
|
||||
QString getUserString(UnitsSchema* schema, double &factor, QString &unitString) const;
|
||||
QString getSafeUserString() const;
|
||||
@@ -159,13 +166,13 @@ public:
|
||||
static Quantity parse(const QString &string);
|
||||
|
||||
/// returns the unit of the quantity
|
||||
const Unit & getUnit() const{return _Unit;}
|
||||
const Unit & getUnit() const{return myUnit;}
|
||||
/// set the unit of the quantity
|
||||
void setUnit(const Unit &un){_Unit = un;}
|
||||
void setUnit(const Unit &un){myUnit = un;}
|
||||
/// get the Value of the quantity
|
||||
double getValue() const{return _Value;}
|
||||
double getValue() const{return myValue;}
|
||||
/// set the value of the quantity
|
||||
void setValue(double val){_Value = val;}
|
||||
void setValue(double val){myValue = val;}
|
||||
/** get the Value in a special unit given as quantity.
|
||||
* One can use one of the predifeined quantity units in this class
|
||||
*/
|
||||
@@ -332,9 +339,9 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
double _Value;
|
||||
Unit _Unit;
|
||||
QuantityFormat _Format;
|
||||
double myValue;
|
||||
Unit myUnit;
|
||||
QuantityFormat myFormat;
|
||||
};
|
||||
|
||||
} // namespace Base
|
||||
|
||||
Reference in New Issue
Block a user