diff --git a/src/blackmisc/aviation/callsignobjectlist.h b/src/blackmisc/aviation/callsignobjectlist.h index 1049932e2..f6a15819a 100644 --- a/src/blackmisc/aviation/callsignobjectlist.h +++ b/src/blackmisc/aviation/callsignobjectlist.h @@ -108,12 +108,12 @@ namespace BlackMisc CONTAINER &container(); }; - extern template class ICallsignObjectList; - extern template class ICallsignObjectList; - extern template class ICallsignObjectList; - extern template class ICallsignObjectList; - extern template class ICallsignObjectList; - extern template class ICallsignObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ICallsignObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ICallsignObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ICallsignObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ICallsignObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ICallsignObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ICallsignObjectList; } //namespace } // namespace diff --git a/src/blackmisc/aviation/modulator.cpp b/src/blackmisc/aviation/modulator.cpp index c83ca71ca..dd3819d9e 100644 --- a/src/blackmisc/aviation/modulator.cpp +++ b/src/blackmisc/aviation/modulator.cpp @@ -23,6 +23,12 @@ namespace BlackMisc namespace Aviation { + template + bool CModulator::isDefaultValue() const + { + return (this->m_frequencyActive == FrequencyNotSet()); + } + template void CModulator::toggleActiveStandby() { @@ -31,6 +37,66 @@ namespace BlackMisc this->m_frequencyStandby = a; } + template + BlackMisc::PhysicalQuantities::CFrequency CModulator::getFrequencyActive() const + { + return this->m_frequencyActive; + } + + template + BlackMisc::PhysicalQuantities::CFrequency CModulator::getFrequencyStandby() const + { + return this->m_frequencyStandby; + } + + template + void CModulator::setFrequencyActive(const BlackMisc::PhysicalQuantities::CFrequency &frequency) + { + this->m_frequencyActive = frequency; + } + + template + void CModulator::setFrequencyStandby(const BlackMisc::PhysicalQuantities::CFrequency &frequency) + { + this->m_frequencyStandby = frequency; + } + + template + qint32 CModulator::getVolumeOutput() const + { + return this->m_volumeOutput; + } + + template + qint32 CModulator::getVolumeInput() const + { + return this->m_volumeInput; + } + + template + void CModulator::setVolumeOutput(qint32 volume) + { + this->m_volumeOutput = volume; + } + + template + void CModulator::setVolumeInput(qint32 volume) + { + this->m_volumeInput = volume; + } + + template + bool CModulator::isEnabled() const + { + return this->m_enabled; + } + + template + void CModulator::setEnabled(bool enable) + { + this->m_enabled = enable; + } + template CVariant CModulator::propertyByIndex(const CPropertyIndex &index) const { @@ -85,6 +151,113 @@ namespace BlackMisc } } + template + CModulator::CModulator() : + CModulator::CValueObject("default") {} + + template + CModulator::CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency) : + CModulator::CValueObject(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency) {} + + template + QString CModulator::convertToQString(bool i18n) const + { + QString s(this->getName()); + s.append(" Active: ").append(this->m_frequencyActive.valueRoundedWithUnit(3, i18n)); + s.append(" Standby: ").append(this->m_frequencyStandby.valueRoundedWithUnit(3, i18n)); + return s; + } + + template + void CModulator::setFrequencyActiveKHz(double frequencyKHz) + { + this->m_frequencyActive = BlackMisc::PhysicalQuantities::CFrequency(frequencyKHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz()); + } + + template + void CModulator::setFrequencyStandbyKHz(double frequencyKHz) + { + this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyKHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz()); + } + + + template + void CModulator::setFrequencyActiveMHz(double frequencyMHz) + { + frequencyMHz = Math::CMathUtils::round(frequencyMHz, 3); + this->m_frequencyActive = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); + } + + template + void CModulator::setFrequencyStandbyMHz(double frequencyMHz) + { + frequencyMHz = Math::CMathUtils::round(frequencyMHz, 3); + this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); + } + + template + const QString &CModulator::NameCom1() + { + static QString n("COM1"); + return n; + } + + template + const QString &CModulator::NameCom2() + { + static QString n("COM2"); + return n; + } + + template + const QString &CModulator::NameCom3() + { + static QString n("COM3"); + return n; + } + + template + const QString &CModulator::NameNav1() + { + static QString n("NAV1"); + return n; + } + + template + const QString &CModulator::NameNav2() + { + static QString n("NAV2"); + return n; + } + + template + const QString &CModulator::NameNav3() + { + static QString n("NAV3"); + return n; + } + + template + const QString &CModulator::NameAdf1() + { + static QString n("ADF1"); + return n; + } + + template + const QString &CModulator::NameAdf2() + { + static QString n("ADF2"); + return n; + } + + template + const BlackMisc::PhysicalQuantities::CFrequency &CModulator::FrequencyNotSet() + { + static BlackMisc::PhysicalQuantities::CFrequency f; + return f; + } + template AVIO const *CModulator::derived() const { diff --git a/src/blackmisc/aviation/modulator.h b/src/blackmisc/aviation/modulator.h index 9956c435a..148d934df 100644 --- a/src/blackmisc/aviation/modulator.h +++ b/src/blackmisc/aviation/modulator.h @@ -41,55 +41,40 @@ namespace BlackMisc }; //! Default value? - virtual bool isDefaultValue() const - { - return (this->m_frequencyActive == FrequencyNotSet()); - } + virtual bool isDefaultValue() const; //! Toggle active and standby frequencies void toggleActiveStandby(); //! Active frequency - BlackMisc::PhysicalQuantities::CFrequency getFrequencyActive() const - { - return this->m_frequencyActive; - } + BlackMisc::PhysicalQuantities::CFrequency getFrequencyActive() const; //! Standby frequency - BlackMisc::PhysicalQuantities::CFrequency getFrequencyStandby() const - { - return this->m_frequencyStandby; - } + BlackMisc::PhysicalQuantities::CFrequency getFrequencyStandby() const; //! Set active frequency - virtual void setFrequencyActive(const BlackMisc::PhysicalQuantities::CFrequency &frequency) - { - this->m_frequencyActive = frequency; - } + virtual void setFrequencyActive(const BlackMisc::PhysicalQuantities::CFrequency &frequency); //! Set standby frequency - virtual void setFrequencyStandby(const BlackMisc::PhysicalQuantities::CFrequency &frequency) - { - this->m_frequencyStandby = frequency; - } + virtual void setFrequencyStandby(const BlackMisc::PhysicalQuantities::CFrequency &frequency); //! Output volume 0..100 - qint32 getVolumeOutput() const { return this->m_volumeOutput; } + qint32 getVolumeOutput() const; //! Input volume 0..100 - qint32 getVolumeInput() const { return this->m_volumeInput; } + qint32 getVolumeInput() const; //! Output volume 0.100 - void setVolumeOutput(qint32 volume) { this->m_volumeOutput = volume; } + void setVolumeOutput(qint32 volume); //! Input volume 0..100 - void setVolumeInput(qint32 volume) { this->m_volumeInput = volume; } + void setVolumeInput(qint32 volume); //! Enabled? - bool isEnabled() const { return this->m_enabled;} + bool isEnabled() const; //! Enabled? - void setEnabled(bool enable) { this->m_enabled = enable;} + void setEnabled(bool enable); //! \copydoc CValueObject::propertyByIndex virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override; @@ -99,110 +84,52 @@ namespace BlackMisc protected: //! Default constructor - CModulator() : - CModulator::CValueObject("default") {} + CModulator(); //! Constructor - CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency) : - CModulator::CValueObject(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency) {} + CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency); //! \copydoc CValueObject::convertToQString - virtual QString convertToQString(bool i18n = false) const override - { - QString s(this->getName()); - s.append(" Active: ").append(this->m_frequencyActive.valueRoundedWithUnit(3, i18n)); - s.append(" Standby: ").append(this->m_frequencyStandby.valueRoundedWithUnit(3, i18n)); - return s; - } + virtual QString convertToQString(bool i18n = false) const override; //! Set active frequency - void setFrequencyActiveKHz(double frequencyKHz) - { - this->m_frequencyActive = BlackMisc::PhysicalQuantities::CFrequency(frequencyKHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz()); - } + void setFrequencyActiveKHz(double frequencyKHz); //! Set standby frequency - void setFrequencyStandbyKHz(double frequencyKHz) - { - this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyKHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz()); - } + void setFrequencyStandbyKHz(double frequencyKHz); //! Set active frequency - virtual void setFrequencyActiveMHz(double frequencyMHz) - { - frequencyMHz = Math::CMathUtils::round(frequencyMHz, 3); - this->m_frequencyActive = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); - } + virtual void setFrequencyActiveMHz(double frequencyMHz); //! Set standby frequency - virtual void setFrequencyStandbyMHz(double frequencyMHz) - { - frequencyMHz = Math::CMathUtils::round(frequencyMHz, 3); - this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); - } + virtual void setFrequencyStandbyMHz(double frequencyMHz); //! COM1 - static const QString &NameCom1() - { - static QString n("COM1"); - return n; - } + static const QString &NameCom1(); //! COM2 - static const QString &NameCom2() - { - static QString n("COM2"); - return n; - } + static const QString &NameCom2(); //! COM3 - static const QString &NameCom3() - { - static QString n("COM3"); - return n; - } + static const QString &NameCom3(); //! NAV1 - static const QString &NameNav1() - { - static QString n("NAV1"); - return n; - } + static const QString &NameNav1(); //! NAV2 - static const QString &NameNav2() - { - static QString n("NAV2"); - return n; - } + static const QString &NameNav2(); //! NAV3 - static const QString &NameNav3() - { - static QString n("NAV3"); - return n; - } + static const QString &NameNav3(); //! ADF1 - static const QString &NameAdf1() - { - static QString n("ADF1"); - return n; - } + static const QString &NameAdf1(); //! ADF2 - static const QString &NameAdf2() - { - static QString n("ADF2"); - return n; - } + static const QString &NameAdf2(); //! Frequency not set - static const BlackMisc::PhysicalQuantities::CFrequency &FrequencyNotSet() - { - static BlackMisc::PhysicalQuantities::CFrequency f; - return f; - } + static const BlackMisc::PhysicalQuantities::CFrequency &FrequencyNotSet(); private: BLACK_ENABLE_TUPLE_CONVERSION(CModulator) @@ -219,9 +146,9 @@ namespace BlackMisc AVIO *derived(); }; - extern template class CModulator; - extern template class CModulator; - extern template class CModulator; + extern template class BLACKMISC_EXPORT_TEMPLATE CModulator; + extern template class BLACKMISC_EXPORT_TEMPLATE CModulator; + extern template class BLACKMISC_EXPORT_TEMPLATE CModulator; } } diff --git a/src/blackmisc/blackmiscexport.h b/src/blackmisc/blackmiscexport.h index 9fc90d490..3bbf96a6a 100644 --- a/src/blackmisc/blackmiscexport.h +++ b/src/blackmisc/blackmiscexport.h @@ -24,4 +24,10 @@ # define BLACKMISC_EXPORT #endif -#endif // BLACKMISC_MACROS_H \ No newline at end of file +#if defined(Q_OS_WIN) && defined(Q_CC_GNU) +# define BLACKMISC_EXPORT_TEMPLATE BLACKMISC_EXPORT +#else +# define BLACKMISC_EXPORT_TEMPLATE +#endif + +#endif // BLACKMISC_MACROS_H diff --git a/src/blackmisc/geo/earthangle.cpp b/src/blackmisc/geo/earthangle.cpp index fee28e8fc..8c0c56def 100644 --- a/src/blackmisc/geo/earthangle.cpp +++ b/src/blackmisc/geo/earthangle.cpp @@ -17,7 +17,77 @@ namespace BlackMisc namespace Geo { - template LATorLON CEarthAngle::fromWgs84(const QString &wgsCoordinate) + template + CEarthAngle &CEarthAngle::operator +=(const CEarthAngle &latOrLon) + { + this->PhysicalQuantities::CAngle::operator +=(latOrLon); + return *this; + } + + template + CEarthAngle &CEarthAngle::operator -=(const CEarthAngle &latOrLon) + { + this->PhysicalQuantities::CAngle::operator -=(latOrLon); + return *this; + } + + template + CEarthAngle &CEarthAngle::operator *=(double multiply) + { + this->PhysicalQuantities::CAngle::operator *=(multiply); + return *this; + } + + template + bool CEarthAngle::operator >(const CEarthAngle &latOrLon) const + { + return this->PhysicalQuantities::CAngle::operator >(latOrLon); + } + + template + bool CEarthAngle::operator <(const CEarthAngle &latOrLon) const + { + return this->PhysicalQuantities::CAngle::operator >(latOrLon); + } + + template + bool CEarthAngle::operator <=(const CEarthAngle &latOrLon) const + { + return this->PhysicalQuantities::CAngle::operator <=(latOrLon); + } + + template + bool CEarthAngle::operator >=(const CEarthAngle &latOrLon) const + { + return this->PhysicalQuantities::CAngle::operator >=(latOrLon); + } + + template + LATorLON CEarthAngle::operator +(const CEarthAngle &latOrLon) const + { + LATorLON l(*this); + l += latOrLon; + return l; + } + + template + LATorLON CEarthAngle::operator -(const CEarthAngle &latOrLon) const + { + LATorLON l(*this); + l -= latOrLon; + return l; + } + + template + LATorLON CEarthAngle::operator *(double multiply) const + { + LATorLON l(*this); + l *= multiply; + return l; + } + + template + LATorLON CEarthAngle::fromWgs84(const QString &wgsCoordinate) { // http://www.regular-expressions.info/floatingpoint.html const QString wgs = wgsCoordinate.simplified().trimmed(); @@ -65,7 +135,35 @@ namespace BlackMisc return LATorLON(a); } - template CIcon CEarthAngle::toIcon() const + template + CEarthAngle::CEarthAngle() + : CEarthAngle::CValueObject(0.0, BlackMisc::PhysicalQuantities::CAngleUnit::deg()) + { } + + template + CEarthAngle::CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) + : CEarthAngle::CValueObject(value, unit) + { } + + template + CEarthAngle::CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle) + : CEarthAngle::CValueObject(angle) + { } + + template + QString CEarthAngle::convertToQString(bool i18n) const + { + return this->valueRoundedWithUnit(BlackMisc::PhysicalQuantities::CAngleUnit::deg(), 6, i18n); + } + + template + LATorLON const *CEarthAngle::derived() const { return static_cast(this); } + + template + LATorLON *CEarthAngle::derived() { return static_cast(this); } + + template + CIcon CEarthAngle::toIcon() const { return BlackMisc::CIconList::iconByIndex(CIcons::GeoPosition); } diff --git a/src/blackmisc/geo/earthangle.h b/src/blackmisc/geo/earthangle.h index bbad9ef85..0aa1ebcc2 100644 --- a/src/blackmisc/geo/earthangle.h +++ b/src/blackmisc/geo/earthangle.h @@ -37,73 +37,33 @@ namespace BlackMisc { public: //! Plus operator += - CEarthAngle &operator +=(const CEarthAngle &latOrLon) - { - this->PhysicalQuantities::CAngle::operator +=(latOrLon); - return *this; - } + CEarthAngle &operator +=(const CEarthAngle &latOrLon); //! Minus operator-= - CEarthAngle &operator -=(const CEarthAngle &latOrLon) - { - this->PhysicalQuantities::CAngle::operator -=(latOrLon); - return *this; - } + CEarthAngle &operator -=(const CEarthAngle &latOrLon); //! Multiply operator *= - CEarthAngle operator *=(double multiply) - { - this->PhysicalQuantities::CAngle::operator *=(multiply); - return *this; - } + CEarthAngle &operator *=(double multiply); //! Greater operator > - bool operator >(const CEarthAngle &latOrLon) const - { - return this->PhysicalQuantities::CAngle::operator >(latOrLon); - } - + bool operator >(const CEarthAngle &latOrLon) const; //! Less operator < - bool operator <(const CEarthAngle &latOrLon) const - { - return this->PhysicalQuantities::CAngle::operator >(latOrLon); - } + bool operator <(const CEarthAngle &latOrLon) const; //! Less equal operator <= - bool operator <=(const CEarthAngle &latOrLon) const - { - return this->PhysicalQuantities::CAngle::operator <=(latOrLon); - } + bool operator <=(const CEarthAngle &latOrLon) const; //! Greater equal operator >= - bool operator >=(const CEarthAngle &latOrLon) const - { - return this->PhysicalQuantities::CAngle::operator >=(latOrLon); - } + bool operator >=(const CEarthAngle &latOrLon) const; //! Plus operator + - LATorLON operator +(const CEarthAngle &latOrLon) const - { - LATorLON l(*this); - l += latOrLon; - return l; - } + LATorLON operator +(const CEarthAngle &latOrLon) const; //! Minus operator - - LATorLON operator -(const CEarthAngle &latOrLon) const - { - LATorLON l(*this); - l -= latOrLon; - return l; - } + LATorLON operator -(const CEarthAngle &latOrLon) const; //! Multiply operator * - LATorLON operator *(double multiply) const - { - LATorLON l(*this); - l *= multiply; - return l; - } + LATorLON operator *(double multiply) const; //! \copydoc CValueObject::toIcon CIcon toIcon() const override; @@ -117,30 +77,27 @@ namespace BlackMisc protected: //! Default constructor - CEarthAngle() : CEarthAngle::CValueObject(0.0, BlackMisc::PhysicalQuantities::CAngleUnit::deg()) {} + CEarthAngle(); //! Init by double value - CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle::CValueObject(value, unit) {} + CEarthAngle(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit); //! Init by CAngle value - CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle) : CEarthAngle::CValueObject(angle) {} + CEarthAngle(const BlackMisc::PhysicalQuantities::CAngle &angle); //! \copydoc CValueObject::convertToQString - virtual QString convertToQString(bool i18n = false) const override - { - return this->valueRoundedWithUnit(BlackMisc::PhysicalQuantities::CAngleUnit::deg(), 6, i18n); - } + virtual QString convertToQString(bool i18n = false) const override; private: //! Easy access to derived class (CRTP template parameter) - LATorLON const *derived() const { return static_cast(this); } + LATorLON const *derived() const; //! Easy access to derived class (CRTP template parameter) - LATorLON *derived() { return static_cast(this); } + LATorLON *derived(); }; - extern template class CEarthAngle; - extern template class CEarthAngle; + extern template class BLACKMISC_EXPORT_TEMPLATE CEarthAngle; + extern template class BLACKMISC_EXPORT_TEMPLATE CEarthAngle; } } diff --git a/src/blackmisc/geo/geoobjectlist.h b/src/blackmisc/geo/geoobjectlist.h index 1df2aabc1..51e13c795 100644 --- a/src/blackmisc/geo/geoobjectlist.h +++ b/src/blackmisc/geo/geoobjectlist.h @@ -61,10 +61,10 @@ namespace BlackMisc CONTAINER &container(); }; - extern template class IGeoObjectList; - extern template class IGeoObjectList; - extern template class IGeoObjectList; - extern template class IGeoObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectList; //! List of objects with geo coordinates. template @@ -92,10 +92,10 @@ namespace BlackMisc }; - extern template class IGeoObjectWithRelativePositionList; - extern template class IGeoObjectWithRelativePositionList; - extern template class IGeoObjectWithRelativePositionList; - extern template class IGeoObjectWithRelativePositionList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectWithRelativePositionList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectWithRelativePositionList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectWithRelativePositionList; + extern template class BLACKMISC_EXPORT_TEMPLATE IGeoObjectWithRelativePositionList; } //namespace } // namespace diff --git a/src/blackmisc/pq/physicalquantity.cpp b/src/blackmisc/pq/physicalquantity.cpp index bd5ccadaf..7820799e3 100644 --- a/src/blackmisc/pq/physicalquantity.cpp +++ b/src/blackmisc/pq/physicalquantity.cpp @@ -16,11 +16,46 @@ namespace BlackMisc namespace PhysicalQuantities { - template CPhysicalQuantity::CPhysicalQuantity(double value, const MU &unit) : + template + MU CPhysicalQuantity::getUnit() const + { + return this->m_unit; + } + + template + void CPhysicalQuantity::setUnit(const MU &unit) + { + this->m_unit = unit; + } + + template + void CPhysicalQuantity::setUnitBySymbol(const QString &unitName) + { + this->m_unit = CMeasurementUnit::unitFromSymbol(unitName); + } + + template + QString CPhysicalQuantity::getUnitSymbol() const { return this->m_unit.getSymbol(true); } + + template + CPhysicalQuantity::CPhysicalQuantity() : + m_value(0.0), m_unit(MU::nullUnit()) + { } + + template + CPhysicalQuantity::CPhysicalQuantity(double value, const MU &unit) : m_value(unit.isNull() ? 0.0 : value), m_unit(unit) { } - template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &other) const + template + CPhysicalQuantity::CPhysicalQuantity(const QString &unitString) : + m_value(0.0), m_unit(MU::nullUnit()) + { + this->parseFromString(unitString); + } + + template + bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &other) const { if (this == &other) return true; @@ -31,55 +66,94 @@ namespace BlackMisc return diff <= this->m_unit.getEpsilon(); } - template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &other) const + template + bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &other) const { return !((*this) == other); } - template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other) + template + CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &other) { this->m_value += other.value(this->m_unit); return *this; } - template PQ CPhysicalQuantity::operator +(const PQ &other) const + template + PQ CPhysicalQuantity::operator +(const PQ &other) const { PQ copy(other); copy += *this; return copy; } - template void CPhysicalQuantity::addValueSameUnit(double value) + template + void CPhysicalQuantity::addValueSameUnit(double value) { this->m_value += value; } - template void CPhysicalQuantity::substractValueSameUnit(double value) + template + void CPhysicalQuantity::substractValueSameUnit(double value) { this->m_value -= value; } - template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &other) + template + CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &other) { this->m_value -= other.value(this->m_unit); return *this; } - template PQ CPhysicalQuantity::operator -(const PQ &other) const + template + PQ CPhysicalQuantity::operator -(const PQ &other) const { PQ copy = *derived(); copy -= other; return copy; } - template void CPhysicalQuantity::marshallToDbus(QDBusArgument &argument) const + template + bool CPhysicalQuantity::isZeroEpsilonConsidered() const + { + return this->m_unit.isEpsilon(this->m_value); + } + + template + bool CPhysicalQuantity::isPositiveWithEpsilonConsidered() const + { + return !this->isZeroEpsilonConsidered() && this->m_value > 0; + } + + template + bool CPhysicalQuantity::isNegativeWithEpsilonConsidered() const + { + return !this->isZeroEpsilonConsidered() && this->m_value < 0; + } + + template + void CPhysicalQuantity::makePositive() + { + if (this->m_value < 0) { this->m_value *= -1.0; } + } + + template + void CPhysicalQuantity::makeNegative() + { + if (this->m_value > 0) { this->m_value *= -1.0; } + } + + template + void CPhysicalQuantity::marshallToDbus(QDBusArgument &argument) const { argument << this->value(UnitClass::defaultUnit()); argument << this->m_value; argument << this->m_unit; } - template void CPhysicalQuantity::unmarshallFromDbus(const QDBusArgument &argument) + template + void CPhysicalQuantity::unmarshallFromDbus(const QDBusArgument &argument) { double ignore; argument >> ignore; @@ -87,33 +161,38 @@ namespace BlackMisc argument >> this->m_unit; } - template CPhysicalQuantity &CPhysicalQuantity::operator *=(double factor) + template + CPhysicalQuantity &CPhysicalQuantity::operator *=(double factor) { this->m_value *= factor; return *this; } - template PQ CPhysicalQuantity::operator *(double factor) const + template + PQ CPhysicalQuantity::operator *(double factor) const { PQ copy = *derived(); copy *= factor; return copy; } - template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divisor) + template + CPhysicalQuantity &CPhysicalQuantity::operator /=(double divisor) { this->m_value /= divisor; return *this; } - template PQ CPhysicalQuantity::operator /(double divisor) const + template + PQ CPhysicalQuantity::operator /(double divisor) const { PQ copy = *derived(); copy /= divisor; return copy; } - template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &other) const + template + bool CPhysicalQuantity::operator <(const CPhysicalQuantity &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 bool CPhysicalQuantity::operator >(const CPhysicalQuantity &other) const + template + bool CPhysicalQuantity::operator >(const CPhysicalQuantity &other) const { return other < *this; } - template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &other) const + template + bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &other) const { if (*this == other) return true; return *this > other; } - template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &other) const + template + bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &other) const { if (*this == other) return true; return *this < other; } - template PQ &CPhysicalQuantity::switchUnit(const MU &newUnit) + template + PQ &CPhysicalQuantity::switchUnit(const MU &newUnit) { if (this->m_unit != newUnit) { @@ -148,38 +231,82 @@ namespace BlackMisc return *derived(); } - template void CPhysicalQuantity::setValueSameUnit(double baseValue) + template + bool CPhysicalQuantity::isNull() const + { + return this->m_unit.isNull(); + } + + template + void CPhysicalQuantity::setNull() + { + this->m_unit = MU::nullUnit(); + } + + template + double CPhysicalQuantity::value() const + { + if (this->isNull()) + { + return 0.0; + } + return this->m_value; + } + + template + void CPhysicalQuantity::setCurrentUnitValue(double value) + { + if (!this->isNull()) + { + this->m_value = value; + } + } + + template + void CPhysicalQuantity::setValueSameUnit(double baseValue) { this->m_value = baseValue; } - template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const + template + QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits, bool i18n) const { return unit.makeRoundedQStringWithUnit(this->value(unit), digits, i18n); } - template double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const + template + QString CPhysicalQuantity::valueRoundedWithUnit(int digits, bool i18n) const + { + return this->valueRoundedWithUnit(this->m_unit, digits, i18n); + } + + template + double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const { return unit.roundValue(this->value(unit), digits); } - template int CPhysicalQuantity::valueInteger(const MU &unit) const + template + int CPhysicalQuantity::valueInteger(const MU &unit) const { double v = unit.roundValue(this->value(unit), 0); return static_cast(v); } - template double CPhysicalQuantity::valueRounded(int digits) const + template + double CPhysicalQuantity::valueRounded(int digits) const { return this->valueRounded(this->m_unit, digits); } - template double CPhysicalQuantity::value(const MU &unit) const + template + double CPhysicalQuantity::value(const MU &unit) const { return unit.convertFrom(this->m_value, this->m_unit); } - template QString CPhysicalQuantity::convertToQString(bool i18n) const + template + QString CPhysicalQuantity::convertToQString(bool i18n) const { if (this->isNull()) { @@ -188,7 +315,8 @@ namespace BlackMisc return this->valueRoundedWithUnit(this->getUnit(), -1, i18n); } - template uint CPhysicalQuantity::getValueHash() const + template + uint CPhysicalQuantity::getValueHash() const { QList hashs; // there is no double qHash @@ -197,7 +325,8 @@ namespace BlackMisc return BlackMisc::calculateHash(hashs, "PQ"); } - template QJsonObject CPhysicalQuantity::toJson() const + template + QJsonObject CPhysicalQuantity::toJson() const { QJsonObject json; json.insert("value", QJsonValue(this->m_value)); @@ -205,24 +334,28 @@ namespace BlackMisc return json; } - template void CPhysicalQuantity::convertFromJson(const QJsonObject &json) + template + void CPhysicalQuantity::convertFromJson(const QJsonObject &json) { const QString unitSymbol = json.value("unit").toString(); this->setUnitBySymbol(unitSymbol); this->m_value = json.value("value").toDouble(); } - template void CPhysicalQuantity::parseFromString(const QString &value, CPqString::SeparatorMode mode) + template + void CPhysicalQuantity::parseFromString(const QString &value, CPqString::SeparatorMode mode) { *this = CPqString::parse(value, mode); } - template void CPhysicalQuantity::parseFromString(const QString &value) + template + void CPhysicalQuantity::parseFromString(const QString &value) { *this = CPqString::parse(value, CPqString::SeparatorsCLocale); } - template CVariant CPhysicalQuantity::propertyByIndex(const CPropertyIndex &index) const + template + CVariant CPhysicalQuantity::propertyByIndex(const CPropertyIndex &index) const { if (index.isMyself()) { return this->toCVariant(); } ColumnIndex i = index.frontCasted(); @@ -247,7 +380,8 @@ namespace BlackMisc } } - template void CPhysicalQuantity::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) + template + void CPhysicalQuantity::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) { if (index.isMyself()) { @@ -276,7 +410,8 @@ namespace BlackMisc } } - template int CPhysicalQuantity::compareImpl(const PQ &a, const PQ &b) + template + int CPhysicalQuantity::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 + PQ const *CPhysicalQuantity::derived() const + { + return static_cast(this); + } + + template + PQ *CPhysicalQuantity::derived() + { + return static_cast(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; diff --git a/src/blackmisc/pq/physicalquantity.h b/src/blackmisc/pq/physicalquantity.h index ec095027b..0a182a3b5 100644 --- a/src/blackmisc/pq/physicalquantity.h +++ b/src/blackmisc/pq/physicalquantity.h @@ -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(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(this); } + PQ const *derived() const; //! Easy access to derived class (CRTP template parameter) - PQ *derived() { return static_cast(this); } + PQ *derived(); }; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; - extern template class CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; + extern template class BLACKMISC_EXPORT_TEMPLATE CPhysicalQuantity; } } diff --git a/src/blackmisc/timestampobjectlist.h b/src/blackmisc/timestampobjectlist.h index e3134606f..f38336702 100644 --- a/src/blackmisc/timestampobjectlist.h +++ b/src/blackmisc/timestampobjectlist.h @@ -101,10 +101,10 @@ namespace BlackMisc CONTAINER &container(); }; - extern template class ITimestampObjectList; - extern template class ITimestampObjectList; - extern template class ITimestampObjectList; - extern template class ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; } //namespace