Base: apply clang format
This commit is contained in:
@@ -28,24 +28,28 @@
|
||||
#include <QString>
|
||||
|
||||
// NOLINTBEGIN
|
||||
#ifndef DOUBLE_MAX
|
||||
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
|
||||
#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"*/
|
||||
#ifndef DOUBLE_MIN
|
||||
#define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
|
||||
#endif
|
||||
// NOLINTEND
|
||||
|
||||
namespace Base {
|
||||
namespace Base
|
||||
{
|
||||
class UnitsSchema;
|
||||
|
||||
struct BaseExport QuantityFormat {
|
||||
enum NumberOption {
|
||||
struct BaseExport QuantityFormat
|
||||
{
|
||||
enum NumberOption
|
||||
{
|
||||
None = 0x00,
|
||||
OmitGroupSeparator = 0x01,
|
||||
RejectGroupSeparator = 0x02
|
||||
};
|
||||
enum NumberFormat {
|
||||
enum NumberFormat
|
||||
{
|
||||
Default = 0,
|
||||
Fixed = 1,
|
||||
Scientific = 2
|
||||
@@ -60,51 +64,57 @@ 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 int defaultDenominator; // i.e 8 for 1/8"
|
||||
|
||||
static inline int getDefaultDenominator() {
|
||||
static inline int getDefaultDenominator()
|
||||
{
|
||||
return defaultDenominator;
|
||||
}
|
||||
|
||||
static inline void setDefaultDenominator(int denom) {
|
||||
static inline void setDefaultDenominator(int denom)
|
||||
{
|
||||
defaultDenominator = denom;
|
||||
}
|
||||
|
||||
inline int getDenominator() const {
|
||||
inline int getDenominator() const
|
||||
{
|
||||
return denominator;
|
||||
}
|
||||
|
||||
inline void setDenominator(int denom) {
|
||||
inline void setDenominator(int denom)
|
||||
{
|
||||
denominator = denom;
|
||||
}
|
||||
QuantityFormat();
|
||||
explicit QuantityFormat(NumberFormat format, int decimals=-1);
|
||||
inline char toFormat() const {
|
||||
explicit QuantityFormat(NumberFormat format, int decimals = -1);
|
||||
inline char toFormat() const
|
||||
{
|
||||
switch (format) {
|
||||
case Fixed:
|
||||
return 'f';
|
||||
case Scientific:
|
||||
return 'e';
|
||||
default:
|
||||
return 'g';
|
||||
case Fixed:
|
||||
return 'f';
|
||||
case Scientific:
|
||||
return 'e';
|
||||
default:
|
||||
return 'g';
|
||||
}
|
||||
}
|
||||
static inline NumberFormat toFormat(char ch, bool* ok = nullptr) {
|
||||
static inline NumberFormat toFormat(char ch, bool* ok = nullptr)
|
||||
{
|
||||
if (ok) {
|
||||
*ok = true;
|
||||
}
|
||||
switch (ch) {
|
||||
case 'f':
|
||||
return Fixed;
|
||||
case 'e':
|
||||
return Scientific;
|
||||
case 'g':
|
||||
return Default;
|
||||
default:
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
}
|
||||
return Default;
|
||||
case 'f':
|
||||
return Fixed;
|
||||
case 'e':
|
||||
return Scientific;
|
||||
case 'g':
|
||||
return Default;
|
||||
default:
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
}
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -119,74 +129,89 @@ public:
|
||||
Quantity();
|
||||
Quantity(const Quantity&) = default;
|
||||
Quantity(Quantity&&) = default;
|
||||
explicit Quantity(double value, const Unit& unit=Unit());
|
||||
explicit Quantity(double value, const Unit& unit = Unit());
|
||||
explicit Quantity(double value, const QString& unit);
|
||||
/// Destruction
|
||||
~Quantity () = default;
|
||||
~Quantity() = default;
|
||||
|
||||
/** Operators. */
|
||||
//@{
|
||||
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 &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&) = default;
|
||||
Quantity& operator =(Quantity&&) = default;
|
||||
Quantity pow(const Quantity&)const;
|
||||
Quantity pow(double)const;
|
||||
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& 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&) = default;
|
||||
Quantity& operator=(Quantity&&) = default;
|
||||
Quantity pow(const Quantity&) const;
|
||||
Quantity pow(double) const;
|
||||
//@}
|
||||
|
||||
const QuantityFormat& getFormat() const {
|
||||
const QuantityFormat& getFormat() const
|
||||
{
|
||||
return myFormat;
|
||||
}
|
||||
void setFormat(const QuantityFormat& fmt) {
|
||||
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{};
|
||||
QString getUserString(double& factor, QString& unitString) const;
|
||||
QString getUserString() const
|
||||
{ // to satisfy GCC
|
||||
double dummy1 {};
|
||||
QString dummy2 {};
|
||||
return getUserString(dummy1, dummy2);
|
||||
}
|
||||
QString getUserString(UnitsSchema* schema, double &factor, QString &unitString) const;
|
||||
QString getUserString(UnitsSchema* schema, double& factor, QString& unitString) const;
|
||||
QString getSafeUserString() const;
|
||||
|
||||
static Quantity parse(const QString &string);
|
||||
static Quantity parse(const QString& string);
|
||||
|
||||
/// returns the unit of the quantity
|
||||
const Unit & getUnit() const{return myUnit;}
|
||||
const Unit& getUnit() const
|
||||
{
|
||||
return myUnit;
|
||||
}
|
||||
/// set the unit of the quantity
|
||||
void setUnit(const Unit &un){myUnit = un;}
|
||||
void setUnit(const Unit& un)
|
||||
{
|
||||
myUnit = un;
|
||||
}
|
||||
/// get the Value of the quantity
|
||||
double getValue() const{return myValue;}
|
||||
double getValue() const
|
||||
{
|
||||
return myValue;
|
||||
}
|
||||
/// set the value of the quantity
|
||||
void setValue(double val){myValue = 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
|
||||
*/
|
||||
double getValueAs(const Quantity &)const;
|
||||
* One can use one of the predifeined quantity units in this class
|
||||
*/
|
||||
double getValueAs(const Quantity&) const;
|
||||
|
||||
|
||||
/// true if it has a number without a unit
|
||||
bool isDimensionless()const;
|
||||
bool isDimensionless() const;
|
||||
/// true if it has a specific unit or no dimension.
|
||||
bool isDimensionlessOrUnit(const Unit& unit)const;
|
||||
bool isDimensionlessOrUnit(const Unit& unit) const;
|
||||
/// true if it has a number and a valid unit
|
||||
bool isQuantity()const;
|
||||
bool isQuantity() const;
|
||||
/// true if it has a number with or without a unit
|
||||
bool isValid()const;
|
||||
bool isValid() const;
|
||||
/// sets the quantity invalid
|
||||
void setInvalid();
|
||||
|
||||
@@ -303,7 +328,7 @@ public:
|
||||
|
||||
static const Quantity Weber;
|
||||
|
||||
//static const Quantity Oersted;
|
||||
// static const Quantity Oersted;
|
||||
|
||||
static const Quantity Farad;
|
||||
static const Quantity MilliFarad;
|
||||
@@ -340,12 +365,12 @@ public:
|
||||
//@}
|
||||
|
||||
|
||||
protected:
|
||||
double myValue;
|
||||
Unit myUnit;
|
||||
private:
|
||||
double myValue;
|
||||
Unit myUnit;
|
||||
QuantityFormat myFormat;
|
||||
};
|
||||
|
||||
} // namespace Base
|
||||
} // namespace Base
|
||||
|
||||
#endif // BASE_Quantity_H
|
||||
#endif // BASE_Quantity_H
|
||||
|
||||
Reference in New Issue
Block a user