refs #403 workaround different extern template behaviour with MinGW

This commit is contained in:
Roland Winklmeier
2015-04-19 22:25:31 +02:00
parent a089d3641d
commit d0302c275a
10 changed files with 555 additions and 281 deletions

View File

@@ -16,11 +16,46 @@ namespace BlackMisc
namespace PhysicalQuantities
{
template <class MU, class PQ> CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(double value, const MU &unit) :
template <class MU, class PQ>
MU CPhysicalQuantity<MU, PQ>::getUnit() const
{
return this->m_unit;
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::setUnit(const MU &unit)
{
this->m_unit = unit;
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::setUnitBySymbol(const QString &unitName)
{
this->m_unit = CMeasurementUnit::unitFromSymbol<MU>(unitName);
}
template <class MU, class PQ>
QString CPhysicalQuantity<MU, PQ>::getUnitSymbol() const { return this->m_unit.getSymbol(true); }
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity() :
m_value(0.0), m_unit(MU::nullUnit())
{ }
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(double value, const MU &unit) :
m_value(unit.isNull() ? 0.0 : value), m_unit(unit)
{ }
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator ==(const CPhysicalQuantity<MU, PQ> &other) const
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ>::CPhysicalQuantity(const QString &unitString) :
m_value(0.0), m_unit(MU::nullUnit())
{
this->parseFromString(unitString);
}
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::operator ==(const CPhysicalQuantity<MU, PQ> &other) const
{
if (this == &other) return true;
@@ -31,55 +66,94 @@ namespace BlackMisc
return diff <= this->m_unit.getEpsilon();
}
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator !=(const CPhysicalQuantity<MU, PQ> &other) const
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::operator !=(const CPhysicalQuantity<MU, PQ> &other) const
{
return !((*this) == other);
}
template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator +=(const CPhysicalQuantity<MU, PQ> &other)
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator +=(const CPhysicalQuantity<MU, PQ> &other)
{
this->m_value += other.value(this->m_unit);
return *this;
}
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator +(const PQ &other) const
template <class MU, class PQ>
PQ CPhysicalQuantity<MU, PQ>::operator +(const PQ &other) const
{
PQ copy(other);
copy += *this;
return copy;
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::addValueSameUnit(double value)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::addValueSameUnit(double value)
{
this->m_value += value;
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::substractValueSameUnit(double value)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::substractValueSameUnit(double value)
{
this->m_value -= value;
}
template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator -=(const CPhysicalQuantity<MU, PQ> &other)
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator -=(const CPhysicalQuantity<MU, PQ> &other)
{
this->m_value -= other.value(this->m_unit);
return *this;
}
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator -(const PQ &other) const
template <class MU, class PQ>
PQ CPhysicalQuantity<MU, PQ>::operator -(const PQ &other) const
{
PQ copy = *derived();
copy -= other;
return copy;
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::marshallToDbus(QDBusArgument &argument) const
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::isZeroEpsilonConsidered() const
{
return this->m_unit.isEpsilon(this->m_value);
}
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::isPositiveWithEpsilonConsidered() const
{
return !this->isZeroEpsilonConsidered() && this->m_value > 0;
}
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::isNegativeWithEpsilonConsidered() const
{
return !this->isZeroEpsilonConsidered() && this->m_value < 0;
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::makePositive()
{
if (this->m_value < 0) { this->m_value *= -1.0; }
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::makeNegative()
{
if (this->m_value > 0) { this->m_value *= -1.0; }
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::marshallToDbus(QDBusArgument &argument) const
{
argument << this->value(UnitClass::defaultUnit());
argument << this->m_value;
argument << this->m_unit;
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::unmarshallFromDbus(const QDBusArgument &argument)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::unmarshallFromDbus(const QDBusArgument &argument)
{
double ignore;
argument >> ignore;
@@ -87,33 +161,38 @@ namespace BlackMisc
argument >> this->m_unit;
}
template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator *=(double factor)
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator *=(double factor)
{
this->m_value *= factor;
return *this;
}
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator *(double factor) const
template <class MU, class PQ>
PQ CPhysicalQuantity<MU, PQ>::operator *(double factor) const
{
PQ copy = *derived();
copy *= factor;
return copy;
}
template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator /=(double divisor)
template <class MU, class PQ>
CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::operator /=(double divisor)
{
this->m_value /= divisor;
return *this;
}
template <class MU, class PQ> PQ CPhysicalQuantity<MU, PQ>::operator /(double divisor) const
template <class MU, class PQ>
PQ CPhysicalQuantity<MU, PQ>::operator /(double divisor) const
{
PQ copy = *derived();
copy /= divisor;
return copy;
}
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator <(const CPhysicalQuantity<MU, PQ> &other) const
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::operator <(const CPhysicalQuantity<MU, PQ> &other) const
{
if (*this == other) return false;
if (this->isNull() || other.isNull()) return false;
@@ -121,24 +200,28 @@ namespace BlackMisc
return (this->m_value < other.value(this->m_unit));
}
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator >(const CPhysicalQuantity<MU, PQ> &other) const
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::operator >(const CPhysicalQuantity<MU, PQ> &other) const
{
return other < *this;
}
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator >=(const CPhysicalQuantity<MU, PQ> &other) const
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::operator >=(const CPhysicalQuantity<MU, PQ> &other) const
{
if (*this == other) return true;
return *this > other;
}
template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator <=(const CPhysicalQuantity<MU, PQ> &other) const
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::operator <=(const CPhysicalQuantity<MU, PQ> &other) const
{
if (*this == other) return true;
return *this < other;
}
template <class MU, class PQ> PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
template <class MU, class PQ>
PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
{
if (this->m_unit != newUnit)
{
@@ -148,38 +231,82 @@ namespace BlackMisc
return *derived();
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::setValueSameUnit(double baseValue)
template <class MU, class PQ>
bool CPhysicalQuantity<MU, PQ>::isNull() const
{
return this->m_unit.isNull();
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::setNull()
{
this->m_unit = MU::nullUnit();
}
template <class MU, class PQ>
double CPhysicalQuantity<MU, PQ>::value() const
{
if (this->isNull())
{
return 0.0;
}
return this->m_value;
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::setCurrentUnitValue(double value)
{
if (!this->isNull())
{
this->m_value = value;
}
}
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::setValueSameUnit(double baseValue)
{
this->m_value = baseValue;
}
template <class MU, class PQ> QString CPhysicalQuantity<MU, PQ>::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const
template <class MU, class PQ>
QString CPhysicalQuantity<MU, PQ>::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const
{
return unit.makeRoundedQStringWithUnit(this->value(unit), digits, i18n);
}
template <class MU, class PQ> double CPhysicalQuantity<MU, PQ>::valueRounded(const MU &unit, int digits) const
template <class MU, class PQ>
QString CPhysicalQuantity<MU, PQ>::valueRoundedWithUnit(int digits, bool i18n) const
{
return this->valueRoundedWithUnit(this->m_unit, digits, i18n);
}
template <class MU, class PQ>
double CPhysicalQuantity<MU, PQ>::valueRounded(const MU &unit, int digits) const
{
return unit.roundValue(this->value(unit), digits);
}
template <class MU, class PQ> int CPhysicalQuantity<MU, PQ>::valueInteger(const MU &unit) const
template <class MU, class PQ>
int CPhysicalQuantity<MU, PQ>::valueInteger(const MU &unit) const
{
double v = unit.roundValue(this->value(unit), 0);
return static_cast<int>(v);
}
template <class MU, class PQ> double CPhysicalQuantity<MU, PQ>::valueRounded(int digits) const
template <class MU, class PQ>
double CPhysicalQuantity<MU, PQ>::valueRounded(int digits) const
{
return this->valueRounded(this->m_unit, digits);
}
template <class MU, class PQ> double CPhysicalQuantity<MU, PQ>::value(const MU &unit) const
template <class MU, class PQ>
double CPhysicalQuantity<MU, PQ>::value(const MU &unit) const
{
return unit.convertFrom(this->m_value, this->m_unit);
}
template <class MU, class PQ> QString CPhysicalQuantity<MU, PQ>::convertToQString(bool i18n) const
template <class MU, class PQ>
QString CPhysicalQuantity<MU, PQ>::convertToQString(bool i18n) const
{
if (this->isNull())
{
@@ -188,7 +315,8 @@ namespace BlackMisc
return this->valueRoundedWithUnit(this->getUnit(), -1, i18n);
}
template <class MU, class PQ> uint CPhysicalQuantity<MU, PQ>::getValueHash() const
template <class MU, class PQ>
uint CPhysicalQuantity<MU, PQ>::getValueHash() const
{
QList<uint> hashs;
// there is no double qHash
@@ -197,7 +325,8 @@ namespace BlackMisc
return BlackMisc::calculateHash(hashs, "PQ");
}
template <class MU, class PQ> QJsonObject CPhysicalQuantity<MU, PQ>::toJson() const
template <class MU, class PQ>
QJsonObject CPhysicalQuantity<MU, PQ>::toJson() const
{
QJsonObject json;
json.insert("value", QJsonValue(this->m_value));
@@ -205,24 +334,28 @@ namespace BlackMisc
return json;
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::convertFromJson(const QJsonObject &json)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::convertFromJson(const QJsonObject &json)
{
const QString unitSymbol = json.value("unit").toString();
this->setUnitBySymbol(unitSymbol);
this->m_value = json.value("value").toDouble();
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value, CPqString::SeparatorMode mode)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value, CPqString::SeparatorMode mode)
{
*this = CPqString::parse<PQ>(value, mode);
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value)
{
*this = CPqString::parse<PQ>(value, CPqString::SeparatorsCLocale);
}
template <class MU, class PQ> CVariant CPhysicalQuantity<MU, PQ>::propertyByIndex(const CPropertyIndex &index) const
template <class MU, class PQ>
CVariant CPhysicalQuantity<MU, PQ>::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return this->toCVariant(); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
@@ -247,7 +380,8 @@ namespace BlackMisc
}
}
template <class MU, class PQ> void CPhysicalQuantity<MU, PQ>::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index)
template <class MU, class PQ>
void CPhysicalQuantity<MU, PQ>::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index)
{
if (index.isMyself())
{
@@ -276,7 +410,8 @@ namespace BlackMisc
}
}
template <class MU, class PQ> int CPhysicalQuantity<MU, PQ>::compareImpl(const PQ &a, const PQ &b)
template <class MU, class PQ>
int CPhysicalQuantity<MU, PQ>::compareImpl(const PQ &a, const PQ &b)
{
if (a.isNull() > b.isNull()) { return -1; }
if (a.isNull() < b.isNull()) { return 1; }
@@ -286,6 +421,18 @@ namespace BlackMisc
else { return 0; }
}
template <class MU, class PQ>
PQ const *CPhysicalQuantity<MU, PQ>::derived() const
{
return static_cast<PQ const *>(this);
}
template <class MU, class PQ>
PQ *CPhysicalQuantity<MU, PQ>::derived()
{
return static_cast<PQ *>(this);
}
// see here for the reason of thess forward instantiations
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
template class CPhysicalQuantity<CLengthUnit, CLength>;

View File

@@ -76,53 +76,37 @@ namespace BlackMisc
};
//! Unit
MU getUnit() const { return this->m_unit; }
MU getUnit() const;
/*!
* \brief Simply set unit, do no calclulate conversion
* \sa switchUnit
*/
void setUnit(const MU &unit) { this->m_unit = unit; }
void setUnit(const MU &unit);
//! Set unit by string
void setUnitBySymbol(const QString &unitName)
{
this->m_unit = CMeasurementUnit::unitFromSymbol<MU>(unitName);
}
void setUnitBySymbol(const QString &unitName);
//! Unit
QString getUnitSymbol() const { return this->m_unit.getSymbol(true); }
QString getUnitSymbol() const;
//! Change unit, and convert value to maintain the same quantity
PQ &switchUnit(const MU &newUnit);
//! Is quantity null?
bool isNull() const { return this->m_unit.isNull(); }
bool isNull() const;
//! Set null
void setNull() { this->m_unit = MU::nullUnit(); }
void setNull();
//! Value in given unit
double value(const MU &unit) const;
//! Value in current unit
double value() const
{
if (this->isNull())
{
return 0.0;
}
return this->m_value;
}
double value() const;
//! Set value in current unit
void setCurrentUnitValue(double value)
{
if (!this->isNull())
{
this->m_value = value;
}
}
void setCurrentUnitValue(double value);
//! Rounded value in given unit
double valueRounded(const MU &unit, int digits = -1) const;
@@ -137,10 +121,7 @@ namespace BlackMisc
QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const;
//! Value to QString with the current unit, e.g. "5.00m"
QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const
{
return this->valueRoundedWithUnit(this->m_unit, digits, i18n);
}
QString valueRoundedWithUnit(int digits = -1, bool i18n = false) const;
//! Change value without changing unit
void setValueSameUnit(double value);
@@ -197,31 +178,19 @@ namespace BlackMisc
PQ operator -(const PQ &other) const;
//! Quantity value <= epsilon
bool isZeroEpsilonConsidered() const { return this->m_unit.isEpsilon(this->m_value); }
bool isZeroEpsilonConsidered() const;
//! Value >= 0 epsilon considered
bool isPositiveWithEpsilonConsidered() const
{
return !this->isZeroEpsilonConsidered() && this->m_value > 0;
}
bool isPositiveWithEpsilonConsidered() const;
//! Value <= 0 epsilon considered
bool isNegativeWithEpsilonConsidered() const
{
return !this->isZeroEpsilonConsidered() && this->m_value < 0;
}
bool isNegativeWithEpsilonConsidered() const;
//! Make value always positive
void makePositive()
{
if (this->m_value < 0) { this->m_value *= -1.0; }
}
void makePositive();
//! Make value always negative
void makeNegative()
{
if (this->m_value > 0) { this->m_value *= -1.0; }
}
void makeNegative();
//! \copydoc CValueObject::marshallToDbus
virtual void marshallToDbus(QDBusArgument &argument) const override;
@@ -254,16 +223,13 @@ namespace BlackMisc
//! Default constructor
//! \todo Remove as part of MS' CValueObject refactoring
CPhysicalQuantity() : m_value(0.0), m_unit(MU::nullUnit()) {}
CPhysicalQuantity();
//! Constructor with double
CPhysicalQuantity(double value, const MU &unit);
//! Constructor by parsed string, e.g. 10m
CPhysicalQuantity(const QString &unitString) : m_value(0.0), m_unit(MU::nullUnit())
{
this->parseFromString(unitString);
}
CPhysicalQuantity(const QString &unitString);
//! \copydoc CValueObject::convertToQString
virtual QString convertToQString(bool i18n = false) const override;
@@ -279,21 +245,21 @@ namespace BlackMisc
static int compareImpl(const PQ &, const PQ &);
//! Easy access to derived class (CRTP template parameter)
PQ const *derived() const { return static_cast<PQ const *>(this); }
PQ const *derived() const;
//! Easy access to derived class (CRTP template parameter)
PQ *derived() { return static_cast<PQ *>(this); }
PQ *derived();
};
extern template class CPhysicalQuantity<CLengthUnit, CLength>;
extern template class CPhysicalQuantity<CPressureUnit, CPressure>;
extern template class CPhysicalQuantity<CFrequencyUnit, CFrequency>;
extern template class CPhysicalQuantity<CMassUnit, CMass>;
extern template class CPhysicalQuantity<CTemperatureUnit, CTemperature>;
extern template class CPhysicalQuantity<CSpeedUnit, CSpeed>;
extern template class CPhysicalQuantity<CAngleUnit, CAngle>;
extern template class CPhysicalQuantity<CTimeUnit, CTime>;
extern template class CPhysicalQuantity<CAccelerationUnit, CAcceleration>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CLengthUnit, CLength>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CPressureUnit, CPressure>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CFrequencyUnit, CFrequency>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CMassUnit, CMass>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CTemperatureUnit, CTemperature>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CSpeedUnit, CSpeed>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CAngleUnit, CAngle>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CTimeUnit, CTime>;
extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity<CAccelerationUnit, CAcceleration>;
}
}