From 9a87731944698dfd9002e2f40b597151abd67778 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 9 Apr 2013 02:00:38 +0200 Subject: [PATCH] Avionics classes for Transponder, ADF, changed namespace to 2ndlevel --- .../blackmiscquantities/samplesaviation.cpp | 24 +- samples/blackmiscquantities/samplesaviation.h | 7 +- .../samplesphysicalquantities.h | 2 +- src/blackmisc/avaltitude.cpp | 11 +- src/blackmisc/avaltitude.h | 23 +- src/blackmisc/avheading.cpp | 11 +- src/blackmisc/avheading.h | 21 +- src/blackmisc/aviation.h | 4 + src/blackmisc/avioadfsystem.h | 247 ++++++++++++++++ src/blackmisc/aviobase.h | 58 +++- src/blackmisc/aviocomsystem.h | 237 ++++++++++++--- src/blackmisc/aviomodulator.cpp | 27 +- src/blackmisc/aviomodulator.h | 112 +++++-- src/blackmisc/avionavsystem.h | 256 ++++++++++++++++ src/blackmisc/aviotransponder.cpp | 103 +++++++ src/blackmisc/aviotransponder.h | 275 ++++++++++++++++++ src/blackmisc/avtrack.cpp | 11 +- src/blackmisc/avtrack.h | 24 +- src/blackmisc/avverticalpositions.cpp | 34 ++- src/blackmisc/avverticalpositions.h | 26 +- src/blackmisc/blackmisc.h | 7 +- src/blackmisc/blackmisc.pro | 9 +- src/blackmisc/com_handler.h | 94 +++--- src/blackmisc/pqangle.h | 19 +- src/blackmisc/pqbase.cpp | 57 ++-- src/blackmisc/pqbase.h | 147 +++++++--- src/blackmisc/pqconstants.h | 56 +++- src/blackmisc/pqfrequency.h | 17 +- src/blackmisc/pqlength.h | 15 +- src/blackmisc/pqmass.h | 19 +- src/blackmisc/pqphysicalquantity.cpp | 106 ++++--- src/blackmisc/pqphysicalquantity.h | 66 ++++- src/blackmisc/pqpressure.h | 19 +- src/blackmisc/pqspeed.h | 11 +- src/blackmisc/pqtemperature.h | 16 +- src/blackmisc/pqtime.h | 12 +- src/blackmisc/pqunits.cpp | 21 +- src/blackmisc/pqunits.h | 247 ++++++++++++---- tests/blackmisc/testaviationbase.cpp | 36 ++- tests/blackmisc/testaviationbase.h | 10 +- .../blackmisc/testphysicalquantitiesbase.cpp | 5 + tests/blackmisc/testphysicalquantitiesbase.h | 7 +- 42 files changed, 2110 insertions(+), 399 deletions(-) create mode 100644 src/blackmisc/aviation.h create mode 100644 src/blackmisc/avioadfsystem.h create mode 100644 src/blackmisc/avionavsystem.h create mode 100644 src/blackmisc/aviotransponder.cpp create mode 100644 src/blackmisc/aviotransponder.h diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index 2e6aac4ed..1cd4cfc21 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -16,11 +16,33 @@ int CSamplesAviation::samples() CAviationVerticalPositions vp2 = vp1; qDebug() << vp1 << (vp1 == vp2) << (vp1 != vp2); - CComSystem c1 = CComSystem::getCom1Unit(125.3); + CComSystem c1 = CComSystem::getCom1System(125.3); qDebug() << c1; c1.setActiveUnicom(); qDebug() << c1; + if(!CComSystem::tryGetComSystem(c1, "Test", -1.0)) + qDebug() << c1 << "is reset to default as expected"; + else + qDebug() << "Something is utterly wrong here"; + + try{ + // uncomment to test assert + // CFrequency f1(-1.0, CFrequencyUnit::MHz()); + // c1 = CComSystem("ups", f1, f1); + // qDebug() << "Why do I get here??"; + } catch(std::range_error &ex) { + qDebug() << "As expected" << ex.what(); + } + + CNavSystem nav1; + CNavSystem::tryGetNav1System(nav1, 110.0); + qDebug() << nav1; + + CTransponder tr1("T1", 7000, CTransponder::StateStandby); + CTransponder tr2("T2", "4532", CTransponder::ModeMil3); + qDebug() << tr1 << tr2; + // bye return 0; } diff --git a/samples/blackmiscquantities/samplesaviation.h b/samples/blackmiscquantities/samplesaviation.h index 83e7817b3..5b475054b 100644 --- a/samples/blackmiscquantities/samplesaviation.h +++ b/samples/blackmiscquantities/samplesaviation.h @@ -5,8 +5,11 @@ #include "blackmisc/avverticalpositions.h" #include "blackmisc/pqconstants.h" #include "blackmisc/aviocomsystem.h" +#include "blackmisc/avionavsystem.h" +#include "blackmisc/aviotransponder.h" -using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; namespace BlackMiscTest { @@ -21,6 +24,6 @@ public: */ static int samples(); }; -} +} // namespace #endif diff --git a/samples/blackmiscquantities/samplesphysicalquantities.h b/samples/blackmiscquantities/samplesphysicalquantities.h index b7baac64a..fe1dc3121 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.h +++ b/samples/blackmiscquantities/samplesphysicalquantities.h @@ -5,7 +5,7 @@ #include "blackmisc/pqconstants.h" #include "blackmisc/debug.h" -using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; namespace BlackMiscTest { diff --git a/src/blackmisc/avaltitude.cpp b/src/blackmisc/avaltitude.cpp index 70ca59660..f6f70b75e 100644 --- a/src/blackmisc/avaltitude.cpp +++ b/src/blackmisc/avaltitude.cpp @@ -1,6 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "avaltitude.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace Aviation +{ /** * Own implementation for streaming @@ -40,3 +48,4 @@ bool CAltitude::operator !=(const CAltitude &otherAltitude) } } // namespace +} // namespace diff --git a/src/blackmisc/avaltitude.h b/src/blackmisc/avaltitude.h index 26071b8df..c744b0135 100644 --- a/src/blackmisc/avaltitude.h +++ b/src/blackmisc/avaltitude.h @@ -1,9 +1,19 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVALTITUDE_H #define AVALTITUDE_H - #include "blackmisc/pqlength.h" -namespace BlackMisc { +using BlackMisc::PhysicalQuantities::CLength; +using BlackMisc::PhysicalQuantities::CLengthUnit; + +namespace BlackMisc +{ +namespace Aviation +{ /*! * \brief Altitude as used in aviation, can be AGL or MSL Altitude @@ -75,14 +85,19 @@ public: * \brief AGL Above ground level? * \return */ - bool isAboveGroundLevel() const { return !this->m_msl; } + bool isAboveGroundLevel() const { + return !this->m_msl; + } /*! * \brief MSL Mean sea level? * \return */ - bool isMeanSeaLevel() const { return this->m_msl; } + bool isMeanSeaLevel() const { + return this->m_msl; + } }; +} // namespace } // namespace #endif // AVALTITUDE_H diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index 38f5ebbb7..e73b14a45 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -1,6 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "avheading.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace Aviation +{ /** * Own implementation for streaming @@ -40,3 +48,4 @@ bool CHeading::operator !=(const CHeading &otherHeading) } } // namespace +} // namespace diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 9903710f1..39fa8dccd 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -1,9 +1,19 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVHEADING_H #define AVHEADING_H #include "blackmisc/pqangle.h" -namespace BlackMisc { +using BlackMisc::PhysicalQuantities::CAngle; +using BlackMisc::PhysicalQuantities::CAngleUnit; +namespace BlackMisc +{ +namespace Aviation +{ /*! * \brief Heading as used in aviation, can be true or magnetic heading * \remarks Intentionally allowing +/- CAngle , and >= / <= CAngle. @@ -74,13 +84,18 @@ public: * \brief Magnetic heading? * \return */ - bool isMagneticHeading() const { return this->m_magnetic; } + bool isMagneticHeading() const { + return this->m_magnetic; + } /*! * \brief True heading? * \return */ - bool isTrueHeading() const { return !this->m_magnetic; } + bool isTrueHeading() const { + return !this->m_magnetic; + } }; +} // namespace } // namespace #endif // AVHEADING_H diff --git a/src/blackmisc/aviation.h b/src/blackmisc/aviation.h new file mode 100644 index 000000000..ab011d2d4 --- /dev/null +++ b/src/blackmisc/aviation.h @@ -0,0 +1,4 @@ +#ifndef AVIATION_H +#define AVIATION_H + +#endif // AVIATION_H diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h new file mode 100644 index 000000000..a7dd55389 --- /dev/null +++ b/src/blackmisc/avioadfsystem.h @@ -0,0 +1,247 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef AVIOADFSYSTEM_H +#define AVIOADFSYSTEM_H + +#include "blackmisc/aviomodulator.h" + +namespace BlackMisc +{ +namespace Aviation +{ + +/*! + * \brief ADF system ("for NDBs") + */ +class CAdfSystem : public CModulator +{ +private: + /*! + * \brief Valid civil aviation frequency? + * \param f + * \return + */ + bool isValidFrequency(CFrequency f) const { + double fr = f.valueRounded(CFrequencyUnit::kHz(), this->m_digits); + return fr >= 190.0 && fr <= 1750.0; + } + /*! + * \brief Constructor + * \param validate + * \param name + * \param activeFrequency + * \param standbyFrequency + * \param digits + * + */ + CAdfSystem(bool validate, const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits = 3): + CModulator(name, activeFrequency, standbyFrequency, digits) { + this->validate(validate); + } + +protected: + /*! + * \brief Are the set values valid / in range? + * \return + */ + bool validValues() const { + if (this->isDefaultValue()) return true; // special case + return + (this->isValidFrequency(this->getFrequencyActive()) && + (this->isValidFrequency(this->getFrequencyStandby()); + } + /*! + * \brief Validate values by assert and exception + * \param strict + * \throws std::range_error + * \remarks Cannot be virtualsince already used in constructor + * \return + */ + bool validate(bool strict = true) const { + if (this->isDefaultValue()) return true; + bool valid = this->validValues(); + if (!strict) return valid; + Q_ASSERT_X(valid, "CAdfSystem::validate", "illegal values"); + if (!valid) throw std::range_error("Illegal values in CAdfSystem::validate"); + return true; + } +public: + /*! + * Default constructor + */ + CAdfSystem() : CModulator() {} + /*! + * \brief Copy constructor + * \param otherSystem + */ + CAdfSystem(const CAdfSystem &otherSystem) : CModulator(otherSystem) {} + /*! + * \brief Constructor + * \param name + * \param activeFrequency + * \param standbyFrequency + * \param digits + */ + CAdfSystem(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): + CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) { + this->validate(true); + } + /*! + * \brief Set active frequency + * \param frequencyKHz + */ + void setFrequencyActiveKHz(double frequencyKHz) { + CModulator::setFrequencyActiveKHz(frequencyKHz); + this->validate(true); + } + /*! + * \brief Set standby frequency + * \param frequencyKHz + */ + void setFrequencyActiveKHz(double frequencyKHz) { + CModulator::setFrequencyStandbyKHz(frequencyKHz); + this->validate(true); + } + /*! + * \brief Assigment operator = + * \param otherSystem + * \return + */ + CAdfSystem& operator =(const CAdfSystem &otherSystem) { + CModulator::operator =(otherSystem); + return (*this); + } + /*! + * \brief operator == + * \param otherSystem + * \return + */ + bool operator ==(const CAdfSystem &otherSystem) const { + return CModulator::operator ==(otherSystem); + } + /*! + * \brief operator == + * \param otherSystem + * \return + */ + bool operator !=(const CAdfSystem &otherSystem) const { + return CModulator::operator !=(otherSystem); + } + + /*! + * Try to get a ADF unit with given name and frequency. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param adfSystem + * \param name + * \param activeFrequencyKHz + * \param standbyFrequencyKHz + * \return + */ + static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { + adfSystem = CAdfSystem(false, name, CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + bool s; + if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default + return s; + } + + /*! + * Try to get a ADF unit with given name and frequency. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param adfSystem + * \param name + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetAdfSystem(CAdfSystem &adfSystem, const QString &name, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + adfSystem = CAdfSystem(false, name, activeFrequency, standbyFrequency); + bool s; + if (!(s = adfSystem.validate(false))) adfSystem = CAdfSystem(); // reset to default + return s; + } + /*! + * \brief ADF1 unit + * \param activeFrequencyKHz + * \param standbyFrequencyKHz + * \return + */ + static CAdfSystem GetAdf1System(double activeFrequencyKHz, double standbyFrequencyKHz = -1) { + return CAdfSystem(CModulator::NameCom1(), CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + } + /*! + * \brief ADF1 unit + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static CAdfSystem GetAdf1System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CAdfSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } + /*! + * \brief Try to get ADF unit + * \param adfSystem + * \param activeFrequencyKHz + * \param standbyFrequencyKHz + * \return + */ + static bool tryGetAdf1Unit(CAdfSystem &adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { + return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequencyKHz, standbyFrequencyKHz); + } + /*! + * \brief Try to get ADF unit + * \param adfSystem + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetAdf1Unit(CAdfSystem &adfSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); + } + /*! + * \brief ADF2 unit + * \param activeFrequencyKHz + * \param standbyFrequencyKHz + * \return + */ + static CAdfSystem GetAdf2System(double activeFrequencyKHz, double standbyFrequencyKHz = -1) { + return CAdfSystem(CModulator::NameCom2(), CFrequency(activeFrequencyKHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyKHz < 0 ? activeFrequencyKHz : standbyFrequencyKHz, CFrequencyUnit::MHz())); + } + /*! + * \brief ADF2 unit + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static CAdfSystem GetAdf2System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CAdfSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } + /*! + * \brief Try to get ADF unit + * \param adfSystem + * \param activeFrequencyKHz + * \param standbyFrequencyKHz + * \return + */ + static bool tryGetAdf2System(CAdfSystem &adfSystem, double activeFrequencyKHz, double standbyFrequencyKHz = -1) { + return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequencyKHz, standbyFrequencyKHz); + } + /*! + * \brief Try to get ADF unit + * \param adfSystem + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetAdf2System(CAdfSystem &adfSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CAdfSystem::tryGetAdfSystem(adfSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); + } +}; + +} // namespace +} // namespace + + +#endif // AVIOADFSYSTEM_H diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index 15afa9563..6fee3e251 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -1,9 +1,19 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVIOBASE_H #define AVIOBASE_H +// QtGlobal is required for asserts +#include #include "blackmisc/pqconstants.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace Aviation +{ /*! * \brief Base class for avionics @@ -37,11 +47,13 @@ class CAvionicsBase return log; } +private: + QString m_name; //!< name of the unit protected: /*! * \brief Default constructor */ - CAvionicsBase() {} + CAvionicsBase(const QString &name) : m_name(name) {} /*! * \brief Meaningful string representation * \return @@ -51,16 +63,46 @@ protected: * \brief Are the set values valid / in range * \return */ - virtual bool validValues() { return true; } -public: + virtual bool validValues() { + return true; + } + /*! + * \brief Set name + * \param name + */ + void setName(const QString &name) { + this->m_name = name; + } + /*! + * \brief operator == + * \param otherSystem + * \return + */ + bool operator ==(const CAvionicsBase &otherSystem) const { + if (this == &otherSystem) return true; + return this->m_name == otherSystem.m_name; + } - /** - * @brief Virtual destructor +public: + /*! + * \brief Virtual destructor */ virtual ~CAvionicsBase() {} - + /*! + * \brief Cast as QString + */ + operator QString() const { + return this->stringForStreamingOperator(); + } + /*! + * \brief Name + * \return + */ + QString getName() const { + return this->m_name; + } }; - +} // namespace } // namespace #endif // AVIOBASE_H diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 11cf14ec4..dc811b73c 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -1,8 +1,18 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVIOCOMUNIT_H #define AVIOCOMUNIT_H #include "blackmisc/aviomodulator.h" -namespace BlackMisc { +using BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants; + +namespace BlackMisc +{ +namespace Aviation +{ /*! * \brief COM system (aka "radio") @@ -15,14 +25,61 @@ private: * \param f * \return */ - bool isValidCivilAviationFrequency(CFrequency f) { double fr = f.valueRounded(CFrequencyUnit::MHz(), this->m_digits); return fr >= 118.0 && fr <= 136.975; } + bool isValidCivilAviationFrequency(CFrequency f) const { + double fr = f.valueRounded(CFrequencyUnit::MHz(), this->m_digits); + return fr >= 118.0 && fr <= 136.975; + } /*! * \brief Valid military aviation frequency? * \param f * \return */ - bool isValidMilitaryFrequency(CFrequency f) { double fr = f.valueRounded(CFrequencyUnit::MHz(), this->m_digits); return fr >= 220.0 && fr <= 399.95; } + bool isValidMilitaryFrequency(CFrequency f) const { + double fr = f.valueRounded(CFrequencyUnit::MHz(), this->m_digits); + return fr >= 220.0 && fr <= 399.95; + } + /*! + * \brief Constructor + * \param validate + * \param name + * \param activeFrequency + * \param standbyFrequency + * \param digits + * + */ + CComSystem(bool validate, const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits = 3): + CModulator(name, activeFrequency, standbyFrequency, digits) { + this->validate(validate); + } +protected: + /*! + * \brief Are the set values valid / in range? + * \return + */ + bool validValues() const { + if (this->isDefaultValue()) return true; // special case + return + (this->isValidCivilAviationFrequency(this->getFrequencyActive()) || + this->isValidMilitaryFrequency(this->getFrequencyActive())) && + (this->isValidCivilAviationFrequency(this->getFrequencyStandby()) || + this->isValidMilitaryFrequency(this->getFrequencyStandby())); + } + /*! + * \brief Validate values by assert and exception + * \param strict + * \throws std::range_error + * \remarks Cannot be virtualsince already used in constructor + * \return + */ + bool validate(bool strict = true) const { + if (this->isDefaultValue()) return true; + bool valid = this->validValues(); + if (!strict) return valid; + Q_ASSERT_X(valid, "CComSystem::validate", "illegal values"); + if (!valid) throw std::range_error("Illegal values in CComSystem::validate"); + return true; + } public: /*! * Default constructor @@ -30,9 +87,9 @@ public: CComSystem() : CModulator() {} /*! * \brief Copy constructor - * \param otherUnit + * \param otherSystem */ - CComSystem(const CComSystem &otherUnit) : CModulator(otherUnit) {} + CComSystem(const CComSystem &otherSystem) : CModulator(otherSystem) {} /*! * \brief Constructor * \param name @@ -40,55 +97,96 @@ public: * \param standbyFrequency * \param digits */ - CComSystem(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits =3): - CModulator(name, activeFrequency, standbyFrequency, digits) {} + CComSystem(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): + CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits) { + this->validate(true); + } /*! * \brief Set active frequency * \param frequencyMHz */ - void setFrequencyActiveMHz(double frequencyMHz) { CModulator::setFrequencyActiveMHz(frequencyMHz); } + void setFrequencyActiveMHz(double frequencyMHz) { + CModulator::setFrequencyActiveMHz(frequencyMHz); + this->validate(true); + } /*! * \brief Set standby frequency * \param frequencyMHz */ - void setFrequencyStandbyMHz(double frequencyMHz) { CModulator::setFrequencyStandbyMHz(frequencyMHz); } + void setFrequencyStandbyMHz(double frequencyMHz) { + CModulator::setFrequencyStandbyMHz(frequencyMHz); + this->validate(true); + } /*! * \brief Set UNICOM frequency as active */ - void setActiveUnicom() { this->toggleActiveStandby(); this->setFrequencyActive(CPhysicalQuantitiesConstants::FrequencyUnicom());} + void setActiveUnicom() { + this->toggleActiveStandby(); + this->setFrequencyActive(CPhysicalQuantitiesConstants::FrequencyUnicom()); + } /*! * \brief Set International Air Distress 121.5MHz */ - void setActiveInternationalAirDistress() { this->toggleActiveStandby(); this->setFrequencyActive(CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress());} + void setActiveInternationalAirDistress() { + this->toggleActiveStandby(); + this->setFrequencyActive(CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress()); + } /*! * \brief Assigment operator = * \param otherSystem * \return */ - CComSystem& operator =(const CComSystem &otherSystem) { CModulator::operator =(otherSystem); return (*this); } + CComSystem& operator =(const CComSystem &otherSystem) { + CModulator::operator =(otherSystem); + return (*this); + } /*! * \brief operator == * \param otherSystem * \return */ - bool operator ==(const CComSystem &otherSystem) const { return CModulator::operator ==(otherSystem); } + bool operator ==(const CComSystem &otherSystem) const { + return CModulator::operator ==(otherSystem); + } /*! * \brief operator == * \param otherSystem * \return */ - bool operator !=(const CComSystem &otherSystem) const { return CModulator::operator !=(otherSystem); } + bool operator !=(const CComSystem &otherSystem) const { + return CModulator::operator !=(otherSystem); + } /*! - * \brief Are the set values valid / in range? + * Try to get a COM unit with given name and frequency. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param comSystem + * \param name + * \param activeFrequencyMHz + * \param standbyFrequencyMHz * \return */ - virtual bool validValues() { - return - this->isValidCivilAviationFrequency(this->getFrequencyActive()) && - this->isValidMilitaryFrequency(this->getFrequencyActive()) && - this->isValidCivilAviationFrequency(this->getFrequencyStandby()) && - this->isValidMilitaryFrequency(this->getFrequencyStandby()); + static bool tryGetComSystem(CComSystem &comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + comSystem = CComSystem(false, name, CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + bool s; + if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default + return s; + } + + /*! + * Try to get a COM unit with given name and frequency. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param comSystem + * \param name + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetComSystem(CComSystem &comSystem, const QString &name, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + comSystem = CComSystem(false, name, activeFrequency, standbyFrequency); + bool s; + if (!(s = comSystem.validate(false))) comSystem = CComSystem(); // reset to default + return s; } /*! * \brief COM1 unit @@ -96,51 +194,120 @@ public: * \param standbyFrequencyMHz * \return */ - static CComSystem getCom1Unit(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem(CModulator::NameCom1(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz,CFrequencyUnit::MHz()));} + static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CComSystem(CModulator::NameCom1(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + } /*! * \brief COM1 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CComSystem getCom1Unit(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);} + static CComSystem getCom1System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } + /*! + * \brief Try to get COM unit + * \param comSystem + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static bool tryGetCom1Unit(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz); + } + /*! + * \brief Try to get COM unit + * \param comSystem + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetCom1Unit(CComSystem &comSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); + } /*! * \brief COM2 unit * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static CComSystem getCom2Unit(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem(CModulator::NameCom2(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz,CFrequencyUnit::MHz()));} + static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CComSystem(CModulator::NameCom2(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + } /*! * \brief COM2 unit * \param activeFrequency * \param standbyFrequency * \return */ - static CComSystem getCom2Unit(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);} + static CComSystem getCom2System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } /*! - * \brief COM3 unit + * \brief Try to get COM unit + * \param comSystem * \param activeFrequencyMHz * \param standbyFrequencyMHz * \return */ - static CComSystem getCom3Unit(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { - return CComSystem(CModulator::NameCom3(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz,CFrequencyUnit::MHz()));} + static bool tryGetCom2System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); + } /*! - * \brief COM3 unit + * \brief Try to get COM unit + * \param comSystem * \param activeFrequency * \param standbyFrequency * \return */ - static CComSystem getCom3Unit(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { - return CComSystem(CModulator::NameCom3(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);} + static bool tryGetCom2System(CComSystem &comSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); + } + /*! + * \brief COM3 unit + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CComSystem(CModulator::NameCom3(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + } + /*! + * \brief COM3 unit + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static CComSystem getCom3System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CComSystem(CModulator::NameCom3(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } + + /*! + * \brief Try to get COM unit + * \param comSystem + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static bool tryGetCom3System(CComSystem &comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); + } + /*! + * \brief Try to get COM unit + * \param comSystem + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetCom3System(CComSystem &comSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CComSystem::tryGetComSystem(comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); + } }; } // namespace +} // namespace + #endif // AVIOCOMUNIT_H diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index d6e717912..005356408 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -1,7 +1,11 @@ #include "blackmisc/aviomodulator.h" #include "blackmisc/aviocomsystem.h" +#include "blackmisc/avionavsystem.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace Aviation +{ /** * Toggle standby <-> active @@ -18,22 +22,31 @@ template void CModulator::toggleActiveStandby() */ template QString CModulator::stringForStreamingOperator() const { - QString s(this->m_name); + QString s(this->getName()); s.append(" Active: ").append(this->m_frequencyActive.unitValueRoundedWithUnit(3)); s.append(" Standby: ").append(this->m_frequencyStandby.unitValueRoundedWithUnit(3)); return s; } +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * Assigment operator = */ -template CModulator& CModulator::operator=(const CModulator &otherModulator) { +template CModulator& CModulator::operator=(const CModulator &otherModulator) +{ if (this == &otherModulator) return *this; // Same object? this->m_frequencyActive = otherModulator.m_frequencyActive; this->m_frequencyStandby = otherModulator.m_frequencyStandby; - this->m_name = otherModulator.m_name; this->m_digits = otherModulator.m_digits; + this->setName(otherModulator.getName()); return *this; } @@ -42,8 +55,8 @@ template CModulator& CModulator::operator=(const CModul */ template bool CModulator::operator ==(const CModulator &otherModulator) const { - if(this == &otherModulator) return true; - return (this->m_name == otherModulator.m_name && + if (this == &otherModulator) return true; + return (this->getName() == otherModulator.getName() && this->m_frequencyActive == otherModulator.m_frequencyActive && this->m_frequencyStandby == otherModulator.m_frequencyStandby); } @@ -60,5 +73,7 @@ template bool CModulator::operator !=(const CModulator // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class CModulator; +template class CModulator; } // namespace +} // namespace diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 9275b7ee4..88545df8a 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -1,8 +1,19 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVIOMODULATORUNIT_H #define AVIOMODULATORUNIT_H #include "blackmisc/aviobase.h" -namespace BlackMisc { +using BlackMisc::PhysicalQuantities::CFrequency; +using BlackMisc::PhysicalQuantities::CFrequencyUnit; + +namespace BlackMisc +{ +namespace Aviation +{ /*! * \brief Base class for COM, NAV, Squawk units. @@ -12,7 +23,6 @@ template class CModulator : public CAvionicsBase private: CFrequency m_frequencyActive; //!< active frequency CFrequency m_frequencyStandby; //!< standby frequency - QString m_name; //!< name of the unit protected: int m_digits; //!< digits used @@ -20,14 +30,14 @@ protected: /*! * \brief Default constructor */ - CModulator() {} + CModulator() : CAvionicsBase("default") {} /*! * \brief Copy constructor * \param otherUnit */ CModulator(const CModulator &otherUnit) : m_frequencyActive(otherUnit.m_frequencyActive), m_frequencyStandby(otherUnit.m_frequencyStandby), - m_name(otherUnit.m_name), m_digits(otherUnit.m_digits) {} + m_digits(otherUnit.m_digits), CAvionicsBase(otherUnit.getName()) {} /*! * \brief Constructor * \param name @@ -35,8 +45,8 @@ protected: * \param standbyFrequency */ CModulator(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits) : - m_name(name), m_frequencyActive(activeFrequency), - m_digits(digits), m_frequencyStandby(standbyFrequency) {} + m_frequencyActive(activeFrequency), + m_digits(digits), m_frequencyStandby(standbyFrequency), CAvionicsBase(name) { } /*! * \brief Meaningful string representation * \return @@ -46,22 +56,30 @@ protected: * \brief Set active frequency * \param frequencyKHz */ - void setFrequencyActiveKHz(double frequencyKHz) { this->m_frequencyActive = CFrequency(frequencyKHz, CFrequencyUnit::kHz()); } + void setFrequencyActiveKHz(double frequencyKHz) { + this->m_frequencyActive = CFrequency(frequencyKHz, CFrequencyUnit::kHz()); + } /*! * \brief Set standby frequency * \param frequencyKHz */ - void setFrequencyStandbyKHz(double frequencyKHz) { this->m_frequencyStandby = CFrequency(frequencyKHz, CFrequencyUnit::kHz()); } + void setFrequencyStandbyKHz(double frequencyKHz) { + this->m_frequencyStandby = CFrequency(frequencyKHz, CFrequencyUnit::kHz()); + } /*! * \brief Set active frequency * \param frequencyMHz */ - void setFrequencyActiveMHz(double frequencyMHz) { this->m_frequencyActive = CFrequency(frequencyMHz, CFrequencyUnit::MHz()); } + void setFrequencyActiveMHz(double frequencyMHz) { + this->m_frequencyActive = CFrequency(frequencyMHz, CFrequencyUnit::MHz()); + } /*! * \brief Set standby frequency * \param frequencyMHz */ - void setFrequencyStandbyMHz(double frequencyMHz) { this->m_frequencyStandby = CFrequency(frequencyMHz, CFrequencyUnit::MHz()); } + void setFrequencyStandbyMHz(double frequencyMHz) { + this->m_frequencyStandby = CFrequency(frequencyMHz, CFrequencyUnit::MHz()); + } /*! * \brief Assigment operator = * \param otherModulator @@ -84,84 +102,122 @@ protected: * \brief COM1 * \return */ - static const QString& NameCom1() { static QString n("COM1"); return n; } + static const QString& NameCom1() { + static QString n("COM1"); + return n; + } /*! * \brief COM2 * \return */ - static const QString& NameCom2() { static QString n("COM2"); return n; } + static const QString& NameCom2() { + static QString n("COM2"); + return n; + } /*! * \brief COM3 * \return */ - static const QString& NameCom3() { static QString n("COM3"); return n; } + static const QString& NameCom3() { + static QString n("COM3"); + return n; + } /*! * \brief NAV1 * \return */ - static const QString& NameNav1() { static QString n("NAV1"); return n; } + static const QString& NameNav1() { + static QString n("NAV1"); + return n; + } /*! * \brief NAV2 * \return */ - static const QString& NameNav2() { static QString n("NAV2"); return n; } + static const QString& NameNav2() { + static QString n("NAV2"); + return n; + } /*! * \brief NAV2 * \return */ - static const QString& NameNav3() { static QString n("NAV2"); return n; } + static const QString& NameNav3() { + static QString n("NAV2"); + return n; + } /*! * \brief ADF1 * \return */ - static const QString& NameAdf1() { static QString n("ADF1"); return n; } + static const QString& NameAdf1() { + static QString n("ADF1"); + return n; + } /*! * \brief ADF2 * \return */ - static const QString& NameAdf2() { static QString n("ADF2"); return n; } + static const QString& NameAdf2() { + static QString n("ADF2"); + return n; + } /*! * \brief Frequency not set * \return */ - static const CFrequency& FrequencyNotSet() { static CFrequency f; return f; } + static const CFrequency& FrequencyNotSet() { + static CFrequency f; + return f; + } public: /*! * \brief Virtual destructor */ virtual ~CModulator() {} + /*! + * \brief Default value + * \return + */ + virtual bool isDefaultValue() const { + return this->m_frequencyActive == CModulator::FrequencyNotSet(); + } /*! * \brief Toggle active and standby frequencies */ void toggleActiveStandby(); - /*! - * \brief Name - * \return - */ - QString getName() const { return this->m_name; } /*! * \brief Active frequency * \return */ - CFrequency getFrequencyActive() const { return this->m_frequencyActive; } + CFrequency getFrequencyActive() const { + return this->m_frequencyActive; + } /*! * \brief Standby frequency * \return */ - CFrequency getFrequencyStandby() const { return this->m_frequencyActive; } + CFrequency getFrequencyStandby() const { + return this->m_frequencyActive; + } /*! * \brief Set active frequency * \param frequency */ - void setFrequencyActive(const CFrequency &frequency) { this->m_frequencyActive = frequency; } + void setFrequencyActive(const CFrequency &frequency) { + this->m_frequencyActive = frequency; + } /*! * \brief Set standby frequency * \param frequency */ - void setFrequencyStandby(const CFrequency &frequency) { this->m_frequencyStandby = frequency; } + void setFrequencyStandby(const CFrequency &frequency) { + this->m_frequencyStandby = frequency; + } }; +} // namespace } // namespace #endif // AVIOMODULATORUNIT_H diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h new file mode 100644 index 000000000..ddabc98fc --- /dev/null +++ b/src/blackmisc/avionavsystem.h @@ -0,0 +1,256 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef AVIONAVSYSTEM_H +#define AVIONAVSYSTEM_H +#include "blackmisc/aviomodulator.h" + +namespace BlackMisc +{ + +namespace Aviation +{ + +/*! + * \brief NAV system (radio navigation) + */ +class CNavSystem : public CModulator +{ +private: + /*! + * \brief Valid civil aviation frequency? + * \param f + * \return + */ + bool isValidCivilNavigationFrequency(CFrequency f) const { + double fr = f.valueRounded(CFrequencyUnit::MHz(), this->m_digits); + return fr >= 108.0 && fr <= 117.95; + } + /*! + * \brief Valid military aviation frequency? + * \param f + * \return + */ + bool isValidMilitaryNavigationFrequency(CFrequency f) const { + return false; + } + /*! + * \brief Constructor + * \param validate + * \param name + * \param activeFrequency + * \param standbyFrequency + * \param digits + * + */ + CNavSystem(bool validate, const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits = 3): + CModulator(name, activeFrequency, standbyFrequency, digits) { + this->validate(validate); + } + +protected: + /*! + * \brief Are the set values valid / in range? + * \return + */ + bool validValues() const { + if (this->isDefaultValue()) return true; // special case + bool v = + (this->isValidCivilNavigationFrequency(this->getFrequencyActive()) || + this->isValidMilitaryNavigationFrequency(this->getFrequencyActive())) && + (this->isValidCivilNavigationFrequency(this->getFrequencyStandby()) || + this->isValidMilitaryNavigationFrequency(this->getFrequencyStandby())); + return v; + } + /*! + * \brief Validate values by assert and exception + * \param strict + * \throws std::range_error + * \remarks Cannot be virtualsince already used in constructor + * \return + */ + bool validate(bool strict = true) const { + if (this->isDefaultValue()) return true; + bool valid = this->validValues(); + if (!strict) return valid; + Q_ASSERT_X(valid, "CModulator::validate", "illegal values"); + if (!valid) throw std::range_error("Illegal values in CModulator::validate"); + return true; + } +public: + /*! + * Default constructor + */ + CNavSystem() : CModulator() {} + /*! + * \brief Copy constructor + * \param otherSystem + */ + CNavSystem(const CNavSystem &otherSystem) : CModulator(otherSystem) {} + /*! + * \brief Constructor + * \param name + * \param activeFrequency + * \param standbyFrequency + * \param digits + */ + CNavSystem(const QString &name, const CFrequency &activeFrequency, const CFrequency &standbyFrequency, int digits = 3): + CModulator(name, activeFrequency, standbyFrequency, digits) { + this->validate(true); + } + /*! + * \brief Set active frequency + * \param frequencyMHz + */ + void setFrequencyActiveMHz(double frequencyMHz) { + CModulator::setFrequencyActiveMHz(frequencyMHz); + this->validate(true); + } + /*! + * \brief Set standby frequency + * \param frequencyMHz + */ + void setFrequencyStandbyMHz(double frequencyMHz) { + CModulator::setFrequencyStandbyMHz(frequencyMHz); + this->validate(true); + } + /*! + * \brief Assigment operator = + * \param otherSystem + * \return + */ + CNavSystem& operator =(const CNavSystem &otherSystem) { + CModulator::operator =(otherSystem); + return (*this); + } + /*! + * \brief operator == + * \param otherSystem + * \return + */ + bool operator ==(const CNavSystem &otherSystem) const { + return CModulator::operator ==(otherSystem); + } + /*! + * \brief operator == + * \param otherSystem + * \return + */ + bool operator !=(const CNavSystem &otherSystem) const { + return CModulator::operator !=(otherSystem); + } + + /*! + * Try to get a NAV unit with given name and frequency. Returns true in case an object + * has been sucessfully created,otherwise returns a default object. + * \param navSystem + * \param name + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + navSystem = CNavSystem(false, name, CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + bool s; + if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default + return s; + } + /*! + * Try to get a NAV unit with given name and frequency. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param navSystem + * \param name + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + navSystem = CNavSystem(false, name, activeFrequency, standbyFrequency); + bool s; + if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default + return s; + } + /*! + * \brief NAV1 unit + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static CNavSystem getNav1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CNavSystem(CModulator::NameNav1(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + } + /*! + * \brief NAV1 unit + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static CNavSystem getNav1System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CNavSystem(CModulator::NameNav1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } + /*! + * \brief Try to get NAV unit + * \param navSystem + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static bool tryGetNav1System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequencyMHz, standbyFrequencyMHz); + } + /*! + * \brief Try to get NAV unit + * \param comSystem + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetNav1System(CNavSystem &navSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequency, standbyFrequency); + } + /*! + * \brief NAV2 unit + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static CNavSystem getNav2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CNavSystem(CModulator::NameNav2(), CFrequency(activeFrequencyMHz, CFrequencyUnit::MHz()), CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, CFrequencyUnit::MHz())); + } + /*! + * \brief NAV2 unit + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static CNavSystem getNav2System(CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CNavSystem(CModulator::NameNav2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); + } + /*! + * \brief Try to get NAV unit + * \param navSystem + * \param activeFrequencyMHz + * \param standbyFrequencyMHz + * \return + */ + static bool tryGetNav2System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) { + return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequencyMHz, standbyFrequencyMHz); + } + /*! + * \brief Try to get NAV unit + * \param comSystem + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetNav2System(CNavSystem &navSystem, CFrequency activeFrequency, CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { + return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequency, standbyFrequency); + } +}; + +} // namespace +} // namespace + +#endif // AVIONAVSYSTEM_H diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp new file mode 100644 index 000000000..9c1e569ca --- /dev/null +++ b/src/blackmisc/aviotransponder.cpp @@ -0,0 +1,103 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackmisc/aviotransponder.h" + +namespace BlackMisc +{ +namespace Aviation +{ + +/** + * Valid values? + */ +bool CTransponder::validValues() const +{ + if (this->isDefaultValue()) return true; // special case + if (this->m_transponderCode < 0 || this->m_transponderCode > 7777) return false; + + // check each digit + qint32 tc = this->m_transponderCode; + qint32 d; + while (tc > 7) { + d = (tc % 10); + if (d > 7) return false; + tc /= 10; + } + return true; +} + +/** + * Validate + */ +bool CTransponder::validate(bool strict) const +{ + if (this->isDefaultValue()) return true; + bool valid = this->validValues(); + if (!strict) return valid; + Q_ASSERT_X(valid, "CTransponder::validate", "illegal values"); + if (!valid) throw std::range_error("Illegal values in CTransponder::validate"); + return true; +} + +/** + * String representation + */ +QString CTransponder::stringForStreamingOperator() const +{ + QString s = this->getName(); + s = s.append(" ").append(this->getTransponderCodeFormatted()).append(" ").append(this->getModeAsString()); + return s; +} + +/** + * Mode as readable string + */ +QString CTransponder::getModeAsString() const +{ + QString m; + switch (this->m_transponderMode) { + case StateIdent: + m = "Ident"; + break; + case StateStandby: + m = "Standby"; + break; + case ModeC: + m = "Mode C"; + break; + case ModeMil1: + m = "Mil.Mode 1"; + break; + case ModeMil2: + m = "Mil.Mode 2"; + break; + case ModeMil3: + m = "Mil.Mode 3"; + break; + case ModeMil4: + m = "Mil.Mode 4"; + break; + case ModeMil5: + m = "Mil.Mode 5"; + break; + default: + throw std::range_error("Illegal Transponder Mode"); + } + return m; +} + +/** + * Formatted transponder code + */ +QString CTransponder::getTransponderCodeFormatted() const +{ + QString f("0000"); + f = f.append(QString::number(this->m_transponderCode)); + return f.right(4); +} + +} // namespace +} // namespace diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h new file mode 100644 index 000000000..9eda9bc47 --- /dev/null +++ b/src/blackmisc/aviotransponder.h @@ -0,0 +1,275 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef AVIOTRANSPONDER_H +#define AVIOTRANSPONDER_H +#include "blackmisc/aviobase.h" + +namespace BlackMisc +{ +namespace Aviation +{ + +/*! + * \brief Transponder + */ +class CTransponder : public CAvionicsBase +{ +public: + /*! + * \brief Our transponder codes + */ + enum TransponderMode { + StateStandby = 0, // not a real mode, more a state + ModeMil1 = 1, ModeMil2 = 2, ModeMil3 = 3, ModeMil4 = 4, ModeMil5 = 5, + StateIdent = 10, // not a real mode, more a state + ModeA = 11, + ModeC = 12, + ModeS = 20 + }; +private: + qint32 m_transponderCode; //validate(validate); + } + /*! + * \brief Constructor for validation + * \param validate + * \param name + * \param transponderCode + * \param transponderMode + */ + CTransponder(bool validate, const QString &name, const QString transponderCode, TransponderMode transponderMode) : + m_transponderCode(0), m_transponderMode(transponderMode), CAvionicsBase(name) { + bool ok = false; + this->m_transponderCode = transponderCode.toUInt(&ok); + if (!ok)this->m_transponderCode = -1; // will cause assert / exception + this->validate(validate); + } +protected: + /*! + * \brief Are the set values valid / in range? + * \return + */ + bool validValues() const; + /*! + * \brief Default value + * \return + */ + virtual bool isDefaultValue() const { + return this->m_transponderCode == 0; + } + /*! + * \brief Validate values by assert and exception + * \param strict + * \throws std::range_error + * \remarks Cannot be virtualsince already used in constructor + * \return + */ + bool validate(bool strict = true) const; + /*! + * \brief Meaningful string representation + * \return + */ + virtual QString stringForStreamingOperator() const; +public: + /*! + * Default constructor + */ + CTransponder() : CAvionicsBase("default"), m_transponderCode(0), m_transponderMode(StateStandby) {} + /*! + * \brief Copy constructor + * \param otherTransponder + */ + CTransponder(const CTransponder &otherTransponder) : CAvionicsBase(otherTransponder.getName()), + m_transponderCode(otherTransponder.m_transponderCode), m_transponderMode(otherTransponder.m_transponderMode) {} + /*! + * \brief Constructor + * \param name + * \param transponderCode + */ + CTransponder(const QString &name, qint32 transponderCode, TransponderMode transponderMode) : + CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode) { + this->validate(true); + } + /*! + * \brief Constructor + * \param name + * \param transponderCode + */ + CTransponder(const QString &name, const QString &transponderCode, TransponderMode transponderMode) : + CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode) { + bool ok = false; + this->m_transponderCode = transponderCode.toUInt(&ok); + if (!ok)this->m_transponderCode = -1; // will cause assert / exception + this->validate(true); + } + /*! + * \brief Transponder mode as string + * \return + * \throws std::range_erros + */ + QString getModeAsString() const; + /*! + * \brief Transponder mode + * \return + */ + TransponderMode getTransponderMode() const { + return this->m_transponderMode; + } + /*! + * \brief Transponder code + * \return + */ + qint32 getTransponderCode() const { + return this->m_transponderCode; + } + /*! + * \brief Transponder code + * \return + */ + QString getTransponderCodeFormatted() const; + /*! + * \brief Set transponder code + * \param transponderCode + */ + void setTransponderCode(qint32 transponderCode) { + this->m_transponderCode = transponderCode; + this->validate(true); + } + /*! + * \brief Set transponder mode + * \param mode + */ + void setTransponderMode(TransponderMode mode) { + this->m_transponderMode = mode ; + this->validate(true); + } + /*! + * \brief Set emergency + */ + void setEmergency() { + this->m_transponderCode = 7700; + } + /*! + * \brief Set emergency + */ + void setVFR() { + this->m_transponderCode = 7000; + } + /*! + * \brief Set emergency + */ + void setIFR() { + this->m_transponderCode = 2000; + } + /*! + * \brief Assigment operator = + * \param otherTransponder + * \return + */ + CTransponder& operator =(const CTransponder &otherTransponder) { + CAvionicsBase::operator =(otherTransponder); + this->m_transponderMode = otherTransponder.m_transponderMode; + this->m_transponderCode = otherTransponder.m_transponderCode; + return (*this); + } + /*! + * \brief operator == + * \param otherTransponder + * \return + */ + bool operator ==(const CTransponder &otherTransponder) const { + return + this->m_transponderCode == otherTransponder.m_transponderCode && + this->m_transponderMode == otherTransponder.m_transponderMode && + CAvionicsBase::operator ==(otherTransponder); + } + /*! + * \brief operator =! + * \param otherSystem + * \return + */ + bool operator !=(const CTransponder &otherSystem) const { + return !((*this) == otherSystem); + } + + /*! + * Try to get a Transponder unit with given name and code. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param transponder + * \param name + * \param transponderCode + * \param mode + * \return + */ + static bool tryGetTransponder(CTransponder &transponder, const QString &name, qint32 transponderCode, TransponderMode mode) { + transponder = CTransponder(false, name, transponderCode, mode); + bool s; + if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default + return s; + } + /*! + * Try to get a Transponder unit with given name and code. Returns true in case an object + * has been sucessfully created, otherwise returns a default object. + * \param transponder + * \param name + * \param activeFrequency + * \param standbyFrequency + * \return + */ + static bool tryGetTransponder(CTransponder &transponder, const QString &name, const QString &transponderCode, TransponderMode mode) { + transponder = CTransponder(false, name, transponderCode, mode); + bool s; + if (!(s = transponder.validate(false))) transponder = CTransponder(); // reset to default + return s; + } + /*! + * \brief Transponder unit + * \param transponderCode + * \param mode + * \return + */ + static CTransponder getStandardTransponder(qint32 transponderCode, TransponderMode mode) { + return CTransponder("Transponder", transponderCode, mode); + } + /*! + * \brief Try to get Transponder unit + * \param transponder + * \param transponderCode + * \param mode + * \return + */ + static bool tryGetStandardTransponder(CTransponder &transponder, qint32 transponderCode, TransponderMode mode) { + return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); + } + + /*! + * \brief Try to get Transponder unit + * \param transponder + * \param transponderCode + * \param mode + * \return + */ + static bool tryGetStandardTransponder(CTransponder &transponder, const QString &transponderCode, TransponderMode mode) { + return CTransponder::tryGetTransponder(transponder, "Transponder", transponderCode, mode); + } + +}; + +} // namespace +} // namespace + +#endif // AVIOTRANSPONDER_H diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index 1bd87560b..2e4e2cc4a 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -1,6 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "avtrack.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace Aviation +{ /** * Own implementation for streaming @@ -40,3 +48,4 @@ bool CTrack::operator !=(const CTrack &otherTrack) } } // namespace +} // namespace diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index bfbd13512..31b5f1e62 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -1,8 +1,20 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVTRACK_H #define AVTRACK_H #include "blackmisc/pqangle.h" -namespace BlackMisc { +using BlackMisc::PhysicalQuantities::CAngle; +using BlackMisc::PhysicalQuantities::CAngleUnit; + +namespace BlackMisc +{ + +namespace Aviation +{ /*! * \brief Track as used in aviation, can be true or magnetic Track @@ -74,14 +86,20 @@ public: * \brief Magnetic Track? * \return */ - bool isMagneticTrack() const { return this->m_magnetic; } + bool isMagneticTrack() const { + return this->m_magnetic; + } /*! * \brief True Track? * \return */ - bool isTrueTrack() const { return !this->m_magnetic; } + bool isTrueTrack() const { + return !this->m_magnetic; + } }; } // namespace +} // namespace + #endif // AVTRACK_H diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp index 814e464a6..239a78e51 100644 --- a/src/blackmisc/avverticalpositions.cpp +++ b/src/blackmisc/avverticalpositions.cpp @@ -1,6 +1,15 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "avverticalpositions.h" -namespace BlackMisc { +namespace BlackMisc +{ + +namespace Aviation +{ /** * Constructor @@ -39,7 +48,7 @@ CAviationVerticalPositions &CAviationVerticalPositions::operator =(const CAviati if (this == &otherPositions) return *this; // Same object? this->m_altitude = otherPositions.m_altitude; this->m_elevation = otherPositions.m_elevation; - this->m_height= otherPositions.m_height; + this->m_height = otherPositions.m_height; return *this; } @@ -49,8 +58,8 @@ CAviationVerticalPositions &CAviationVerticalPositions::operator =(const CAviati bool CAviationVerticalPositions::operator ==(const CAviationVerticalPositions &otherPositions) { return this->m_altitude == otherPositions.m_altitude && - this->m_elevation == otherPositions.m_elevation && - this->m_height == otherPositions.m_height; + this->m_elevation == otherPositions.m_elevation && + this->m_height == otherPositions.m_height; } /** @@ -67,11 +76,11 @@ bool CAviationVerticalPositions::operator !=(const CAviationVerticalPositions &o QString CAviationVerticalPositions::stringForStreamingOperator() const { QString s = QString("Altitude: "). - append(this->m_altitude.unitValueRoundedWithUnit()). - append(" Elevation: "). - append(this->m_elevation.unitValueRoundedWithUnit()). - append(" Height: "). - append(this->m_height.unitValueRoundedWithUnit()); + append(this->m_altitude.unitValueRoundedWithUnit()). + append(" Elevation: "). + append(this->m_elevation.unitValueRoundedWithUnit()). + append(" Height: "). + append(this->m_height.unitValueRoundedWithUnit()); return s; } @@ -82,7 +91,7 @@ CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationI { CAltitude a(altitudeMslFt, true, CLengthUnit::ft()); CLength e(elevationFt, CLengthUnit::ft()); - CLength h(altitudeMslFt-elevationFt,CLengthUnit::ft()); + CLength h(altitudeMslFt - elevationFt, CLengthUnit::ft()); return CAviationVerticalPositions(a, e, h); } @@ -93,7 +102,7 @@ CAviationVerticalPositions CAviationVerticalPositions::fromAltitudeAndElevationI { CAltitude a(altitudeMslM, true, CLengthUnit::m()); CLength e(elevationM, CLengthUnit::m()); - CLength h(altitudeMslM-elevationM,CLengthUnit::m()); + CLength h(altitudeMslM - elevationM, CLengthUnit::m()); return CAviationVerticalPositions(a, e, h); } @@ -114,5 +123,6 @@ QDebug operator <<(QDebug d, const CAviationVerticalPositions &positions) d << positions.stringForStreamingOperator(); return d; } -} +} // namespace +} // namespace diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h index 8d9596779..89faf6058 100644 --- a/src/blackmisc/avverticalpositions.h +++ b/src/blackmisc/avverticalpositions.h @@ -1,9 +1,20 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef AVLATERALPOSITION_H #define AVLATERALPOSITION_H #include "blackmisc/avaltitude.h" #include "blackmisc/pqconstants.h" -namespace BlackMisc { +using BlackMisc::PhysicalQuantities::CLength; +using BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants; + +namespace BlackMisc +{ +namespace Aviation +{ /*! * \brief Vertical (Z) positions of an aircraft @@ -78,17 +89,23 @@ public: * \brief Height * \return */ - CLength getHeight() const { return this->m_height;} + CLength getHeight() const { + return this->m_height; + } /*! * \brief Elevation * \return */ - CLength getElevation() const { return this->m_elevation;} + CLength getElevation() const { + return this->m_elevation; + } /*! * \brief Altitude * \return */ - CAltitude getAltitude()const { return this->m_altitude; } + CAltitude getAltitude()const { + return this->m_altitude; + } /*! * \brief Factory getting tupel frome levation and altitude values in ft * \param altitudeMslFt @@ -105,6 +122,7 @@ public: static CAviationVerticalPositions fromAltitudeAndElevationInM(double altitudeMslM, double elevationM); }; +} // namespace } // namespace #endif // AVLATERALPOSITION_H diff --git a/src/blackmisc/blackmisc.h b/src/blackmisc/blackmisc.h index f9978b99f..2f569bff9 100644 --- a/src/blackmisc/blackmisc.h +++ b/src/blackmisc/blackmisc.h @@ -3,12 +3,9 @@ // just a dummy header, namespace documentation will go here - /** - * @namespace BlackMisc - * BlackMisc is the namespace for generic utility classes. As of its nature - * (containing central classes such as CLogMessage, or CPhysicalQuantity), - * BlackMisc is available in any other compilation unit. + * @namespace Aviation + * Aviation and Avionics classes such as CHeading or CTransponder */ #endif diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index 5726d3799..a14331ad7 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -55,7 +55,11 @@ HEADERS += \ avverticalpositions.h \ aviobase.h \ aviomodulator.h \ - aviocomsystem.h + aviocomsystem.h \ + avionavsystem.h \ + aviotransponder.h \ + avioadfsystem.h \ + aviation.h SOURCES += \ logmessage.cpp \ @@ -83,6 +87,7 @@ SOURCES += \ avtrack.cpp \ avaltitude.cpp \ avverticalpositions.cpp \ - aviomodulator.cpp + aviomodulator.cpp \ + aviotransponder.cpp DESTDIR = ../../lib diff --git a/src/blackmisc/com_handler.h b/src/blackmisc/com_handler.h index 913e50635..2a98b2993 100644 --- a/src/blackmisc/com_handler.h +++ b/src/blackmisc/com_handler.h @@ -14,58 +14,58 @@ const qint32 Sync_Marker = 0x1ACFFC1D; namespace BlackMisc { - //! IComHandler Interface. - /*! - This interface implements the basic class for every InterCommunikation - objects. It creates the frames in which the data is packed and - deframes it, when it receives something from the TCP socket. - \sa CComClient CComServer - */ - class IComHandler : public QObject - { - Q_OBJECT +//! IComHandler Interface. +/*! + This interface implements the basic class for every InterCommunikation + objects. It creates the frames in which the data is packed and + deframes it, when it receives something from the TCP socket. + \sa CComClient CComServer +*/ +class IComHandler : public QObject +{ + Q_OBJECT - public: - //! Constructor - /*! - \param parent Pointer to the parent QObject - */ - explicit IComHandler(QObject *parent = 0); +public: + //! Constructor + /*! + \param parent Pointer to the parent QObject + */ + explicit IComHandler(QObject *parent = 0); - //! Virtual destructor - virtual ~IComHandler() {} - - protected: - - //! Creates a sendable frame containing some data. - /*! - \param messageID QString with the unique messageID - \param message The actual data - \sa IMessage - */ - void createFrame (const QString &messageID, const QByteArray &data); + //! Virtual destructor + virtual ~IComHandler() {} - //! Parses a new frame and constructs messageID and data out of it - /*! - \param messageID Reference to the QString messageID - \param message Reference where the data will be stored in. - \sa IMessage - */ - bool parseFrame(QString &messageID, QByteArray &data); +protected: - //! Receive Buffer - /*! - Data received from the TCP socket, will stored in here. - */ - QByteArray m_receive_buffer; - - //! Sender Buffer - /*! - Sending data via the TCP socket, should be stored in here. - */ - QByteArray m_sender_buffer; + //! Creates a sendable frame containing some data. + /*! + \param messageID QString with the unique messageID + \param message The actual data + \sa IMessage + */ + void createFrame(const QString &messageID, const QByteArray &data); - }; + //! Parses a new frame and constructs messageID and data out of it + /*! + \param messageID Reference to the QString messageID + \param message Reference where the data will be stored in. + \sa IMessage + */ + bool parseFrame(QString &messageID, QByteArray &data); + + //! Receive Buffer + /*! + Data received from the TCP socket, will stored in here. + */ + QByteArray m_receive_buffer; + + //! Sender Buffer + /*! + Sending data via the TCP socket, should be stored in here. + */ + QByteArray m_sender_buffer; + +}; } // namespace BlackMisc diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index 8a4a02885..e19024ec8 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -1,8 +1,16 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQANGLE_H #define PQANGLE_H #include "blackmisc/pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief Physical unit degree @@ -40,14 +48,19 @@ public: * \brief Convenience method PI * \return */ - const static double pi() { return M_PI;} + const static double pi() { + return M_PI; + } /*! * \brief Value as factor of PI (e.g.0.5PI) * \return */ - double piFactor() const { return CMeasurementUnit::round(this->convertedSiValueToDouble() / M_PI,6);} + double piFactor() const { + return CMeasurementUnit::round(this->convertedSiValueToDouble() / M_PI, 6); + } }; +} // namespace } // namespace #endif // PQANGLE_H diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index 09a216d71..a7aa7e806 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -1,6 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "blackmisc/pqbase.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ // ----------------------------------------------------------------------- // --- Mulitplier -------------------------------------------------------- @@ -10,7 +18,7 @@ namespace BlackMisc { * Constructor */ CMeasurementPrefix::CMeasurementPrefix(const QString &name, const QString &unitName, double factor): - m_name(name),m_prefix(unitName),m_factor(factor) + m_name(name), m_prefix(unitName), m_factor(factor) { // void } @@ -27,12 +35,13 @@ CMeasurementPrefix::CMeasurementPrefix(const CMeasurementPrefix &otherMultiplier /** * Assignment operator */ -CMeasurementPrefix& CMeasurementPrefix::operator=(const CMeasurementPrefix &otherMultiplier) { +CMeasurementPrefix& CMeasurementPrefix::operator=(const CMeasurementPrefix &otherMultiplier) +{ if (this == &otherMultiplier) return *this; // Same object? Yes, so skip assignment, and just return *this this->m_name = otherMultiplier.m_name; - this->m_prefix=otherMultiplier.m_prefix; - this->m_factor=otherMultiplier.m_factor; + this->m_prefix = otherMultiplier.m_prefix; + this->m_factor = otherMultiplier.m_factor; return *this; } @@ -41,7 +50,7 @@ CMeasurementPrefix& CMeasurementPrefix::operator=(const CMeasurementPrefix &othe */ bool CMeasurementPrefix::operator ==(const CMeasurementPrefix &otherMultiplier) const { - if ( this == &otherMultiplier ) return true; + if (this == &otherMultiplier) return true; return this->m_factor == otherMultiplier.m_factor && this->m_name == otherMultiplier.m_name; } @@ -109,7 +118,7 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &unitName, */ CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &otherUnit): m_name(otherUnit.m_name), m_unitName(otherUnit.m_unitName), m_type(otherUnit.m_type), m_isSiUnit(otherUnit.m_isSiUnit), - m_isSiBaseUnit(otherUnit.m_isSiBaseUnit), m_displayDigits(otherUnit.m_displayDigits),m_conversionFactorToSIConversionUnit(otherUnit.m_conversionFactorToSIConversionUnit), + m_isSiBaseUnit(otherUnit.m_isSiBaseUnit), m_displayDigits(otherUnit.m_displayDigits), m_conversionFactorToSIConversionUnit(otherUnit.m_conversionFactorToSIConversionUnit), m_epsilon(otherUnit.m_epsilon), m_multiplier(otherUnit.m_multiplier), m_fromSiConverter(otherUnit.m_fromSiConverter), m_toSiConverter(otherUnit.m_toSiConverter) { // void @@ -122,14 +131,14 @@ CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &otherUnit { if (this == &otherUnit) return *this; // Same object? Yes, so skip assignment, and just return *this this->m_name = otherUnit.m_name; - this->m_unitName =otherUnit.m_unitName; - this->m_type=otherUnit.m_type; - this->m_isSiUnit =otherUnit.m_isSiUnit; - this->m_isSiBaseUnit =otherUnit.m_isSiBaseUnit; - this->m_conversionFactorToSIConversionUnit=otherUnit.m_conversionFactorToSIConversionUnit; + this->m_unitName = otherUnit.m_unitName; + this->m_type = otherUnit.m_type; + this->m_isSiUnit = otherUnit.m_isSiUnit; + this->m_isSiBaseUnit = otherUnit.m_isSiBaseUnit; + this->m_conversionFactorToSIConversionUnit = otherUnit.m_conversionFactorToSIConversionUnit; this->m_multiplier = otherUnit.m_multiplier; - this->m_displayDigits=otherUnit.m_displayDigits; - this->m_epsilon= otherUnit.m_epsilon; + this->m_displayDigits = otherUnit.m_displayDigits; + this->m_epsilon = otherUnit.m_epsilon; this->m_fromSiConverter = otherUnit.m_fromSiConverter; this->m_toSiConverter = otherUnit.m_toSiConverter; return *this; @@ -140,10 +149,10 @@ CMeasurementUnit &CMeasurementUnit::operator =(const CMeasurementUnit &otherUnit */ bool CMeasurementUnit::operator ==(const CMeasurementUnit &otherUnit) const { - if ( this == &otherUnit ) return true; - if ( this->m_type != otherUnit.m_type) return false; + if (this == &otherUnit) return true; + if (this->m_type != otherUnit.m_type) return false; return this->m_multiplier == otherUnit.m_multiplier && this->m_name == otherUnit.m_name - && this->m_isSiUnit==otherUnit.m_isSiUnit; + && this->m_isSiUnit == otherUnit.m_isSiUnit; } /** @@ -186,14 +195,16 @@ double CMeasurementUnit::conversionToUnit(double value, const CMeasurementUnit & * Value to QString with unit, e.g. "5.00m" * @return */ -QString CMeasurementUnit::valueRoundedWithUnit(double value, int digits) const { +QString CMeasurementUnit::valueRoundedWithUnit(double value, int digits) const +{ return this->toQStringRounded(value, digits).append(this->getUnitName()); } /*! * Value rounded */ -double CMeasurementUnit::valueRounded(double value, int digits) const { +double CMeasurementUnit::valueRounded(double value, int digits) const +{ if (digits < 0) digits = this->m_displayDigits; return CMeasurementUnit::round(value, digits); } @@ -212,10 +223,11 @@ QString CMeasurementUnit::toQStringRounded(double value, int digits) const /** * Round utility method */ -double CMeasurementUnit::round(double value, int digits) { +double CMeasurementUnit::round(double value, int digits) +{ // gosh, is there no Qt method for this??? // It's year 2013 - double m = pow(10.0,digits); + double m = pow(10.0, digits); double rv = double(qRound(value * m) / m); return rv; } @@ -227,8 +239,9 @@ double CMeasurementUnit::epsilonRounding(double value) const { // does notwork reliable with qRound for some reason double v = floor((value + this->m_epsilon) / this->m_epsilon); - v *=this->m_epsilon; + v *= this->m_epsilon; return v; } } // namespace +} // namespace diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 48f85c8c6..6aa1a5dde 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -1,6 +1,7 @@ -//! This Source Code Form is subject to the terms of the Mozilla Public -//! License, v. 2.0. If a copy of the MPL was not distributed with this -//! file, You can obtain one at http://mozilla.org/MPL/2.0/ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef PQBASE_H #define PQBASE_H @@ -10,7 +11,11 @@ #include #include "blackmisc/debug.h" -namespace BlackMisc { +namespace BlackMisc +{ + +namespace PhysicalQuantities +{ /*! * Typical prefixes (multipliers) such as kilo, mega, hecto. @@ -18,7 +23,8 @@ namespace BlackMisc { * Use the static values such CMeasurementMultiplier::k() as to specify values. * \author KWB */ -class CMeasurementPrefix { +class CMeasurementPrefix +{ /*! * \brief Stream << overload to be used in debugging messages * \param d @@ -76,36 +82,46 @@ public: * \param otherMultiplier * \return */ - bool operator > (const CMeasurementPrefix &otherMultiplier) const; + bool operator > (const CMeasurementPrefix &otherMultiplier) const; /*! * \brief Less operator < * \param otherMultiplier * \return */ - bool operator < (const CMeasurementPrefix &otherMultiplier) const; + bool operator < (const CMeasurementPrefix &otherMultiplier) const; /*! * \brief Cast as double */ - operator double() const { return this->m_factor; } + operator double() const { + return this->m_factor; + } /*! * \brief Cast as QString */ - operator QString() const { return this->m_name;} + operator QString() const { + return this->m_name; + } /*! * \brief Factor, e.g.1000 for "kilo" * \return */ - double getFactor() const { return this->m_factor;} + double getFactor() const { + return this->m_factor; + } /*! * \brief Name, e.g. "kilo" * \return */ - QString getName() const { return this->m_name; } + QString getName() const { + return this->m_name; + } /*! * \brief Prefix, e.g. "k" for "kilo" * \return */ - QString getPrefix() const { return this->m_prefix; } + QString getPrefix() const { + return this->m_prefix; + } // --- static units, always use these for initialization // --- Remark: Static initialization in C++ is random, this is why no static members @@ -115,42 +131,66 @@ public: * \brief Unit "None" * \return */ - static const CMeasurementPrefix& None() { static CMeasurementPrefix none("", "", 0.0); return none;} + static const CMeasurementPrefix& None() { + static CMeasurementPrefix none("", "", 0.0); + return none; + } /*! * \brief Unit "One" * \return */ - static const CMeasurementPrefix& One() { static CMeasurementPrefix one("one", "", 1.0); return one;} + static const CMeasurementPrefix& One() { + static CMeasurementPrefix one("one", "", 1.0); + return one; + } /*! * \brief Unit "mega" * \return */ - static const CMeasurementPrefix& M() { static CMeasurementPrefix mega("mega", "M", 1E6); return mega;} + static const CMeasurementPrefix& M() { + static CMeasurementPrefix mega("mega", "M", 1E6); + return mega; + } /*! * \brief Unit "kilo" * \return */ - static const CMeasurementPrefix& k() { static CMeasurementPrefix kilo("kilo", "k", 1000.0); return kilo;} + static const CMeasurementPrefix& k() { + static CMeasurementPrefix kilo("kilo", "k", 1000.0); + return kilo; + } /*! * \brief Unit "giga" * \return */ - static const CMeasurementPrefix& G() { static CMeasurementPrefix giga("giga", "G", 1E9); return giga;} + static const CMeasurementPrefix& G() { + static CMeasurementPrefix giga("giga", "G", 1E9); + return giga; + } /*! * \brief Unit "hecto" * \return */ - static const CMeasurementPrefix& h() { static CMeasurementPrefix hecto("hecto", "h", 100.0); return hecto;} + static const CMeasurementPrefix& h() { + static CMeasurementPrefix hecto("hecto", "h", 100.0); + return hecto; + } /*! * \brief Unit "centi" * \return */ - static const CMeasurementPrefix& c() { static CMeasurementPrefix centi("centi", "c", 0.01); return centi;} + static const CMeasurementPrefix& c() { + static CMeasurementPrefix centi("centi", "c", 0.01); + return centi; + } /*! * \brief Unit "milli" * \return */ - static const CMeasurementPrefix& m() { static CMeasurementPrefix milli("milli", "m", 1E-03); return milli;} + static const CMeasurementPrefix& m() { + static CMeasurementPrefix milli("milli", "m", 1E-03); + return milli; + } }; @@ -161,7 +201,8 @@ public: /** * Base class for all units, such as meter, hertz. */ -class CMeasurementUnit { +class CMeasurementUnit +{ /*! * \brief Stream << overload to be used in debugging messages @@ -231,21 +272,27 @@ protected: * \brief Conversion factor to SI conversion unit * \return */ - double getConversionFactorToSI() const { return this->m_conversionFactorToSIConversionUnit; } + double getConversionFactorToSI() const { + return this->m_conversionFactorToSIConversionUnit; + } /*! * Given value to conversion SI conversion unit (e.g. meter, hertz). * Standard implementaion is simply factor based. * \param value * \return */ - virtual double conversionToSiConversionUnit(double value) const { return value * this->m_conversionFactorToSIConversionUnit; } + virtual double conversionToSiConversionUnit(double value) const { + return value * this->m_conversionFactorToSIConversionUnit; + } /*! * \brief Value from SI conversion unit to this unit. * Standard implementaion is simply factor based. * \param value * \return */ - virtual double conversionFromSiConversionUnit(double value) const { return value / this->m_conversionFactorToSIConversionUnit; } + virtual double conversionFromSiConversionUnit(double value) const { + return value / this->m_conversionFactorToSIConversionUnit; + } public: /*! @@ -264,32 +311,44 @@ public: * \brief Representing an SI unit? Examples: kilometer, meter, hertz * \return */ - bool isSiUnit() const { return this->m_isSiUnit;} + bool isSiUnit() const { + return this->m_isSiUnit; + } /*! * \brief Representing an base SI unit? Examples: second, meter * \return */ - bool isSiBaseUnit() const { return this->m_isSiUnit;} + bool isSiBaseUnit() const { + return this->m_isSiUnit; + } /*! * \brief Representing an SI base unit? Example: meter * \return */ - bool isUnprefixedSiUnit() const { return this->m_isSiUnit && this->m_multiplier.getFactor() == 1; } + bool isUnprefixedSiUnit() const { + return this->m_isSiUnit && this->m_multiplier.getFactor() == 1; + } /*! * \brief Name such as "meter" * \return */ - QString getName() const { return this->m_name; } + QString getName() const { + return this->m_name; + } /*! * \brief Unit name such as "m" * \return */ - QString getUnitName() const { return this->m_unitName; } + QString getUnitName() const { + return this->m_unitName; + } /*! * \brief Type such as "distance", "frequency" * \return */ - QString getType() const { return this->m_type; } + QString getType() const { + return this->m_type; + } /*! * Given value to conversion SI conversion unit (e.g. meter, hertz). @@ -297,14 +356,18 @@ public: * \param value * \return */ - double convertToSiConversionUnit(double value) const { return (this->m_toSiConverter) ? this->m_toSiConverter((*this), value) : this->conversionToSiConversionUnit(value); } + double convertToSiConversionUnit(double value) const { + return (this->m_toSiConverter) ? this->m_toSiConverter((*this), value) : this->conversionToSiConversionUnit(value); + } /*! * Value from SI conversion unit to this unit. * Standard implementation is simply factor based. * \param value * \return */ - double convertFromSiConversionUnit(double value) const { return (this->m_fromSiConverter) ? this->m_fromSiConverter((*this), value) : this->conversionFromSiConversionUnit(value); } + double convertFromSiConversionUnit(double value) const { + return (this->m_fromSiConverter) ? this->m_fromSiConverter((*this), value) : this->conversionFromSiConversionUnit(value); + } /*! * Rounded string utility method, virtual so units can have * specialized formatting @@ -312,7 +375,7 @@ public: * \param digits * \return */ - virtual QString toQStringRounded(double value, int digits =-1) const; + virtual QString toQStringRounded(double value, int digits = -1) const; /*! * \brief Rounded value * \param value @@ -331,17 +394,23 @@ public: * \brief Threshold for rounding * \return */ - double getEpsilon() const { return this->m_epsilon;} + double getEpsilon() const { + return this->m_epsilon; + } /*! * \brief getDisplayDigits * \return */ - qint32 getDisplayDigits() const { return this->m_displayDigits; } + qint32 getDisplayDigits() const { + return this->m_displayDigits; + } /*! * \brief Multiplier such as "kilo" * \return */ - CMeasurementPrefix getMultiplier() const { return this->m_multiplier; } + CMeasurementPrefix getMultiplier() const { + return this->m_multiplier; + } /*! * \brief Factor to convert to given unit * \param to @@ -373,9 +442,13 @@ public: * \brief Unit is not specified * \return */ - static CMeasurementUnit& None() { static CMeasurementUnit none("none", "", "", false, false, 0.0, CMeasurementPrefix::None(), 0, 0); return none;} + static CMeasurementUnit& None() { + static CMeasurementUnit none("none", "", "", false, false, 0.0, CMeasurementPrefix::None(), 0, 0); + return none; + } }; +} // namespace } // namespace #endif // PQBASE_H diff --git a/src/blackmisc/pqconstants.h b/src/blackmisc/pqconstants.h index f381ec43a..5bbb0a21a 100644 --- a/src/blackmisc/pqconstants.h +++ b/src/blackmisc/pqconstants.h @@ -1,9 +1,17 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQCONSTANTS_H #define PQCONSTANTS_H #include "blackmisc/pqallquantities.h" -namespace BlackMisc{ +namespace BlackMisc +{ +namespace PhysicalQuantities +{ class CPhysicalQuantitiesConstants { @@ -13,47 +21,75 @@ public: * \brief Temperature absolute Zero in °C * \return */ - static const 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 const 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 const 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 const CPressure& InternationalStandardSeaLevelPressure() { static CPressure p(1013.25, CPressureUnit::hPa()); return p;} + static const CPressure& InternationalStandardSeaLevelPressure() { + static CPressure p(1013.25, CPressureUnit::hPa()); + return p; + } /*! * \brief 0m * \return */ - static const CLength& Length0m() { static CLength l(0, CLengthUnit::m()); return l;} + static const CLength& Length0m() { + static CLength l(0, CLengthUnit::m()); + return l; + } /*! * \brief 0ft * \return */ - static const CLength& Length0ft() { static CLength l(0, CLengthUnit::ft()); return l;} + static const CLength& Length0ft() { + static CLength l(0, CLengthUnit::ft()); + return l; + } /*! * \brief Unicom frequency * \return */ - static const CFrequency& FrequencyUnicom() { static CFrequency f(122.8, CFrequencyUnit::MHz()); return f;} + static const CFrequency& FrequencyUnicom() { + static CFrequency f(122.8, CFrequencyUnit::MHz()); + return f; + } /*! * \brief Civil aircraft emergency frequency * \return */ - static const CFrequency& FrequencyInternationalAirDistress() { static CFrequency f(121.5, CFrequencyUnit::MHz()); return f;} + static const CFrequency& FrequencyInternationalAirDistress() { + static CFrequency f(121.5, CFrequencyUnit::MHz()); + return f; + } /*! * \brief Military aircraft emergency frequency * \return */ - static const CFrequency& FrequencyMilitaryAirDistress() { static CFrequency f(243.0, CFrequencyUnit::MHz()); return f;} + static const CFrequency& FrequencyMilitaryAirDistress() { + static CFrequency f(243.0, CFrequencyUnit::MHz()); + return f; + } }; +} //namespace } // namespace #endif // PQCONSTANTS_H diff --git a/src/blackmisc/pqfrequency.h b/src/blackmisc/pqfrequency.h index 3a4c48623..277380059 100644 --- a/src/blackmisc/pqfrequency.h +++ b/src/blackmisc/pqfrequency.h @@ -1,14 +1,22 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQFREQUENCY_H #define PQFREQUENCY_H #include "pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief Physical unit distance * \author KWB */ -class CFrequency : public CPhysicalQuantity +class CFrequency : public CPhysicalQuantity { public: /*! @@ -24,17 +32,18 @@ public: * \param value * \param unit */ - CFrequency(qint32 value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()){} + CFrequency(qint32 value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} /*! * \brief Init by double value * \param value * \param unit */ - CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()){} + CFrequency(double value, const CFrequencyUnit &unit) : CPhysicalQuantity(value, unit, CFrequencyUnit::Hz()) {} /*! * \brief Virtual destructor */ virtual ~CFrequency() {} }; } // namespace +} // namespace #endif // PQFREQUENCY_H diff --git a/src/blackmisc/pqlength.h b/src/blackmisc/pqlength.h index acb32e949..413abeef3 100644 --- a/src/blackmisc/pqlength.h +++ b/src/blackmisc/pqlength.h @@ -1,20 +1,28 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQlength_H #define PQlength_H #include "blackmisc/pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief Physical unit length (length) * \author KWB */ -class CLength : public CPhysicalQuantity +class CLength : public CPhysicalQuantity { public: /*! * \brief Default constructor */ - CLength() : CPhysicalQuantity (0, CLengthUnit::m(), CLengthUnit::m()) {} + CLength() : CPhysicalQuantity(0, CLengthUnit::m(), CLengthUnit::m()) {} /** *\brief Copy constructor */ @@ -37,4 +45,5 @@ public: virtual ~CLength() {} }; } // namespace +} // namespace #endif // PQlength_H diff --git a/src/blackmisc/pqmass.h b/src/blackmisc/pqmass.h index e2e0cf3cc..da3111c46 100644 --- a/src/blackmisc/pqmass.h +++ b/src/blackmisc/pqmass.h @@ -1,14 +1,22 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQMASS_H #define PQMASS_H #include "blackmisc/pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief Mass * \author KWB */ -class CMass : public CPhysicalQuantity +class CMass : public CPhysicalQuantity { public: /*! @@ -20,23 +28,24 @@ public: * \param value * \param unit */ - CMass(qint32 value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()){} + CMass(qint32 value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} /*! * \brief Init by double value * \param value * \param unit */ - CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()){} + CMass(double value, const CMassUnit &unit) : CPhysicalQuantity(value, unit, CMassUnit::kg()) {} /*! * \brief Copy constructor * \param mass */ - CMass(const CPhysicalQuantity &mass) : CPhysicalQuantity(mass){} + CMass(const CPhysicalQuantity &mass) : CPhysicalQuantity(mass) {} /*! * \brief Virtual destructor */ virtual ~CMass() {} }; } // namespace +} // namespace #endif // PQMASS_H diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 395136852..d1181e693 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -1,11 +1,19 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "blackmisc/pqallquantities.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /** * Constructor by integer */ -template CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit) : +template CPhysicalQuantity::CPhysicalQuantity(qint32 baseValue, const MU &unit, const MU &siConversionUnit) : m_unit(unit), m_conversionSiUnit(siConversionUnit) { this->setUnitValue(baseValue); @@ -14,7 +22,7 @@ template CPhysicalQuantity::CPhysicalQuantity(qint32 /** * Constructor by double */ -template CPhysicalQuantity::CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit) : +template CPhysicalQuantity::CPhysicalQuantity(double baseValue, const MU &unit, const MU &siConversionUnit) : m_unit(unit), m_conversionSiUnit(siConversionUnit) { this->setUnitValue(baseValue); @@ -23,7 +31,7 @@ template CPhysicalQuantity::CPhysicalQuantity(double /** * Copy constructor */ -template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &otherQuantity) : +template CPhysicalQuantity::CPhysicalQuantity(const CPhysicalQuantity &otherQuantity) : m_unitValueD(otherQuantity.m_unitValueD), m_unitValueI(otherQuantity.m_unitValueI), m_convertedSiUnitValueD(otherQuantity.m_convertedSiUnitValueD), m_isIntegerBaseValue(otherQuantity.m_isIntegerBaseValue), m_unit(otherQuantity.m_unit), m_conversionSiUnit(otherQuantity.m_conversionSiUnit) { @@ -33,7 +41,7 @@ template CPhysicalQuantity::CPhysicalQuantity(const /*! * Destructor */ -template CPhysicalQuantity::~CPhysicalQuantity() +template CPhysicalQuantity::~CPhysicalQuantity() { // void } @@ -41,10 +49,10 @@ template CPhysicalQuantity::~CPhysicalQuantity() /** * Equal operator == */ -template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &otherQuantity) const +template bool CPhysicalQuantity::operator ==(const CPhysicalQuantity &otherQuantity) const { - if(this == &otherQuantity) return true; - if(this->m_unit.getType()!= otherQuantity.m_unit.getType()) return false; + if (this == &otherQuantity) return true; + if (this->m_unit.getType() != otherQuantity.m_unit.getType()) return false; // some special cases for best quality double diff; @@ -68,15 +76,17 @@ template bool CPhysicalQuantity::operator ==(const C /** * Not equal */ -template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &otherQuantity) const { - if(this == &otherQuantity) return false; +template bool CPhysicalQuantity::operator !=(const CPhysicalQuantity &otherQuantity) const +{ + if (this == &otherQuantity) return false; return !(*this == otherQuantity); } /** * Assigment operator = */ -template CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &otherQuantity) { +template CPhysicalQuantity& CPhysicalQuantity::operator=(const CPhysicalQuantity &otherQuantity) +{ // Check for self-assignment! if (this == &otherQuantity) return *this; // Same object? @@ -93,7 +103,7 @@ template CPhysicalQuantity& CPhysicalQuantity /** * Plus operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity &CPhysicalQuantity::operator +=(const CPhysicalQuantity &otherQuantity) { if (this->m_unit == otherQuantity.m_unit) { // same unit @@ -124,7 +134,7 @@ template PQ CPhysicalQuantity::operator +(const PQ /** * Explicit plus */ -template void CPhysicalQuantity::addUnitValue(double value) +template void CPhysicalQuantity::addUnitValue(double value) { this->setUnitValue(this->m_unitValueD + value); } @@ -132,7 +142,7 @@ template void CPhysicalQuantity::addUnitValue(double /** * Explicit minus */ -template void CPhysicalQuantity::substractUnitValue(double value) +template void CPhysicalQuantity::substractUnitValue(double value) { this->setUnitValue(this->m_unitValueD - value); } @@ -140,7 +150,7 @@ template void CPhysicalQuantity::substractUnitValue( /** * Minus operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &otherQuantity) +template CPhysicalQuantity &CPhysicalQuantity::operator -=(const CPhysicalQuantity &otherQuantity) { if (this->m_unit == otherQuantity.m_unit) { // same unit @@ -171,9 +181,9 @@ template PQ CPhysicalQuantity::operator -(const PQ /** * Multiply operator */ -template CPhysicalQuantity &CPhysicalQuantity::operator *=(double multiply) +template CPhysicalQuantity &CPhysicalQuantity::operator *=(double multiply) { - this->setUnitValue(this->m_unitValueD *multiply); + this->setUnitValue(this->m_unitValueD * multiply); return *this; } @@ -191,7 +201,7 @@ template PQ CPhysicalQuantity::operator *(double mu /** * Divide operator /= */ -template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divide) +template CPhysicalQuantity &CPhysicalQuantity::operator /=(double divide) { this->setUnitValue(this->m_unitValueD / divide); return *this; @@ -200,7 +210,7 @@ template CPhysicalQuantity &CPhysicalQuantity /** * Divide operator / */ -template PQ CPhysicalQuantity::operator /(double divide) const +template PQ CPhysicalQuantity::operator /(double divide) const { PQ div; div += (*this); @@ -211,8 +221,9 @@ template PQ CPhysicalQuantity::operator /(double div /** * Less operator < */ -template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &otherQuantity) const { - if(this == &otherQuantity) return false; +template bool CPhysicalQuantity::operator <(const CPhysicalQuantity &otherQuantity) const +{ + if (this == &otherQuantity) return false; double diff = this->m_convertedSiUnitValueD - otherQuantity.m_convertedSiUnitValueD; return (diff < 0 && abs(diff) >= this->m_unit.getEpsilon()); } @@ -220,31 +231,34 @@ template bool CPhysicalQuantity::operator <(const CP /** * Greater than */ -template bool CPhysicalQuantity::operator >(const CPhysicalQuantity &otherQuantity) const { - if(this == &otherQuantity) return false; +template bool CPhysicalQuantity::operator >(const CPhysicalQuantity &otherQuantity) const +{ + if (this == &otherQuantity) return false; return otherQuantity < *this; } /** * Greater / Equal */ -template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &otherQuantity) const { - if(this == &otherQuantity) return true; +template bool CPhysicalQuantity::operator >=(const CPhysicalQuantity &otherQuantity) const +{ + if (this == &otherQuantity) return true; return !(*this < otherQuantity); } /** * Less equal */ -template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &otherQuantity) const { - if(this == &otherQuantity) return true; +template bool CPhysicalQuantity::operator <=(const CPhysicalQuantity &otherQuantity) const +{ + if (this == &otherQuantity) return true; return !(*this > otherQuantity); } /** * Switch to another unit */ -template bool CPhysicalQuantity::switchUnit(const MU &newUnit) +template bool CPhysicalQuantity::switchUnit(const MU &newUnit) { if (this->m_unit == newUnit) return true; if (this->m_unit.getType() != newUnit.getType()) return false; // not possible @@ -257,10 +271,10 @@ template bool CPhysicalQuantity::switchUnit(const MU /** * Init by integer */ -template void CPhysicalQuantity::setUnitValue(qint32 baseValue) +template void CPhysicalQuantity::setUnitValue(qint32 baseValue) { - this->m_unitValueI= baseValue; - this->m_unitValueD= double(baseValue); + this->m_unitValueI = baseValue; + this->m_unitValueD = double(baseValue); this->m_isIntegerBaseValue = true; this->setConversionSiUnitValue(); } @@ -268,7 +282,7 @@ template void CPhysicalQuantity::setUnitValue(qint32 /** * Init by double */ -template void CPhysicalQuantity::setUnitValue(double baseValue) +template void CPhysicalQuantity::setUnitValue(double baseValue) { this->m_unitValueD = baseValue; this->m_unitValueI = qRound(baseValue); @@ -279,7 +293,8 @@ template void CPhysicalQuantity::setUnitValue(double /** * Set SI value */ -template void CPhysicalQuantity::setConversionSiUnitValue() { +template void CPhysicalQuantity::setConversionSiUnitValue() +{ double si = this->m_unit.convertToSiConversionUnit(this->m_unitValueD); this->m_convertedSiUnitValueD = si; } @@ -287,7 +302,7 @@ template void CPhysicalQuantity::setConversionSiUnit /** * Round */ -template double CPhysicalQuantity::unitValueToDoubleRounded(int digits) const +template double CPhysicalQuantity::unitValueToDoubleRounded(int digits) const { return this->m_unit.valueRounded(this->m_unitValueD, digits); } @@ -295,7 +310,7 @@ template double CPhysicalQuantity::unitValueToDouble /** * Rounded value to QString */ -template QString CPhysicalQuantity::unitValueToQStringRounded(int digits) const +template QString CPhysicalQuantity::unitValueToQStringRounded(int digits) const { return this->m_unit.toQStringRounded(this->m_unitValueD, digits); } @@ -303,7 +318,7 @@ template QString CPhysicalQuantity::unitValueToQStri /** * Rounded with unit */ -template QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits) const +template QString CPhysicalQuantity::unitValueRoundedWithUnit(int digits) const { return this->m_unit.valueRoundedWithUnit(this->m_unitValueD, digits); } @@ -311,7 +326,7 @@ template QString CPhysicalQuantity::unitValueRounded /** * Rounded SI value to QString */ -template QString CPhysicalQuantity::convertedSiValueToQStringRounded(int digits) const +template QString CPhysicalQuantity::convertedSiValueToQStringRounded(int digits) const { if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); return this->m_conversionSiUnit.toQStringRounded(this->m_convertedSiUnitValueD, digits); @@ -320,7 +335,8 @@ template QString CPhysicalQuantity::convertedSiValue /** * SI base unit value with unit */ -template QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits) const { +template QString CPhysicalQuantity::convertedSiValueRoundedWithUnit(int digits) const +{ if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); return this->convertedSiValueToQStringRounded(digits).append(this->m_conversionSiUnit.getUnitName()); } @@ -328,25 +344,25 @@ template QString CPhysicalQuantity::convertedSiValue /** * Value rounded in unit */ -template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits) const +template QString CPhysicalQuantity::valueRoundedWithUnit(const MU &unit, int digits) const { if (unit == this->m_unit) return this->unitValueRoundedWithUnit(digits); if (unit == this->m_conversionSiUnit) return this->convertedSiValueRoundedWithUnit(digits); - return unit.valueRoundedWithUnit(this->value(unit),digits); + return unit.valueRoundedWithUnit(this->value(unit), digits); } /** * Value rounded in unit */ -template double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const +template double CPhysicalQuantity::valueRounded(const MU &unit, int digits) const { - return unit.valueRounded(this->value(unit),digits); + return unit.valueRounded(this->value(unit), digits); } /** * Value in unit */ -template double CPhysicalQuantity::value(const MU &unit) const +template double CPhysicalQuantity::value(const MU &unit) const { if (unit == this->m_unit) return this->m_unitValueD; if (unit == this->m_conversionSiUnit) return this->m_convertedSiUnitValueD; @@ -357,7 +373,7 @@ template double CPhysicalQuantity::value(const MU &u /** * Round utility method */ -template double CPhysicalQuantity::convertedSiValueToDoubleRounded(int digits) const +template double CPhysicalQuantity::convertedSiValueToDoubleRounded(int digits) const { if (digits < 1) digits = this->m_conversionSiUnit.getDisplayDigits(); return this->m_conversionSiUnit.valueRounded(this->m_convertedSiUnitValueD, digits); @@ -375,5 +391,5 @@ template class CPhysicalQuantity; template class CPhysicalQuantity; template class CPhysicalQuantity; - +} // namespace } // namespace diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index d541af155..ff0ef6b34 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -1,3 +1,8 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQPHYSICALQUANTITY_H #define PQPHYSICALQUANTITY_H @@ -8,7 +13,10 @@ #include "blackmisc/pqunits.h" #include "blackmisc/debug.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief A physical quantity such as "5m", "20s", "1500ft/s" @@ -57,7 +65,9 @@ protected: * \brief String for streaming operators * \return */ - virtual QString stringForStreamingOperator() const { return this->unitValueRoundedWithUnit(-1); } + virtual QString stringForStreamingOperator() const { + return this->unitValueRoundedWithUnit(-1); + } /*! * \brief Constructor with int @@ -84,7 +94,7 @@ protected: * \brief Init by double * \param baseValue */ - void setUnitValue (double baseValue); + void setUnitValue(double baseValue); /*! * \brief Set the SI value */ @@ -103,12 +113,16 @@ public: * \brief Unit of the distance * \return */ - MU getUnit() const { return this->m_unit; } + MU getUnit() const { + return this->m_unit; + } /*! * \brief Conversion SI unit * \return */ - MU getConversionSiUnit() const { return this->m_conversionSiUnit; } + MU getConversionSiUnit() const { + return this->m_conversionSiUnit; + } /*! * \brief Switch unit, e.g. feet meter * \param newUnit @@ -119,17 +133,23 @@ public: * \brief Value in SI base unit? Meter is an SI base unit, hertz not! * \return */ - bool isSiBaseUnit() const { return this->m_unit.isSiBaseUnit(); } + bool isSiBaseUnit() const { + return this->m_unit.isSiBaseUnit(); + } /*! * \brief Value in SI unit? Hertz is an derived SI unit, NM not! * \return */ - bool isSiUnit() const { return this->m_unit.isSiUnit(); } + bool isSiUnit() const { + return this->m_unit.isSiUnit(); + } /*! * \brief Value in unprefixed SI unit? Meter is a unprefixed, kilometer a prefixed SI Unit * \return */ - bool isUnprefixedSiUnit() const { return this->m_unit.isUnprefixedSiUnit(); } + bool isUnprefixedSiUnit() const { + return this->m_unit.isUnprefixedSiUnit(); + } /*! * \brief Value in given unit * \param unit @@ -154,12 +174,16 @@ public: * \brief Value a int * @return */ - qint32 unitValueToInteger() const { return this->m_unitValueI;} + qint32 unitValueToInteger() const { + return this->m_unitValueI; + } /*! * \brief Value a double * @return */ - double unitValueToDouble() const { return this->m_unitValueD;} + double unitValueToDouble() const { + return this->m_unitValueD; + } /*! * \brief Value to QString with unit, e.g. "5.00m" * \param digits @@ -170,12 +194,16 @@ public: * \brief SI value to integer * @return */ - qint32 siBaseUnitValueToInteger() const { return CMeasurementUnit::round(this->m_convertedSiUnitValueD,0);} + qint32 siBaseUnitValueToInteger() const { + return CMeasurementUnit::round(this->m_convertedSiUnitValueD, 0); + } /*! * \brief SI value to double * @return */ - double siBaseUnitValueToDouble() const { return this->m_convertedSiUnitValueD;} + double siBaseUnitValueToDouble() const { + return this->m_convertedSiUnitValueD; + } /*! * \brief Rounded value by n digits * \param digits @@ -192,12 +220,16 @@ public: * \brief SI value as double * \return */ - double convertedSiValueToDouble() const { return this->m_convertedSiUnitValueD;} + double convertedSiValueToDouble() const { + return this->m_convertedSiUnitValueD; + } /*! * \brief SI value as integer * \return */ - qint32 convertedSiValueToInteger() const { return static_cast(CMeasurementUnit::round(this->m_convertedSiUnitValueD,0));} + qint32 convertedSiValueToInteger() const { + return static_cast(CMeasurementUnit::round(this->m_convertedSiUnitValueD, 0)); + } /*! * \brief Rounded SI value by n digits * \param digits @@ -231,8 +263,9 @@ public: /*! * \brief Cast as QString */ - operator QString() const { return this->unitValueRoundedWithUnit();} - + operator QString() const { + return this->unitValueRoundedWithUnit(); + } /*! * \brief Multiply operator *= * \param multiply @@ -326,6 +359,7 @@ public: }; +} // namespace } // namespace #endif // PQPHYSICALQUANTITY_H diff --git a/src/blackmisc/pqpressure.h b/src/blackmisc/pqpressure.h index f64568f99..27ccfb816 100644 --- a/src/blackmisc/pqpressure.h +++ b/src/blackmisc/pqpressure.h @@ -1,21 +1,29 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQPRESSURE_H #define PQPRESSURE_H #include "pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief Physical unit distance * \author KWB */ -class CPressure : public CPhysicalQuantity +class CPressure : public CPhysicalQuantity { public: /*! * \brief Default constructor */ - CPressure() : CPhysicalQuantity(0, CPressureUnit::Pa(), CPressureUnit::Pa()){} + CPressure() : CPhysicalQuantity(0, CPressureUnit::Pa(), CPressureUnit::Pa()) {} /** *\brief Copy constructor */ @@ -25,17 +33,18 @@ public: * \param value * \param unit */ - CPressure(qint32 value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()){} + CPressure(qint32 value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} /*! *\brief Init by double value * \param value * \param unit */ - CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()){} + CPressure(double value, const CPressureUnit &unit) : CPhysicalQuantity(value, unit, CPressureUnit::Pa()) {} /*! * \brief Virtual destructor */ virtual ~CPressure() {} }; } // namespace +} // namespace #endif // PQPRESSURE_H diff --git a/src/blackmisc/pqspeed.h b/src/blackmisc/pqspeed.h index da4f9d56a..5aab5b109 100644 --- a/src/blackmisc/pqspeed.h +++ b/src/blackmisc/pqspeed.h @@ -1,8 +1,16 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef CSPEED_H #define CSPEED_H #include "pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * Speed class, e.g. "m/s", "NM/h", "km/h", "ft/s" @@ -37,5 +45,6 @@ public: virtual ~CSpeed() {} }; } // namespace +} // namespace #endif // CSPEED_H diff --git a/src/blackmisc/pqtemperature.h b/src/blackmisc/pqtemperature.h index c27df8603..9e2721999 100644 --- a/src/blackmisc/pqtemperature.h +++ b/src/blackmisc/pqtemperature.h @@ -1,14 +1,22 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef CTEMPERATURE_H #define CTEMPERATURE_H #include "pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * \brief Physical unit temperature * \author KWB */ -class CTemperature : public CPhysicalQuantity +class CTemperature : public CPhysicalQuantity { public: /*! @@ -18,7 +26,7 @@ public: /** *\brief Copy constructor */ - CTemperature(const CTemperature &temperature) : CPhysicalQuantity(temperature){} + CTemperature(const CTemperature &temperature) : CPhysicalQuantity(temperature) {} /*! * \brief Init by int value * \param value @@ -37,5 +45,5 @@ public: virtual ~CTemperature() {} }; } // namespace - +} // namespace #endif // CTEMPERATURE_H diff --git a/src/blackmisc/pqtime.h b/src/blackmisc/pqtime.h index 66f3724e4..1e9eb1048 100644 --- a/src/blackmisc/pqtime.h +++ b/src/blackmisc/pqtime.h @@ -1,9 +1,17 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQTIME_H #define PQTIME_H #include "pqphysicalquantity.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /*! * Time class, e.g. "ms", "hour", "s", "day" @@ -38,6 +46,6 @@ public: virtual ~CTime() {} }; } // namespace - +} // namespace #endif // PQTIME_H diff --git a/src/blackmisc/pqunits.cpp b/src/blackmisc/pqunits.cpp index 936ba1c33..36b469c80 100644 --- a/src/blackmisc/pqunits.cpp +++ b/src/blackmisc/pqunits.cpp @@ -1,6 +1,14 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "blackmisc/pqunits.h" -namespace BlackMisc { +namespace BlackMisc +{ +namespace PhysicalQuantities +{ /** * Convert to SI @@ -34,8 +42,8 @@ double CAngleUnit::conversionSexagesimalFromSi(const CMeasurementUnit &angleUnit double c = value - v; double mr = c * 60.0; double m = floor(mr); // minutes - double s = (mr-m) * 60; // seconds + rest fraction - v = (v + (m/100) + (s/10000)); + double s = (mr - m) * 60; // seconds + rest fraction + v = (v + (m / 100) + (s / 10000)); return v; } @@ -64,11 +72,11 @@ QString CAngleUnit::toQStringRounded(double value, int digits) const if ((*this) == CAngleUnit::sexagesimalDeg()) { // special formatting for sexagesimal degrees double de = floor(value); - double mi = floor((value-de)*100.0); - double se = floor((value-de-mi/100.0)*1000000) / 100.0; + double mi = floor((value - de) * 100.0); + double se = floor((value - de - mi / 100.0) * 1000000) / 100.0; QString ses = QLocale::system().toString(se, 'f', 2); s = QString::number(de).append(this->getUnitName()).append(QString::number(mi)) - .append("'").append(ses).append("\""); + .append("'").append(ses).append("\""); } else { s = CMeasurementUnit::toQStringRounded(value, digits); } @@ -76,3 +84,4 @@ QString CAngleUnit::toQStringRounded(double value, int digits) const } } // namespace +} // namespace diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index 12570f34d..63f427902 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -1,3 +1,8 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #ifndef PQUNITS_H #define PQUNITS_H #include "blackmisc/pqbase.h" @@ -7,13 +12,18 @@ // Used with the template for quantities. This is the reason for // having all units in one file, since template requires concrete instantiations // -namespace BlackMisc { +namespace BlackMisc +{ + +namespace PhysicalQuantities +{ /*! * Specialized class for distance units (meter, foot, nautical miles). * \author KWB, MS */ -class CLengthUnit : public CMeasurementUnit { +class CLengthUnit : public CMeasurementUnit +{ private: /*! * \brief Constructor Distance unit @@ -27,47 +37,61 @@ private: * \param epsilon */ CLengthUnit(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) - { + CMeasurementUnit(name, unitName, "distance", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon) { // void } public: - CLengthUnit(const CLengthUnit &otherUnit) : CMeasurementUnit(otherUnit) - { + CLengthUnit(const CLengthUnit &otherUnit) : CMeasurementUnit(otherUnit) { // void } /*! * \brief Meter m * \return */ - static const CLengthUnit& m() { static CLengthUnit m("meter", "m", true, true); return m;} + static const CLengthUnit& m() { + static CLengthUnit m("meter", "m", true, true); + return m; + } /*! * \brief Nautical miles NM * \return */ - static const CLengthUnit& NM() { static CLengthUnit NM("nautical miles", "NM", false, false, 1000.0*1.85200, CMeasurementPrefix::One(), 3);return NM;} + static const CLengthUnit& NM() { + static CLengthUnit NM("nautical miles", "NM", false, false, 1000.0 * 1.85200, CMeasurementPrefix::One(), 3); + return NM; + } /*! * \brief Foot ft * \return */ - static const CLengthUnit& ft() { static CLengthUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); return ft;} + static const CLengthUnit& ft() { + static CLengthUnit ft("foot", "ft", false, false, 0.3048, CMeasurementPrefix::One(), 0); + return ft; + } /*! * \brief Kilometer km * \return */ - static const CLengthUnit& km() { static CLengthUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3);return km;} + static const CLengthUnit& km() { + static CLengthUnit km("kilometer", "km", true, false, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 3); + return km; + } /*! * \brief Centimeter cm * \return */ - static const CLengthUnit& cm() { static CLengthUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1);return cm;} + static const CLengthUnit& cm() { + static CLengthUnit cm("centimeter", "cm", true, false, CMeasurementPrefix::c().getFactor(), CMeasurementPrefix::c(), 1); + return cm; + } }; /*! * Specialized class for angles (degrees, radian). * \author KWB, MS */ -class CAngleUnit : public CMeasurementUnit { +class CAngleUnit : public CMeasurementUnit +{ private: /*! * \brief Constructor angle units: Radian, degree @@ -81,10 +105,9 @@ private: */ 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, UnitConverter converterToSi = nullptr, UnitConverter converterFromSi= nullptr) : + double epsilon = 1E-9, UnitConverter converterToSi = nullptr, UnitConverter converterFromSi = nullptr) : CMeasurementUnit(name, unitName, "angle", isSIUnit, false, conversionFactorToSI, - mulitplier, displayDigits, epsilon, converterToSi, converterFromSi) - { + mulitplier, displayDigits, epsilon, converterToSi, converterFromSi) { // void } /*! @@ -117,25 +140,34 @@ public: * \brief Radians * \return */ - static const CAngleUnit& rad() { static CAngleUnit rad("radian", "rad", true); return rad;} + static const CAngleUnit& rad() { + static CAngleUnit rad("radian", "rad", true); + return rad; + } /*! * \brief Degrees * \return */ - static const 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; + } /*! * \brief Sexagesimal degree (degree, minute, seconds) * \return */ - static const CAngleUnit& sexagesimalDeg() { static CAngleUnit deg("segadecimal degree", "°", false, M_PI/180, - CMeasurementPrefix::One(),0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg;} + static const CAngleUnit& sexagesimalDeg() { + static CAngleUnit deg("segadecimal degree", "°", false, M_PI / 180, + CMeasurementPrefix::One(), 0, 1E-9, CAngleUnit::conversionSexagesimalToSi, CAngleUnit::conversionSexagesimalFromSi); return deg; + } }; /*! * Specialized class for frequency (hertz, mega hertz, kilo hertz). * \author KWB, MS */ -class CFrequencyUnit : public CMeasurementUnit { +class CFrequencyUnit : public CMeasurementUnit +{ private: /*! * Constructor @@ -151,37 +183,49 @@ private: 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) {} public: - CFrequencyUnit(const CFrequencyUnit &otherUnit) : CMeasurementUnit(otherUnit) - { + CFrequencyUnit(const CFrequencyUnit &otherUnit) : CMeasurementUnit(otherUnit) { // void } /*! * \brief Hertz * \return */ - static const 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 const CFrequencyUnit& kHz() { static CFrequencyUnit kHz("kilohertz", "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 1);return kHz;} + static const CFrequencyUnit& kHz() { + static CFrequencyUnit kHz("kilohertz", "kHz", true, CMeasurementPrefix::k().getFactor(), CMeasurementPrefix::k(), 1); + return kHz; + } /*! * \brief Megahertz * \return */ - static const CFrequencyUnit& MHz() { static CFrequencyUnit MHz("megahertz", "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 2); return MHz;} + static const CFrequencyUnit& MHz() { + static CFrequencyUnit MHz("megahertz", "MHz", false, CMeasurementPrefix::M().getFactor(), CMeasurementPrefix::M(), 2); + return MHz; + } /*! * \brief Gigahertz * \return */ - static const CFrequencyUnit& GHz() { static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2);return GHz;} + static const CFrequencyUnit& GHz() { + static CFrequencyUnit GHz("gigahertz", "GHz", true, CMeasurementPrefix::G().getFactor(), CMeasurementPrefix::G(), 2); + return GHz; + } }; /*! * Specialized class for mass units (kg, lbs). * \author KWB, MS */ -class CMassUnit : public CMeasurementUnit { +class CMassUnit : public CMeasurementUnit +{ private: /*! * \brief Constructor mass units @@ -197,37 +241,49 @@ private: 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) {} public: - CMassUnit(const CMassUnit &otherUnit) : CMeasurementUnit(otherUnit) - { + CMassUnit(const CMassUnit &otherUnit) : CMeasurementUnit(otherUnit) { // void } /*! * \brief Kilogram, SI base unit * \return */ - static const 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 const 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 const CMassUnit& t() { static CMassUnit t("tonne", "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); return t;} + static const CMassUnit& t() { + static CMassUnit t("tonne", "t", false, false, 1000.0, CMeasurementPrefix::One(), 3); + return t; + } /*! * \brief Pound, aka mass pound * \return */ - static const 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; + } }; /*! * Specialized class for pressure (psi, hPa, bar). * \author KWB, MS */ -class CPressureUnit : public CMeasurementUnit { +class CPressureUnit : public CMeasurementUnit +{ private: /*! * Constructor @@ -247,52 +303,73 @@ public: * \brief Copy constructor * \param otherUnit */ - CPressureUnit(const CPressureUnit &otherUnit) : CMeasurementUnit(otherUnit) - { + CPressureUnit(const CPressureUnit &otherUnit) : CMeasurementUnit(otherUnit) { // void } /*! * \brief Pascal * \return */ - static const 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 const 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 const 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 const 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 const 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 const 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 const 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; + } }; /*! * Specialized class for temperatur units (kelvin, centidegree). * \author KWB */ -class CTemperatureUnit : public CMeasurementUnit { +class CTemperatureUnit : public CMeasurementUnit +{ private: double m_conversionOffsetToSi; private: @@ -308,7 +385,7 @@ private: * \param displayDigits * \param epsilon */ - CTemperatureUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI=0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : + CTemperatureUnit(const QString &name, const QString &unitName, bool isSIUnit, bool isSIBaseUnit, double conversionFactorToSI = 1.0, double temperatureOffsetToSI = 0, const CMeasurementPrefix &mulitplier = CMeasurementPrefix::One(), qint32 displayDigits = 2, double epsilon = 1E-9) : CMeasurementUnit(name, unitName, "temperature", isSIUnit, isSIBaseUnit, conversionFactorToSI, mulitplier, displayDigits, epsilon), m_conversionOffsetToSi(temperatureOffsetToSI) {} protected: /*! @@ -332,8 +409,7 @@ public: /*! * Assigment operator */ - CTemperatureUnit &CTemperatureUnit::operator =(const CTemperatureUnit &otherUnit) - { + CTemperatureUnit &CTemperatureUnit::operator =(const CTemperatureUnit &otherUnit) { if (this == &otherUnit) return *this; // Same object? Yes, so skip assignment, and just return *this CMeasurementUnit::operator = (otherUnit); this->m_conversionOffsetToSi = otherUnit.m_conversionOffsetToSi; @@ -343,24 +419,34 @@ public: * \brief Kelvin * \return */ - static const 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 const CTemperatureUnit& C() { static CTemperatureUnit C("centigrade", "°C", false, false, 1.0, 273.15);return C;} + static const CTemperatureUnit& C() { + static CTemperatureUnit C("centigrade", "°C", false, false, 1.0, 273.15); + return C; + } /*! * \brief Fahrenheit F * \return */ - static const CTemperatureUnit& F() { static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0/9.0, 459.67);return F;} + static const CTemperatureUnit& F() { + static CTemperatureUnit F("Fahrenheit", "°F", false, false, 5.0 / 9.0, 459.67); + return F; + } }; /*! * Specialized class for speed units (m/s, ft/s, NM/h). * \author KWB */ -class CSpeedUnit : public CMeasurementUnit { +class CSpeedUnit : public CMeasurementUnit +{ private: /*! * Constructor @@ -386,39 +472,58 @@ public: * \brief Meter/second m/s * \return */ - static const CSpeedUnit& m_s() { static CSpeedUnit ms("meters/second", "m/s", true, false); return ms;} + static const CSpeedUnit& m_s() { + static CSpeedUnit ms("meters/second", "m/s", true, false); + return ms; + } /*! * \brief Knots * \return */ - static const CSpeedUnit& kts() { static CSpeedUnit kts("knot", "kts", false, false, 1852.0/3600.0, CMeasurementPrefix::One(), 1);return kts;} + static const CSpeedUnit& kts() { + static CSpeedUnit kts("knot", "kts", false, false, 1852.0 / 3600.0, CMeasurementPrefix::One(), 1); + return kts; + } /*! * \brief Nautical miles per hour NM/h (same as kts) * \return */ - static const 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 const 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 const 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 const CSpeedUnit& km_h() { static CSpeedUnit kmh("kilometers/hour", "km/h", false, false, 1.0/3.6, CMeasurementPrefix::One(), 1);return kmh;} + static const CSpeedUnit& km_h() { + static CSpeedUnit kmh("kilometers/hour", "km/h", false, false, 1.0 / 3.6, CMeasurementPrefix::One(), 1); + return kmh; + } }; /*! * Specialized class for time units (ms, hour, min). * \author KWB */ -class CTimeUnit : public CMeasurementUnit { +class CTimeUnit : public CMeasurementUnit +{ private: /*! * Constructor @@ -444,29 +549,45 @@ public: * \brief Second s * \return */ - static const CTimeUnit& s() { static CTimeUnit s("second", "s", true, true, 1, CMeasurementPrefix::None(), 1); return s;} + static const CTimeUnit& s() { + static CTimeUnit s("second", "s", true, true, 1, CMeasurementPrefix::None(), 1); + return s; + } /*! * \brief Millisecond ms * \return */ - static const CTimeUnit& ms() { static CTimeUnit ms("millisecond", "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); return ms;} + static const CTimeUnit& ms() { + static CTimeUnit ms("millisecond", "ms", true, false, 1E-03, CMeasurementPrefix::m(), 0); + return ms; + } /*! * \brief Hour * \return */ - static const CTimeUnit& h() { static CTimeUnit h("hour", "h", false, false, 3600, CMeasurementPrefix::None(), 1); return h;} + static const CTimeUnit& h() { + static CTimeUnit h("hour", "h", false, false, 3600, CMeasurementPrefix::None(), 1); + return h; + } /*! * \brief Minute * \return */ - static const CTimeUnit& min() { static CTimeUnit min("minute", "min", false, false, 60, CMeasurementPrefix::None(), 2); return min;} + static const CTimeUnit& min() { + static CTimeUnit min("minute", "min", false, false, 60, CMeasurementPrefix::None(), 2); + return min; + } /*! * \brief Day * \return */ - static const CTimeUnit& d() { static CTimeUnit day("day", "d", false, false, 3600*24, CMeasurementPrefix::None(), 1); return day;} + static const CTimeUnit& d() { + static CTimeUnit day("day", "d", false, false, 3600 * 24, CMeasurementPrefix::None(), 1); + return day; + } }; +} // namespace } // namespace #endif // PQUNITS_H diff --git a/tests/blackmisc/testaviationbase.cpp b/tests/blackmisc/testaviationbase.cpp index 437e46bd2..3597a974a 100644 --- a/tests/blackmisc/testaviationbase.cpp +++ b/tests/blackmisc/testaviationbase.cpp @@ -1,3 +1,8 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "testaviationbase.h" namespace BlackMiscTest { @@ -49,11 +54,34 @@ void CTestAviationBase::verticalPosition() */ void CTestAviationBase::comAndNav() { - CComSystem c1 = CComSystem::getCom1Unit(122.8); - CComSystem c2 = CComSystem::getCom2Unit(122.8); - QVERIFY2(c1 != c2, "COM units shall not be equal"); + CComSystem c1 = CComSystem::getCom1System(122.8); + CComSystem c2 = CComSystem::getCom2System(122.8); + QVERIFY2(c1 != c2, "COM system shall not be equal"); c1 = c2; - QVERIFY2(c1 == c2, "COM units shall be equal"); + QVERIFY2(c1 == c2, "COM system shall be equal"); + CFrequency f(100.0, CFrequencyUnit::MHz()); + QVERIFY2(!CComSystem::tryGetComSystem(c1, "no valid unit", f), "Expect not to get COM system"); + CNavSystem nav1; + QVERIFY2(CNavSystem::tryGetNav1System(nav1, 110.0), "Expect NAV system"); + QVERIFY2(!CNavSystem::tryGetNav1System(nav1, 200.0), "Expect no NAV system"); +} + +/** + * COM and NAV units + */ +void CTestAviationBase::transponder() +{ + CTransponder t1 = CTransponder::getStandardTransponder(7000, CTransponder::StateStandby); + CTransponder t2 = t1; + QVERIFY2(t1 == t2, "Transponders shall be equal"); + t2.setTransponderMode(CTransponder::ModeC); + QVERIFY2(t1 != t2, "Transponders shall not be equal"); + QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, 8888, CTransponder::StateStandby), "No valid transponder"); + QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, 781, CTransponder::StateStandby), "No valid transponder"); + QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, "0781", CTransponder::StateStandby), "No valid transponder"); + QVERIFY2(CTransponder::tryGetStandardTransponder(t1, "7211", CTransponder::StateStandby), "No valid transponder"); + QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, "schnitzel", CTransponder::StateStandby), "No valid transponder"); + } } // namespace diff --git a/tests/blackmisc/testaviationbase.h b/tests/blackmisc/testaviationbase.h index 51b9cda28..08481c189 100644 --- a/tests/blackmisc/testaviationbase.h +++ b/tests/blackmisc/testaviationbase.h @@ -6,8 +6,10 @@ #include "blackmisc/avheading.h" #include "blackmisc/avverticalpositions.h" #include "blackmisc/aviocomsystem.h" +#include "blackmisc/avionavsystem.h" +#include "blackmisc/aviotransponder.h" -using namespace BlackMisc; +using namespace BlackMisc::Aviation; namespace BlackMiscTest { @@ -30,17 +32,19 @@ private slots: * \brief Basic unit tests for physical units */ void headingBasics(); - /*! * \brief Vertical positions */ void verticalPosition(); - /*! * \brief COM and NAV units */ void comAndNav(); + /*! + * \brief Transponder + */ + void transponder(); }; } // namespace diff --git a/tests/blackmisc/testphysicalquantitiesbase.cpp b/tests/blackmisc/testphysicalquantitiesbase.cpp index 3ad129f51..6cfefa612 100644 --- a/tests/blackmisc/testphysicalquantitiesbase.cpp +++ b/tests/blackmisc/testphysicalquantitiesbase.cpp @@ -1,3 +1,8 @@ +/* Copyright (C) 2013 VATSIM Community + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "testphysicalquantitiesbase.h" namespace BlackMiscTest { diff --git a/tests/blackmisc/testphysicalquantitiesbase.h b/tests/blackmisc/testphysicalquantitiesbase.h index d015c1a4c..6523193ac 100644 --- a/tests/blackmisc/testphysicalquantitiesbase.h +++ b/tests/blackmisc/testphysicalquantitiesbase.h @@ -3,9 +3,11 @@ #include #include "blackmisc/pqconstants.h" -using namespace BlackMisc; -namespace BlackMiscTest { +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackMiscTest +{ /*! * \brief Physical quantities,basic tests @@ -13,6 +15,7 @@ namespace BlackMiscTest { class CTestPhysicalQuantitiesBase : public QObject { Q_OBJECT + public: /*! * \brief Standard test case constructor