mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Virtual destructor for polymorphic classes, const correctness, removed virtual method call in constructor
This commit is contained in:
@@ -58,10 +58,18 @@ int main(int argc, char *argv[])
|
||||
qDebug() << t1 << t2 << t2.convertedSiValueRoundedWithUnit();
|
||||
qDebug() << t3 << t3.valueRoundedWithUnit(CTemperatureUnit::C());
|
||||
|
||||
// some logging wit CLogMessage
|
||||
// some logging with CLogMessage
|
||||
bDebug << p1;
|
||||
bDebug << p1.getUnit() << p1.getUnit().getMultiplier();
|
||||
|
||||
// some of the faults Mathew has pointed out,not longer possible
|
||||
// CAngleUnit::rad() = CAngleUnit::deg();
|
||||
// qDebug() << CAngleUnit::rad(); // wrong
|
||||
(t1 - t2).switchUnit(CTemperatureUnit::F()); // was not working since wrong return type const
|
||||
// CDistanceUnit duA(CSpeedUnit::ft_min()); // no longer possible
|
||||
CDistanceUnit duB(CDistanceUnit::cm());
|
||||
qDebug() << duB;
|
||||
|
||||
// bye
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -34,4 +34,12 @@ CAngle::CAngle(double value, const CAngleUnit &unit) : CPhysicalQuantity(value,
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
CAngle::~CAngle()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,6 +10,13 @@ namespace BlackMisc {
|
||||
* \author KWB
|
||||
*/
|
||||
class CAngleUnit : public CMeasurementUnit {
|
||||
friend class CAngle;
|
||||
private:
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CAngleUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor
|
||||
@@ -24,21 +31,16 @@ public:
|
||||
*/
|
||||
CAngleUnit(const QString &name, const QString &unitName, bool isSIUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "angle", isSIUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CAngleUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
/*!
|
||||
* \brief Meter m
|
||||
* \return
|
||||
*/
|
||||
static CAngleUnit& rad() { static CAngleUnit rad("radian", "rad", true); return rad;}
|
||||
static const CAngleUnit& rad() { static CAngleUnit rad("radian", "rad", true); return rad;}
|
||||
/*!
|
||||
* \brief Nautical miles NM
|
||||
* \return
|
||||
*/
|
||||
static CAngleUnit& deg() { static CAngleUnit deg("degree", "°", false, M_PI/180); return deg;}
|
||||
static const CAngleUnit& deg() { static CAngleUnit deg("degree", "°", false, M_PI/180); return deg;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -68,16 +70,20 @@ public:
|
||||
* \param unit
|
||||
*/
|
||||
CAngle(double value, const CAngleUnit &unit = CAngleUnit::rad());
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CAngle();
|
||||
/*!
|
||||
* \brief Unit of the distance
|
||||
* \return
|
||||
*/
|
||||
CAngleUnit getUnit() const { return this->_unit; }
|
||||
CAngleUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CAngleUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CAngleUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
/*!
|
||||
* \brief Convenience method PI
|
||||
* \return
|
||||
|
||||
@@ -19,22 +19,22 @@ public:
|
||||
* \brief Temperature absolute Zero in °C
|
||||
* \return
|
||||
*/
|
||||
static CTemperature& TemperatureAbsoluteZero() { static CTemperature t(-273.15, CTemperatureUnit::C()); return t;}
|
||||
static const CTemperature& TemperatureAbsoluteZero() { static CTemperature t(-273.15, CTemperatureUnit::C()); return t;}
|
||||
/*!
|
||||
* \brief Tripe point of purified water, 0.01°C
|
||||
* \return
|
||||
*/
|
||||
static CTemperature& TemperatureTriplePointOfVSMOW() { static CTemperature t(-273.16, CTemperatureUnit::K()); return t;}
|
||||
static const CTemperature& TemperatureTriplePointOfVSMOW() { static CTemperature t(-273.16, CTemperatureUnit::K()); return t;}
|
||||
/*!
|
||||
* \brief Temperature absolute Zero in °C
|
||||
* \return
|
||||
*/
|
||||
static CTemperature& TemperatureAbsoluteZeroC() { static CTemperature t(-273.15, CTemperatureUnit::C()); return t;}
|
||||
static const CTemperature& TemperatureAbsoluteZeroC() { static CTemperature t(-273.15, CTemperatureUnit::C()); return t;}
|
||||
/*!
|
||||
* \brief Standard pressure 1013,25mbar / 29.92inHg
|
||||
* \return
|
||||
*/
|
||||
static CPressure& InternationalStandardSeaLevelPressure() { static CPressure p(1013.25, CPressureUnit::hPa()); return p;}
|
||||
static const CPressure& InternationalStandardSeaLevelPressure() { static CPressure p(1013.25, CPressureUnit::hPa()); return p;}
|
||||
};
|
||||
} // namespace
|
||||
#endif // PQCONSTANTS_H
|
||||
|
||||
@@ -34,4 +34,12 @@ CDistance::CDistance(double value, const CDistanceUnit &unit) : CPhysicalQuantit
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
CDistance::~CDistance()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
@@ -9,6 +9,13 @@ namespace BlackMisc {
|
||||
* \author KWB
|
||||
*/
|
||||
class CDistanceUnit : public CMeasurementUnit {
|
||||
friend class CDistance;
|
||||
private:
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CDistanceUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor
|
||||
@@ -24,36 +31,31 @@ public:
|
||||
*/
|
||||
CDistanceUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "distance", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CDistanceUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
/*!
|
||||
* \brief Meter m
|
||||
* \return
|
||||
*/
|
||||
static CDistanceUnit& m() { static CDistanceUnit m("meter", "m", true, true); return m;}
|
||||
static const CDistanceUnit& m() { static CDistanceUnit m("meter", "m", true, true); return m;}
|
||||
/*!
|
||||
* \brief Nautical miles NM
|
||||
* \return
|
||||
*/
|
||||
static CDistanceUnit& NM() { static CDistanceUnit NM("nautical miles", "NM", false, false, 1000.0*1.85200, CMeasurementPrefix::One(), 3);return NM;}
|
||||
static const CDistanceUnit& NM() { static CDistanceUnit NM("nautical miles", "NM", false, false, 1000.0*1.85200, CMeasurementPrefix::One(), 3);return NM;}
|
||||
/*!
|
||||
* \brief Foot ft
|
||||
* \return
|
||||
*/
|
||||
static CDistanceUnit& ft() { static CDistanceUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); return ft;}
|
||||
static const CDistanceUnit& ft() { static CDistanceUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); return ft;}
|
||||
/*!
|
||||
* \brief Kilometer km
|
||||
* \return
|
||||
*/
|
||||
static CDistanceUnit& km() { static CDistanceUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3);return km;}
|
||||
static const CDistanceUnit& km() { static CDistanceUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3);return km;}
|
||||
/*!
|
||||
* \brief Centimeter cm
|
||||
* \return
|
||||
*/
|
||||
static CDistanceUnit& cm() { static CDistanceUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1);return cm;}
|
||||
static const CDistanceUnit& cm() { static CDistanceUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1);return cm;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -83,16 +85,20 @@ public:
|
||||
* \param unit
|
||||
*/
|
||||
CDistance(double value, const CDistanceUnit &unit = CDistanceUnit::m());
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CDistance();
|
||||
/*!
|
||||
* \brief Unit of the distance
|
||||
* \return
|
||||
*/
|
||||
CDistanceUnit getUnit() const { return this->_unit; }
|
||||
CDistanceUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CDistanceUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CDistanceUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
};
|
||||
} // namespace blackCore
|
||||
#endif // PQDISTANCE_H
|
||||
|
||||
@@ -34,5 +34,13 @@ CFrequency::CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuan
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
CFrequency::~CFrequency()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -9,6 +9,13 @@ namespace BlackMisc {
|
||||
* \author KWB
|
||||
*/
|
||||
class CFrequencyUnit : public CMeasurementUnit {
|
||||
friend class CFrequency;
|
||||
private:
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CFrequencyUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor
|
||||
@@ -23,31 +30,26 @@ public:
|
||||
*/
|
||||
CFrequencyUnit(const QString &name, const QString &unitName, bool isSIUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "frequency", isSIUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CFrequencyUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
/*!
|
||||
* \brief Hertz
|
||||
* \return
|
||||
*/
|
||||
static CFrequencyUnit& Hz() { static CFrequencyUnit Hz("hertz", "Hz", true); return Hz;}
|
||||
static const CFrequencyUnit& Hz() { static CFrequencyUnit Hz("hertz", "Hz", true); return Hz;}
|
||||
/*!
|
||||
* \brief Kilohertz
|
||||
* \return
|
||||
*/
|
||||
static CFrequencyUnit& kHz() { static CFrequencyUnit kHz("kilohertz", "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 0);return kHz;}
|
||||
static const CFrequencyUnit& kHz() { static CFrequencyUnit kHz("kilohertz", "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 0);return kHz;}
|
||||
/*!
|
||||
* \brief Megahertz
|
||||
* \return
|
||||
*/
|
||||
static CFrequencyUnit& MHz() { static CFrequencyUnit MHz("megahertz", "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 0); return MHz;}
|
||||
static const CFrequencyUnit& MHz() { static CFrequencyUnit MHz("megahertz", "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 0); return MHz;}
|
||||
/*!
|
||||
* \brief Gigahertz
|
||||
* \return
|
||||
*/
|
||||
static CFrequencyUnit& GHz() { static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 0);return GHz;}
|
||||
static const CFrequencyUnit& GHz() { static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 0);return GHz;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -72,21 +74,25 @@ public:
|
||||
*/
|
||||
CFrequency(qint32 value, const CFrequencyUnit &unit = CFrequencyUnit::Hz());
|
||||
/*!
|
||||
*\brief Init by double value
|
||||
* \brief Init by double value
|
||||
* \param value
|
||||
* \param unit
|
||||
*/
|
||||
CFrequency(double value, const CFrequencyUnit &unit = CFrequencyUnit::Hz());
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CFrequency();
|
||||
/*!
|
||||
* \brief Unit of the distance
|
||||
* \return
|
||||
*/
|
||||
CFrequencyUnit getUnit() const { return this->_unit; }
|
||||
CFrequencyUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CFrequencyUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CFrequencyUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
};
|
||||
} // namespace blackCore
|
||||
#endif // PQFREQUENCY_H
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace BlackMisc {
|
||||
*/
|
||||
CMass::CMass(): CPhysicalQuantity(0, CMassUnit::kg(),CMassUnit::kg())
|
||||
{
|
||||
//void
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
CMass::CMass(const CPhysicalQuantity &weight): CPhysicalQuantity(weight)
|
||||
CMass::CMass(const CPhysicalQuantity &mass): CPhysicalQuantity(mass)
|
||||
{
|
||||
// void
|
||||
}
|
||||
@@ -34,4 +34,12 @@ CMass::CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, uni
|
||||
// void
|
||||
}
|
||||
|
||||
} // namespace BlackCore
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
CMass::~CMass()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
@@ -9,6 +9,13 @@ namespace BlackMisc {
|
||||
* \author KWB
|
||||
*/
|
||||
class CMassUnit : public CMeasurementUnit {
|
||||
friend class CMass;
|
||||
private:
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CMassUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor
|
||||
@@ -24,31 +31,26 @@ public:
|
||||
*/
|
||||
CMassUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "mass", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CMassUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
/*!
|
||||
* \brief Kilogram, SI base unit
|
||||
* \return
|
||||
*/
|
||||
static CMassUnit& kg() { static CMassUnit kg("kilogram", "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); return kg;}
|
||||
static const CMassUnit& kg() { static CMassUnit kg("kilogram", "kg", true, true, 1.0, CMeasurementPrefix::k(), 1); return kg;}
|
||||
/*!
|
||||
* \brief Gram, SI unit
|
||||
* \return
|
||||
*/
|
||||
static CMassUnit& g() { static CMassUnit g("gram", "g", true, false, 1.0/1000.0, CMeasurementPrefix::One(), 0); return g;}
|
||||
static const CMassUnit& g() { static CMassUnit g("gram", "g", true, false, 1.0/1000.0, CMeasurementPrefix::One(), 0); return g;}
|
||||
/*!
|
||||
* \brief Tonne, aka metric tonne (1000kg)
|
||||
* \return
|
||||
*/
|
||||
static CMassUnit& t() { static CMassUnit t("tonne", "t", true, false, 1000.0, CMeasurementPrefix::One(), 3); return t;}
|
||||
static const CMassUnit& t() { static CMassUnit t("tonne", "t", true, false, 1000.0, CMeasurementPrefix::One(), 3); return t;}
|
||||
/*!
|
||||
* \brief Pound, aka mass pound
|
||||
* \return
|
||||
*/
|
||||
static CMassUnit& lb() { static CMassUnit lbs("pound", "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); return lbs;}
|
||||
static const CMassUnit& lb() { static CMassUnit lbs("pound", "lb", false, false, 0.45359237, CMeasurementPrefix::One(), 1); return lbs;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -62,10 +64,6 @@ public:
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CMass();
|
||||
/**
|
||||
*\brief downcast copy constructor
|
||||
*/
|
||||
CMass(const CPhysicalQuantity &mass);
|
||||
/*!
|
||||
* \brief Init by int value
|
||||
* \param value
|
||||
@@ -78,16 +76,25 @@ public:
|
||||
* \param unit
|
||||
*/
|
||||
CMass(double value, const CMassUnit &unit = CMassUnit::kg());
|
||||
/*!
|
||||
* \brief Copyconstructor
|
||||
* \param mass
|
||||
*/
|
||||
CMass(const CPhysicalQuantity &mass);
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CMass();
|
||||
/*!
|
||||
* \brief Unit of the mass
|
||||
* \return
|
||||
*/
|
||||
CMassUnit getUnit() const { return this->_unit; }
|
||||
CMassUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CMassUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CMassUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
};
|
||||
} // namespace blackCore
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace BlackMisc {
|
||||
/**
|
||||
* Constructor by integer
|
||||
*/
|
||||
CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit) :
|
||||
_unit(unit), _conversionSiUnit(siConversionUnit)
|
||||
CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit, const CPhysicalQuantityUnitConverter unitConverter) :
|
||||
_pUnit(unit), _pConversionSiUnit(siConversionUnit), _unitConverter(unitConverter)
|
||||
{
|
||||
this->setUnitValue(baseValue);
|
||||
}
|
||||
@@ -14,8 +14,8 @@ CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const CMeasurementUnit &u
|
||||
/**
|
||||
* Constructor by double
|
||||
*/
|
||||
CPhysicalQuantity::CPhysicalQuantity(double baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit) :
|
||||
_unit(unit), _conversionSiUnit(siConversionUnit)
|
||||
CPhysicalQuantity::CPhysicalQuantity(double baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit, const CPhysicalQuantityUnitConverter unitConverter) :
|
||||
_pUnit(unit), _pConversionSiUnit(siConversionUnit),_unitConverter(unitConverter)
|
||||
{
|
||||
this->setUnitValue(baseValue);
|
||||
}
|
||||
@@ -25,7 +25,15 @@ CPhysicalQuantity::CPhysicalQuantity(double baseValue, const CMeasurementUnit &u
|
||||
*/
|
||||
CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &otherQuantity) :
|
||||
_unitValueD(otherQuantity._unitValueD), _unitValueI(otherQuantity._unitValueI), _convertedSiUnitValueD(otherQuantity._convertedSiUnitValueD),
|
||||
_isIntegerBaseValue(otherQuantity._isIntegerBaseValue), _unit(otherQuantity._unit), _conversionSiUnit(otherQuantity._conversionSiUnit)
|
||||
_isIntegerBaseValue(otherQuantity._isIntegerBaseValue), _pUnit(otherQuantity._pUnit), _pConversionSiUnit(otherQuantity._pConversionSiUnit), _unitConverter(otherQuantity._unitConverter)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destructor
|
||||
*/
|
||||
CPhysicalQuantity::~CPhysicalQuantity()
|
||||
{
|
||||
// void
|
||||
}
|
||||
@@ -56,24 +64,24 @@ CLogMessage operator <<(CLogMessage d, const CPhysicalQuantity &quantity)
|
||||
bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &otherQuantity) const
|
||||
{
|
||||
if(this == &otherQuantity) return true;
|
||||
if(this->_unit.getType()!= otherQuantity._unit.getType()) return false;
|
||||
if(this->_pUnit.getType()!= otherQuantity._pUnit.getType()) return false;
|
||||
|
||||
// some special case for best quality
|
||||
double diff;
|
||||
const double lenient = 1.001; // even diff alread has a round issue
|
||||
if (this->_unit == otherQuantity._unit) {
|
||||
if (this->_pUnit == otherQuantity._pUnit) {
|
||||
// same unit
|
||||
if (this->_isIntegerBaseValue && otherQuantity._isIntegerBaseValue) {
|
||||
// pure integer comparison, no rounding issues
|
||||
return this->_unitValueI == otherQuantity._unitValueI;
|
||||
} else {
|
||||
diff = abs(this->_unitValueD - otherQuantity._unitValueD);
|
||||
return diff <= (lenient * this->_unit.getEpsilon());
|
||||
return diff <= (lenient * this->_pUnit.getEpsilon());
|
||||
}
|
||||
} else {
|
||||
// based on SI value
|
||||
diff = abs(this->_convertedSiUnitValueD - otherQuantity._convertedSiUnitValueD);
|
||||
return diff <= (lenient * this->_unit.getEpsilon());
|
||||
return diff <= (lenient * this->_pUnit.getEpsilon());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +105,9 @@ CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &otherQu
|
||||
CPhysicalQuantity::_unitValueD = otherQuantity._unitValueD;
|
||||
CPhysicalQuantity::_convertedSiUnitValueD = otherQuantity._convertedSiUnitValueD;
|
||||
CPhysicalQuantity::_isIntegerBaseValue = otherQuantity._isIntegerBaseValue;
|
||||
CPhysicalQuantity::_unit = otherQuantity._unit;
|
||||
CPhysicalQuantity::_conversionSiUnit = otherQuantity._conversionSiUnit;
|
||||
CPhysicalQuantity::_pUnit = otherQuantity._pUnit;
|
||||
CPhysicalQuantity::_pConversionSiUnit = otherQuantity._pConversionSiUnit;
|
||||
CPhysicalQuantity::_unitConverter = otherQuantity._unitConverter;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -107,7 +116,7 @@ CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &otherQu
|
||||
*/
|
||||
CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &otherQuantity)
|
||||
{
|
||||
if (this->_unit == otherQuantity._unit) {
|
||||
if (this->_pUnit == otherQuantity._pUnit) {
|
||||
// same unit
|
||||
if (this->_isIntegerBaseValue && otherQuantity._isIntegerBaseValue) {
|
||||
// pure integer, no rounding issues
|
||||
@@ -116,7 +125,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other
|
||||
this->setUnitValue(otherQuantity._unitValueI + this->_unitValueI);
|
||||
}
|
||||
} else {
|
||||
double v = otherQuantity.value(this->_unit);
|
||||
double v = otherQuantity.value(this->_pUnit);
|
||||
this->setUnitValue(v + this->_unitValueD);
|
||||
}
|
||||
return *this;
|
||||
@@ -128,7 +137,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other
|
||||
CPhysicalQuantity &CPhysicalQuantity::operator +=(double unprefixedSiUnitValue)
|
||||
{
|
||||
if (!this->isUnprefixedSiUnit()) {
|
||||
this->switchUnit(this->_conversionSiUnit);
|
||||
this->switchUnit(this->_pConversionSiUnit);
|
||||
}
|
||||
this->setUnitValue(this->_unitValueD + unprefixedSiUnitValue);
|
||||
return *this;
|
||||
@@ -137,7 +146,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator +=(double unprefixedSiUnitValue)
|
||||
/**
|
||||
* Plus operator
|
||||
*/
|
||||
const CPhysicalQuantity CPhysicalQuantity::operator +(const CPhysicalQuantity &otherQuantity) const
|
||||
CPhysicalQuantity CPhysicalQuantity::operator +(const CPhysicalQuantity &otherQuantity) const
|
||||
{
|
||||
CPhysicalQuantity pq = (*this);
|
||||
return pq+= otherQuantity;
|
||||
@@ -148,7 +157,7 @@ const CPhysicalQuantity CPhysicalQuantity::operator +(const CPhysicalQuantity &o
|
||||
*/
|
||||
CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &otherQuantity)
|
||||
{
|
||||
if (this->_unit == otherQuantity._unit) {
|
||||
if (this->_pUnit == otherQuantity._pUnit) {
|
||||
// same unit
|
||||
if (this->_isIntegerBaseValue && otherQuantity._isIntegerBaseValue) {
|
||||
// pure integer, no rounding issues
|
||||
@@ -157,7 +166,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &other
|
||||
this->setUnitValue(otherQuantity._unitValueI - this->_unitValueI);
|
||||
}
|
||||
} else {
|
||||
double v = otherQuantity.value(this->_unit);
|
||||
double v = otherQuantity.value(this->_pUnit);
|
||||
this->setUnitValue(v - this->_unitValueD);
|
||||
}
|
||||
return *this;
|
||||
@@ -175,7 +184,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator -=(double unprefixedSiUnitValue)
|
||||
/**
|
||||
* Minus operator
|
||||
*/
|
||||
const CPhysicalQuantity CPhysicalQuantity::operator -(const CPhysicalQuantity &otherQuantity) const
|
||||
CPhysicalQuantity CPhysicalQuantity::operator -(const CPhysicalQuantity &otherQuantity) const
|
||||
{
|
||||
CPhysicalQuantity pq = (*this);
|
||||
return pq-= otherQuantity;
|
||||
@@ -193,7 +202,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator *=(double multiply)
|
||||
/**
|
||||
* Multiply operator
|
||||
*/
|
||||
const CPhysicalQuantity CPhysicalQuantity::operator *(double multiply) const
|
||||
CPhysicalQuantity CPhysicalQuantity::operator *(double multiply) const
|
||||
{
|
||||
CPhysicalQuantity pq= (*this);
|
||||
return pq *= multiply;
|
||||
@@ -211,7 +220,7 @@ CPhysicalQuantity &CPhysicalQuantity::operator /=(double divide)
|
||||
/**
|
||||
* Divide operator /=
|
||||
*/
|
||||
const CPhysicalQuantity CPhysicalQuantity::operator /(double divide) const
|
||||
CPhysicalQuantity CPhysicalQuantity::operator /(double divide) const
|
||||
{
|
||||
CPhysicalQuantity pq= (*this);
|
||||
return pq /= divide;
|
||||
@@ -223,7 +232,7 @@ const CPhysicalQuantity CPhysicalQuantity::operator /(double divide) const
|
||||
bool CPhysicalQuantity::operator <(const CPhysicalQuantity &otherQuantity) const {
|
||||
if(this == &otherQuantity) return false;
|
||||
double diff = this->_convertedSiUnitValueD - otherQuantity._convertedSiUnitValueD;
|
||||
return (diff < 0 && abs(diff) >= this->_unit.getEpsilon());
|
||||
return (diff < 0 && abs(diff) >= this->_pUnit.getEpsilon());
|
||||
}
|
||||
|
||||
bool CPhysicalQuantity::operator >(const CPhysicalQuantity &otherQuantity) const {
|
||||
@@ -246,10 +255,10 @@ bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &otherQuantity) cons
|
||||
*/
|
||||
bool CPhysicalQuantity::switchUnit(const CMeasurementUnit &newUnit)
|
||||
{
|
||||
if (this->_unit == newUnit) return true;
|
||||
if (this->_unit.getType() != newUnit.getType()) return false; // not possible
|
||||
double cf = this->calculateValueInOtherUnit(newUnit);
|
||||
this->_unit = newUnit;
|
||||
if (this->_pUnit == newUnit) return true;
|
||||
if (this->_pUnit.getType() != newUnit.getType()) return false; // not possible
|
||||
double cf = this->_unitConverter(this, newUnit);
|
||||
this->_pUnit = newUnit;
|
||||
this->setUnitValue(cf);
|
||||
return true;
|
||||
}
|
||||
@@ -280,17 +289,17 @@ void CPhysicalQuantity::setUnitValue(double baseValue)
|
||||
* Set SI value
|
||||
*/
|
||||
void CPhysicalQuantity::setConversionSiUnitValue() {
|
||||
this->_convertedSiUnitValueD = this->calculateValueInOtherUnit(this->_conversionSiUnit);
|
||||
this->_convertedSiUnitValueD = this->_unitConverter(this, this->_pConversionSiUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard conversion by factor, used in most cases,in some cases overridden (e.g.CTemperature)
|
||||
* Standard conversion by factor, used in most cases, in some cases (e.g. CTemperature) arbitrary converter
|
||||
*/
|
||||
double CPhysicalQuantity::calculateValueInOtherUnit(const CMeasurementUnit &otherUnit) const {
|
||||
if (this->_unit == CMeasurementUnit::None() || this->_unitValueD == 0.0) return 0.0;
|
||||
if (this->_unit == otherUnit) return this->_unitValueD;
|
||||
double f = this->_unit.conversionFactor(otherUnit);
|
||||
return f * this->_unitValueD;
|
||||
double CPhysicalQuantity::standardUnitFactorValueConverter(const CPhysicalQuantity *quantity, const CMeasurementUnit &otherUnit) {
|
||||
if (quantity->_pUnit == CMeasurementUnit::None() || quantity->_unitValueD == 0.0) return 0.0;
|
||||
if (quantity->_pUnit == otherUnit) return quantity->_unitValueD;
|
||||
double f = quantity->_pUnit.conversionFactor(otherUnit);
|
||||
return f * quantity->_unitValueD;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,7 +307,7 @@ double CPhysicalQuantity::calculateValueInOtherUnit(const CMeasurementUnit &othe
|
||||
*/
|
||||
double CPhysicalQuantity::unitValueToDoubleRounded(int digits) const
|
||||
{
|
||||
if (digits < 1) digits = this->_unit.getDisplayDigits();
|
||||
if (digits < 1) digits = this->_pUnit.getDisplayDigits();
|
||||
return CPhysicalQuantity::round(this->_unitValueD, digits);
|
||||
}
|
||||
|
||||
@@ -317,7 +326,7 @@ QString CPhysicalQuantity::toQStringRounded(double value, int digits)
|
||||
*/
|
||||
QString CPhysicalQuantity::unitValueToQStringRounded(int digits) const
|
||||
{
|
||||
if (digits < 1) digits = this->_unit.getDisplayDigits();
|
||||
if (digits < 1) digits = this->_pUnit.getDisplayDigits();
|
||||
return CPhysicalQuantity::toQStringRounded(this->_unitValueD, digits);
|
||||
}
|
||||
|
||||
@@ -326,7 +335,7 @@ QString CPhysicalQuantity::unitValueToQStringRounded(int digits) const
|
||||
*/
|
||||
QString CPhysicalQuantity::convertedSiValueToQStringRounded(int digits) const
|
||||
{
|
||||
if (digits < 1) digits = this->_conversionSiUnit.getDisplayDigits();
|
||||
if (digits < 1) digits = this->_pConversionSiUnit.getDisplayDigits();
|
||||
return CPhysicalQuantity::toQStringRounded(this->_convertedSiUnitValueD, digits);
|
||||
}
|
||||
|
||||
@@ -334,16 +343,16 @@ QString CPhysicalQuantity::convertedSiValueToQStringRounded(int digits) const
|
||||
* Value rounded in original unit
|
||||
*/
|
||||
QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits) const {
|
||||
if (digits < 1) digits = this->_unit.getDisplayDigits();
|
||||
return this->unitValueToQStringRounded(digits).append(this->_unit.getUnitName());
|
||||
if (digits < 1) digits = this->_pUnit.getDisplayDigits();
|
||||
return this->unitValueToQStringRounded(digits).append(this->_pUnit.getUnitName());
|
||||
}
|
||||
|
||||
/**
|
||||
* SI base unit value with unit
|
||||
*/
|
||||
QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits) const {
|
||||
if (digits < 1) digits = this->_conversionSiUnit.getDisplayDigits();
|
||||
return this->convertedSiValueToQStringRounded(digits).append(this->_conversionSiUnit.getUnitName());
|
||||
if (digits < 1) digits = this->_pConversionSiUnit.getDisplayDigits();
|
||||
return this->convertedSiValueToQStringRounded(digits).append(this->_pConversionSiUnit.getUnitName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,8 +360,8 @@ QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits) const {
|
||||
*/
|
||||
QString CPhysicalQuantity::valueRoundedWithUnit(const CMeasurementUnit &unit, int digits) const
|
||||
{
|
||||
if (unit == this->_unit) return this->unitValueRoundedWithUnit(digits);
|
||||
if (unit == this->_conversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits);
|
||||
if (unit == this->_pUnit) return this->unitValueRoundedWithUnit(digits);
|
||||
if (unit == this->_pConversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits);
|
||||
if (digits < 0) digits = unit.getDisplayDigits();
|
||||
return CPhysicalQuantity::toQStringRounded(this->value(unit), digits).append(unit.getUnitName());
|
||||
}
|
||||
@@ -371,8 +380,8 @@ double CPhysicalQuantity::valueRounded(const CMeasurementUnit &unit, int digits)
|
||||
*/
|
||||
double CPhysicalQuantity::value(const CMeasurementUnit &unit) const
|
||||
{
|
||||
if (unit == this->_conversionSiUnit) return this->_convertedSiUnitValueD;
|
||||
double v = this->calculateValueInOtherUnit(unit);
|
||||
if (unit == this->_pConversionSiUnit) return this->_convertedSiUnitValueD;
|
||||
double v = this->_unitConverter(this, unit);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -381,7 +390,7 @@ double CPhysicalQuantity::value(const CMeasurementUnit &unit) const
|
||||
*/
|
||||
double CPhysicalQuantity::convertedSiValueToDoubleRounded(int digits) const
|
||||
{
|
||||
if (digits < 1) digits = this->_conversionSiUnit.getDisplayDigits();
|
||||
if (digits < 1) digits = this->_pConversionSiUnit.getDisplayDigits();
|
||||
return CPhysicalQuantity::round(this->_convertedSiUnitValueD, digits);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
|
||||
namespace BlackMisc {
|
||||
|
||||
class CPhysicalQuantity;
|
||||
|
||||
/*!
|
||||
* Our converter function, should be implemented as static method of the quantity
|
||||
* classes for clarity
|
||||
*/
|
||||
typedef double (*CPhysicalQuantityUnitConverter)(const CPhysicalQuantity *quantity, const CMeasurementUnit &unit);
|
||||
|
||||
/*!
|
||||
* \brief A physical quantity such as "5m", "20s", "1500ft/s"
|
||||
* \author KWB
|
||||
@@ -37,28 +45,43 @@ private:
|
||||
double _unitValueD; //!< value backed by double
|
||||
double _convertedSiUnitValueD; //!< SI unit value
|
||||
bool _isIntegerBaseValue; //!< flag integer? / double?
|
||||
CPhysicalQuantityUnitConverter _unitConverter; //! <! converts values between units
|
||||
|
||||
/*!
|
||||
* Convert value in another unit, normally just by a factor, but in some cases
|
||||
* (e.g. CTemperature)overridden because arbitrary conversion is required
|
||||
* \sa CMeasurementUnit::conversionFactor(CMeasurementUnit)
|
||||
* \param quantity quanity
|
||||
* \param otherUnit
|
||||
* \return
|
||||
*/
|
||||
static double standardUnitFactorValueConverter(const CPhysicalQuantity *quantity, const CMeasurementUnit &otherUnit);
|
||||
|
||||
protected:
|
||||
CMeasurementUnit _unit; //!< unit
|
||||
CMeasurementUnit _conversionSiUnit; //!< corresponding SI base unit
|
||||
CMeasurementUnit _pUnit; //!< unit
|
||||
CMeasurementUnit _pConversionSiUnit; //!< corresponding SI base unit
|
||||
|
||||
/*!
|
||||
* \brief Constructor with int
|
||||
* \param baseValue
|
||||
* \param unit
|
||||
* \param siBaseUnit
|
||||
* \param unitConverter
|
||||
*/
|
||||
CPhysicalQuantity(qint32 baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit);
|
||||
CPhysicalQuantity(qint32 baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit,
|
||||
const CPhysicalQuantityUnitConverter unitConverter = CPhysicalQuantity::standardUnitFactorValueConverter);
|
||||
/*!
|
||||
* \brief Constructor with double
|
||||
* \param baseValue
|
||||
* \param unit
|
||||
* \param siBaseUnit
|
||||
*/
|
||||
CPhysicalQuantity(double baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit);
|
||||
CPhysicalQuantity(double baseValue, const CMeasurementUnit &unit, const CMeasurementUnit &siConversionUnit,
|
||||
const CPhysicalQuantityUnitConverter unitConverter = CPhysicalQuantity::standardUnitFactorValueConverter);
|
||||
/*!
|
||||
* \brief Init by integer
|
||||
* \param baseValue
|
||||
* \param unitConverter
|
||||
*/
|
||||
void setUnitValue(qint32 baseValue);
|
||||
/*!
|
||||
@@ -70,14 +93,6 @@ protected:
|
||||
* \brief Set the SI value
|
||||
*/
|
||||
void setConversionSiUnitValue();
|
||||
/*!
|
||||
* Convert value in another unit, normally just by a factor, but in some cases
|
||||
* (e.g. CTemperature)overridden because arbitrary conversion is required
|
||||
* \sa CMeasurementUnit::conversionFactor(CMeasurementUnit)
|
||||
* \param otherUnit
|
||||
* \return
|
||||
*/
|
||||
virtual double calculateValueInOtherUnit(const CMeasurementUnit &otherUnit) const;
|
||||
|
||||
public:
|
||||
/*!
|
||||
@@ -85,6 +100,11 @@ public:
|
||||
* \param otherQuantity
|
||||
*/
|
||||
CPhysicalQuantity(const CPhysicalQuantity &otherQuantity);
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CPhysicalQuantity();
|
||||
|
||||
/*!
|
||||
* \brief Switch unit, e.g. feet meter
|
||||
* \param newUnit
|
||||
@@ -95,17 +115,17 @@ public:
|
||||
* \brief Value in SI base unit? Meter is an SI base unit, hertz not!
|
||||
* \return
|
||||
*/
|
||||
bool isSiBaseUnit() const { return this->_unit.isSiBaseUnit(); }
|
||||
bool isSiBaseUnit() const { return this->_pUnit.isSiBaseUnit(); }
|
||||
/*!
|
||||
* \brief Value in SI unit? Hertz is an derived SI unit, NM not!
|
||||
* \return
|
||||
*/
|
||||
bool isSiUnit() const { return this->_unit.isSiUnit(); }
|
||||
bool isSiUnit() const { return this->_pUnit.isSiUnit(); }
|
||||
/*!
|
||||
* \brief Value in unprefixed SI unit? Meter is a unprefixed, kilometer a prefixed SI Unit
|
||||
* \return
|
||||
*/
|
||||
bool isUnprefixedSiUnit() const { return this->_unit.isUnprefixedSiUnit(); }
|
||||
bool isUnprefixedSiUnit() const { return this->_pUnit.isUnprefixedSiUnit(); }
|
||||
/*!
|
||||
* \brief Value to QString with unit, e.g. "5.00m"
|
||||
* \param digits
|
||||
@@ -235,13 +255,13 @@ public:
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
*/
|
||||
const CPhysicalQuantity operator +(const CPhysicalQuantity &otherQuantity) const;
|
||||
CPhysicalQuantity operator +(const CPhysicalQuantity &otherQuantity) const;
|
||||
/*!
|
||||
* \brief Minus operator -
|
||||
* \param otherQuantity
|
||||
* @return
|
||||
*/
|
||||
const CPhysicalQuantity operator -(const CPhysicalQuantity &otherQuantity) const;
|
||||
CPhysicalQuantity operator -(const CPhysicalQuantity &otherQuantity) const;
|
||||
/*!
|
||||
* \brief Multiply operator *=
|
||||
* \param multiply
|
||||
@@ -259,13 +279,13 @@ public:
|
||||
* \param multiply
|
||||
* @return
|
||||
*/
|
||||
const CPhysicalQuantity operator *(double multiply) const;
|
||||
CPhysicalQuantity operator *(double multiply) const;
|
||||
/*!
|
||||
* \brief Operator /
|
||||
* \param divide
|
||||
* @return
|
||||
*/
|
||||
const CPhysicalQuantity operator /(double divide) const;
|
||||
CPhysicalQuantity operator /(double divide) const;
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param otherQuantity
|
||||
|
||||
@@ -34,5 +34,13 @@ CPressure::CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantit
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
CPressure::~CPressure()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,6 +10,14 @@ namespace BlackMisc {
|
||||
* \author KWB
|
||||
*/
|
||||
class CPressureUnit : public CMeasurementUnit {
|
||||
friend class CPressure;
|
||||
private:
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* and cast unit
|
||||
* \param otherUnit
|
||||
*/
|
||||
CPressureUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor
|
||||
@@ -24,46 +32,41 @@ public:
|
||||
*/
|
||||
CPressureUnit(const QString &name, const QString &unitName, bool isSIUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "frequency", isSIUnit, false, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CPressureUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
/*!
|
||||
* \brief Pascal
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& Pa() { static CPressureUnit Pa("pascal", "Pa", true); return Pa;}
|
||||
static const CPressureUnit& Pa() { static CPressureUnit Pa("pascal", "Pa", true); return Pa;}
|
||||
/*!
|
||||
* \brief Hectopascal
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& hPa() { static CPressureUnit hPa("hectopascal", "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); return hPa;}
|
||||
static const CPressureUnit& hPa() { static CPressureUnit hPa("hectopascal", "hPa", true, CMeasurementPrefix::h().getFactor(), CMeasurementPrefix::h()); return hPa;}
|
||||
/*!
|
||||
* \brief Pounds per square inch
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& psi() { static CPressureUnit psi("pounds per square inch", "psi", false, 6894.8, CMeasurementPrefix::One(), 2); return psi;}
|
||||
static const CPressureUnit& psi() { static CPressureUnit psi("pounds per square inch", "psi", false, 6894.8, CMeasurementPrefix::One(), 2); return psi;}
|
||||
/*!
|
||||
* \brief Bar
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& bar() { static CPressureUnit bar("bar", "bar", false, 1E5);return bar;}
|
||||
static const CPressureUnit& bar() { static CPressureUnit bar("bar", "bar", false, 1E5);return bar;}
|
||||
/*!
|
||||
* \brief Millibar, actually the same as hPa
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& mbar() { static CPressureUnit bar("bar", "bar", false, 1E2);return bar;}
|
||||
static const CPressureUnit& mbar() { static CPressureUnit bar("bar", "bar", false, 1E2);return bar;}
|
||||
/*!
|
||||
* \brief Inch of mercury at 0°C
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& inHg() { static CPressureUnit inhg("Inch of mercury 0°C", "inHg", false, 3386.389);return inhg;}
|
||||
static const CPressureUnit& inHg() { static CPressureUnit inhg("Inch of mercury 0°C", "inHg", false, 3386.389);return inhg;}
|
||||
/*!
|
||||
* \brief Inch of mercury for flight level 29,92inHg = 1013,25mbar = 1013,25hPa
|
||||
* \return
|
||||
*/
|
||||
static CPressureUnit& inHgFL() { static CPressureUnit inhg("Inch of mercury ", "inHg", false, 3386.5307486631);return inhg;}
|
||||
static const CPressureUnit& inHgFL() { static CPressureUnit inhg("Inch of mercury ", "inHg", false, 3386.5307486631);return inhg;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -93,16 +96,20 @@ public:
|
||||
* \param unit
|
||||
*/
|
||||
CPressure(double value, const CPressureUnit &unit = CPressureUnit::Pa());
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
*/
|
||||
virtual ~CPressure();
|
||||
/*!
|
||||
* \brief Unit of the distance
|
||||
* \return
|
||||
*/
|
||||
CPressureUnit getUnit() const { return this->_unit; }
|
||||
CPressureUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CPressureUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CPressureUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
};
|
||||
} // namespace blackCore
|
||||
#endif // PQPRESSURE_H
|
||||
|
||||
@@ -10,13 +10,13 @@ CSpeed::CSpeed() : CPhysicalQuantity(0, CSpeedUnit::m_s(), CSpeedUnit::m_s())
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
CSpeed::CSpeed(const CPhysicalQuantity &speed): CPhysicalQuantity(speed)
|
||||
{
|
||||
//void
|
||||
}
|
||||
///**
|
||||
// * Constructor
|
||||
// */
|
||||
//CSpeed::CSpeed(const CPhysicalQuantity &speed): CPhysicalQuantity(speed)
|
||||
//{
|
||||
// //void
|
||||
//}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -34,5 +34,12 @@ CSpeed::CSpeed(double value, const CSpeedUnit &unit) : CPhysicalQuantity(value,
|
||||
// void
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructor
|
||||
*/
|
||||
CSpeed::~CSpeed()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -33,27 +33,27 @@ public:
|
||||
* \brief Meter/second m/s
|
||||
* \return
|
||||
*/
|
||||
static CSpeedUnit& m_s() { static CSpeedUnit ms("meter/second", "m/s", true, false); return ms;}
|
||||
static const CSpeedUnit& m_s() { static CSpeedUnit ms("meter/second", "m/s", true, false); return ms;}
|
||||
/*!
|
||||
* \brief Nautical miles per hour NM/h
|
||||
* \return
|
||||
*/
|
||||
static CSpeedUnit& NM_h() { static CSpeedUnit NMh("nautical miles/hour", "NM/h", false, false, 1852.0/3600.0, CMeasurementPrefix::One(), 1);return NMh;}
|
||||
static const CSpeedUnit& NM_h() { static CSpeedUnit NMh("nautical miles/hour", "NM/h", false, false, 1852.0/3600.0, CMeasurementPrefix::One(), 1);return NMh;}
|
||||
/*!
|
||||
* \brief Feet/second ft/s
|
||||
* \return
|
||||
*/
|
||||
static CSpeedUnit& ft_s() { static CSpeedUnit fts("feet/seconds", "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); return fts;}
|
||||
static const CSpeedUnit& ft_s() { static CSpeedUnit fts("feet/seconds", "ft/s", false, false, 0.3048, CMeasurementPrefix::One(), 0); return fts;}
|
||||
/*!
|
||||
* \brief Feet/min ft/min
|
||||
* \return
|
||||
*/
|
||||
static CSpeedUnit& ft_min() { static CSpeedUnit ftmin("feet/minute", "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); return ftmin;}
|
||||
static const CSpeedUnit& ft_min() { static CSpeedUnit ftmin("feet/minute", "ft/min", false, false, 0.3048 / 60.0, CMeasurementPrefix::One(), 0); return ftmin;}
|
||||
/*!
|
||||
* \brief Kilometer/hour km/h
|
||||
* \return
|
||||
*/
|
||||
static CSpeedUnit& km_h() { static CSpeedUnit kmh("kilometer/hour", "km/h", false, false, 1.0/3.6, CMeasurementPrefix::One(), 1);return kmh;}
|
||||
static const CSpeedUnit& km_h() { static CSpeedUnit kmh("kilometer/hour", "km/h", false, false, 1.0/3.6, CMeasurementPrefix::One(), 1);return kmh;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -62,15 +62,17 @@ public:
|
||||
*/
|
||||
class CSpeed : public CPhysicalQuantity
|
||||
{
|
||||
friend class CSpeedUnit;
|
||||
private:
|
||||
/**
|
||||
*\brief Downcast copy constructor, allows casting units
|
||||
*/
|
||||
CSpeed(const CPhysicalQuantity &speed);
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
CSpeed();
|
||||
/**
|
||||
*\brief downcast copy constructor
|
||||
*/
|
||||
CSpeed(const CPhysicalQuantity &speed);
|
||||
/*!
|
||||
* \brief Init by int value
|
||||
* \param value
|
||||
@@ -83,16 +85,20 @@ public:
|
||||
* \param unit
|
||||
*/
|
||||
CSpeed(double value, const CSpeedUnit &unit = CSpeedUnit::m_s());
|
||||
/*!
|
||||
* \brief Destructor
|
||||
*/
|
||||
virtual ~CSpeed();
|
||||
/*!
|
||||
* \brief Unit of the distance
|
||||
* \return
|
||||
*/
|
||||
CSpeedUnit getUnit() const { return this->_unit; }
|
||||
CSpeedUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CSpeedUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CSpeedUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace BlackMisc {
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
CTemperature::CTemperature(): CPhysicalQuantity(0, CTemperatureUnit::K(),CTemperatureUnit::K())
|
||||
CTemperature::CTemperature(): CPhysicalQuantity(0, CTemperatureUnit::K(),CTemperatureUnit::K(), CTemperature::temperaturUnitConverter)
|
||||
{
|
||||
this->setUnitValue(this->unitValueToDouble()); // I have to recall, since virtual method overriding does not work in constructor
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,53 +15,62 @@ CTemperature::CTemperature(): CPhysicalQuantity(0, CTemperatureUnit::K(),CTemper
|
||||
*/
|
||||
CTemperature::CTemperature(const CPhysicalQuantity &temperature): CPhysicalQuantity(temperature)
|
||||
{
|
||||
this->setUnitValue(this->unitValueToDouble()); // I have to recall, since virtual method overriding does not work in constructor
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
CTemperature::CTemperature(qint32 value, const CTemperatureUnit &unit) : CPhysicalQuantity(value, unit, CTemperatureUnit::K())
|
||||
CTemperature::CTemperature(qint32 value, const CTemperatureUnit &unit) : CPhysicalQuantity(value, unit, CTemperatureUnit::K(), CTemperature::temperaturUnitConverter)
|
||||
{
|
||||
this->setUnitValue(value); // I have to recall, since virtual method overriding does not work in constructor
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
CTemperature::CTemperature(double value, const CTemperatureUnit &unit) : CPhysicalQuantity(value, unit, CTemperatureUnit::K())
|
||||
CTemperature::CTemperature(double value, const CTemperatureUnit &unit) : CPhysicalQuantity(value, unit, CTemperatureUnit::K(), CTemperature::temperaturUnitConverter)
|
||||
{
|
||||
this->setUnitValue(value); // I have to recall, since virtual method overriding does not work in constructor
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden specializedmethodfortemperture
|
||||
* Destructor
|
||||
*/
|
||||
double CTemperature::calculateValueInOtherUnit(const CMeasurementUnit &otherUnit) const
|
||||
CTemperature::~CTemperature()
|
||||
{
|
||||
if (this->getUnit()==otherUnit) return this->siBaseUnitValueToDouble();
|
||||
// void
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialized method for temperture
|
||||
*/
|
||||
double CTemperature::temperaturUnitConverter(const CPhysicalQuantity *quantity, const CMeasurementUnit &otherUnit)
|
||||
{
|
||||
CTemperature *me = (CTemperature*) quantity; // allow me access to protected
|
||||
if (me->_pUnit == otherUnit) return me->siBaseUnitValueToDouble();
|
||||
|
||||
double siValue;
|
||||
// I always convert via SI Unit, other I would need too many conversions
|
||||
if(otherUnit == this->_conversionSiUnit) {
|
||||
if(otherUnit == me->_pConversionSiUnit) {
|
||||
// here I expect a conversion to SI is required and not done yet
|
||||
if(this->_unit == CTemperatureUnit::C()) {
|
||||
siValue = this->unitValueToDouble() + 273.15;
|
||||
} else if(this->_unit == CTemperatureUnit::F()) {
|
||||
siValue = (this->unitValueToDouble() + 459.67) *5.0 / 9.0;
|
||||
if(me->_pUnit == CTemperatureUnit::C()) {
|
||||
siValue = quantity->unitValueToDouble() + 273.15;
|
||||
} else if(me->_pUnit == CTemperatureUnit::F()) {
|
||||
siValue = (me->unitValueToDouble() + 459.67) *5.0 / 9.0;
|
||||
} else{
|
||||
// TODO: EXCEPTION
|
||||
}
|
||||
} else {
|
||||
// here I expect the SI value is already set
|
||||
siValue = this->siBaseUnitValueToDouble();
|
||||
siValue = quantity->siBaseUnitValueToDouble();
|
||||
}
|
||||
|
||||
// from SI
|
||||
if (otherUnit == this->_conversionSiUnit) return siValue;
|
||||
if (otherUnit == me->_pConversionSiUnit) return siValue;
|
||||
if(otherUnit == CTemperatureUnit::C()) {
|
||||
return siValue - 273.15;
|
||||
} else if(this->_unit == CTemperatureUnit::F()) {
|
||||
} else if(me->_pUnit == CTemperatureUnit::F()) {
|
||||
return (siValue * 9.0 / 5.0) - 459.67;
|
||||
}
|
||||
// TODO: Exception
|
||||
|
||||
@@ -9,6 +9,13 @@ namespace BlackMisc {
|
||||
* \author KWB
|
||||
*/
|
||||
class CTemperatureUnit : public CMeasurementUnit {
|
||||
friend class CTemperature;
|
||||
private:
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CTemperatureUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
public:
|
||||
/*!
|
||||
* Constructor
|
||||
@@ -24,26 +31,21 @@ public:
|
||||
*/
|
||||
CTemperatureUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) :
|
||||
CMeasurementUnit(name, unitName, "temperature", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) {}
|
||||
/*!
|
||||
* Downcast copy constructor, allows to implement methods in base class
|
||||
* \param otherUnit
|
||||
*/
|
||||
CTemperatureUnit(const CMeasurementUnit &otherUnit) : CMeasurementUnit(otherUnit) {}
|
||||
/*!
|
||||
* \brief Kelvin
|
||||
* \return
|
||||
*/
|
||||
static CTemperatureUnit& K() { static CTemperatureUnit K("Kelvin", "K", true, true); return K;}
|
||||
static const CTemperatureUnit& K() { static CTemperatureUnit K("Kelvin", "K", true, true); return K;}
|
||||
/*!
|
||||
* \brief Centigrade C
|
||||
* \return
|
||||
*/
|
||||
static CTemperatureUnit& C() { static CTemperatureUnit C("centigrade", "°C", false, false);return C;}
|
||||
static const CTemperatureUnit& C() { static CTemperatureUnit C("centigrade", "°C", false, false);return C;}
|
||||
/*!
|
||||
* \brief Fahrenheit F
|
||||
* \return
|
||||
*/
|
||||
static CTemperatureUnit& F() { static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0/9.0);return F;}
|
||||
static const CTemperatureUnit& F() { static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0/9.0);return F;}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -52,14 +54,14 @@ public:
|
||||
*/
|
||||
class CTemperature : public CPhysicalQuantity
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
/*!
|
||||
* Specific method for temperature, a normal factor conversion is not sufficient.
|
||||
* \brief Convert into another temperature unit
|
||||
* \param quantity
|
||||
* \param otherUnit
|
||||
* \return
|
||||
*/
|
||||
virtual double calculateValueInOtherUnit(const CMeasurementUnit &otherUnit) const;
|
||||
|
||||
static double temperaturUnitConverter(const CPhysicalQuantity *quantity, const CMeasurementUnit &otherUnit);
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
@@ -81,16 +83,20 @@ public:
|
||||
* \param unit
|
||||
*/
|
||||
CTemperature(double value, const CTemperatureUnit &unit = CTemperatureUnit::K());
|
||||
/*!
|
||||
* \brief Destructor
|
||||
*/
|
||||
virtual ~CTemperature();
|
||||
/*!
|
||||
* \brief Unit of the temperature
|
||||
* \return
|
||||
*/
|
||||
CTemperatureUnit getUnit() const { return this->_unit; }
|
||||
CTemperatureUnit getUnit() const { return this->_pUnit; }
|
||||
/*!
|
||||
* \brief Conversion SI unit
|
||||
* \return
|
||||
*/
|
||||
CTemperatureUnit getConversionSiUnit() const { return this->_conversionSiUnit; }
|
||||
CTemperatureUnit getConversionSiUnit() const { return this->_pConversionSiUnit; }
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user