refs #192, some housekeeping during the JSON introduction

* removed unused tryGet methods for transponder / COM
* adjusted unit tests
This commit is contained in:
Klaus Basan
2014-03-26 18:55:40 +01:00
parent e2461cb67c
commit 57435b2a73
5 changed files with 60 additions and 290 deletions

View File

@@ -135,181 +135,52 @@ namespace BlackMisc
//! \copydoc CValueObject::fromJson
virtual void fromJson(const QJsonObject &json) override;
/*!
* 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[out] o_comSystem
* \param name
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
o_comSystem = CComSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
bool s;
if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default
return s;
}
//! \brief Members
static const QStringList &jsonMembers();
/*!
* 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[out] o_comSystem
* \param name
* \param activeFrequency
* \param standbyFrequency
* \return
*/
static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
o_comSystem = CComSystem(false, name, activeFrequency, standbyFrequency);
bool s;
if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default
return s;
}
//! \brief operator ==
bool operator ==(const CComSystem &other) const;
/*!
* \brief COM1 unit
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
//! \brief operator !=
bool operator !=(const CComSystem &other) const;
//! \brief COM1 unit
static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
return CComSystem(CModulator::NameCom1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
}
/*!
* \brief COM1 unit
* \param activeFrequency
* \param standbyFrequency
* \return
*/
//! \brief COM1 unit
static CComSystem getCom1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);
}
/*!
* \brief Try to get COM unit
* \param[out] o_comSystem
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
static bool tryGetCom1Unit(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz);
}
/*!
* \brief Try to get COM unit
* \param[out] o_comSystem
* \param activeFrequency
* \param standbyFrequency
* \return
*/
static bool tryGetCom1Unit(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency);
}
/*!
* \brief COM2 unit
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
//! \brief COM2 unit
static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
return CComSystem(CModulator::NameCom2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
}
/*!
* \brief COM2 unit
* \param activeFrequency
* \param standbyFrequency
* \return
*/
//! \brief COM2 unit
static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);
}
/*!
* \brief Try to get COM unit
* \param[out] o_comSystem
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
static bool tryGetCom2System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz);
}
/*!
* \brief Try to get COM unit
* \param[out] o_comSystem
* \param activeFrequency
* \param standbyFrequency
* \return
*/
static bool tryGetCom2System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency);
}
/*!
* \brief COM3 unit
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
//! \brief COM3 unit
static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
return CComSystem(CModulator::NameCom3(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
}
/*!
* \brief COM3 unit
* \param activeFrequency
* \param standbyFrequency
* \return
*/
//! \brief COM3 unit
static CComSystem getCom3System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
return CComSystem(CModulator::NameCom3(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);
}
/*!
* \brief Try to get COM unit
* \param[out] o_comSystem
* \param activeFrequencyMHz
* \param standbyFrequencyMHz
* \return
*/
static bool tryGetCom3System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
{
return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz);
}
/*!
* \brief Try to get COM unit
* \param[out] o_comSystem
* \param activeFrequency
* \param standbyFrequency
* \return
*/
static bool tryGetCom3System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
{
return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency);
}
/*!
* \brief Valid civil aviation frequency?
*/
//! \brief Valid civil aviation frequency?
static bool isValidCivilAviationFrequency(const BlackMisc::PhysicalQuantities::CFrequency &f)
{
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), 3);

View File

@@ -34,45 +34,8 @@ namespace BlackMisc
qint32 m_transponderCode; //<! Transponder code
TransponderMode m_transponderMode; //<! Transponder mode
/*!
* \brief Constructor for validation
* \param validate
* \param name
* \param transponderCode
* \param transponderMode
*/
CTransponder(bool validate, const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
{
this->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) :
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(validate);
}
protected:
/*!
* \copydoc CAvionicsBase::validValues
*/
virtual bool validValues() const override;
/*!
* \brief Default value
* \return
*/
//! \brief Default value?
virtual bool isDefaultValue() const
{
return this->m_transponderCode == 0;
@@ -100,36 +63,21 @@ namespace BlackMisc
virtual int compareImpl(const CValueObject &other) const override;
public:
/*!
* Default constructor
*/
//! \brief Default constructor
CTransponder() : CAvionicsBase("transponder"), m_transponderCode(0), m_transponderMode(ModeS) {}
/*!
* \brief Copy constructor
* \param other
*/
//! \brief Copy constructor
CTransponder(const CTransponder &other) : CAvionicsBase(other.getName()),
m_transponderCode(other.m_transponderCode), m_transponderMode(other.m_transponderMode) {}
/*!
* \brief Constructor
* \param name
* \param transponderCode
* \param transponderMode
*/
//! \brief Constructor
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
* \param transponderMode
*/
//! \brief Constructor with transponder mode as string
CTransponder(const QString &name, qint32 transponderCode, QString transponderMode) :
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby)
{
@@ -137,12 +85,7 @@ namespace BlackMisc
this->validate(true);
}
/*!
* \brief Constructor
* \param name
* \param transponderCode
* \param transponderMode
*/
//! \brief Constructor, code as string
CTransponder(const QString &name, QString transponderCode, TransponderMode transponderMode) :
CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode)
{
@@ -152,12 +95,7 @@ namespace BlackMisc
this->validate(true);
}
/*!
* \brief Constructor
* \param name
* \param transponderCode
* \param transponderMode
*/
//! \brief Constructor
CTransponder(const QString &name, QString transponderCode, QString transponderMode) :
CAvionicsBase(name), m_transponderCode(0), m_transponderMode(StateStandby)
{
@@ -168,9 +106,27 @@ namespace BlackMisc
this->validate(true);
}
/*!
* \copydoc CValueObject::toQVariant
*/
//! \brief Constructor for validation, used with test cases
CTransponder(bool validate, const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
{
this->validate(validate);
}
//! \brief Constructor for validation, used with test cases
CTransponder(bool validate, 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(validate);
}
//! \copydoc CAvionicsBase::validValues
virtual bool validValues() const override;
//! \copydoc CValueObject::toQVariant
virtual QVariant toQVariant() const override
{
return QVariant::fromValue(*this);
@@ -250,75 +206,12 @@ namespace BlackMisc
return !((*this) == other);
}
/*!
* 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[out] o_transponder
* \param name
* \param transponderCode
* \param mode
* \return
*/
static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, qint32 transponderCode, TransponderMode mode)
{
o_transponder = CTransponder(false, name, transponderCode, mode);
bool s;
if (!(s = o_transponder.validate(false))) o_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[out] o_transponder
* \param name
* \param transponderCode
* \param mode
* \return
*/
static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, const QString &transponderCode, TransponderMode mode)
{
o_transponder = CTransponder(false, name, transponderCode, mode);
bool s;
if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default
return s;
}
/*!
* \brief Transponder unit
* \param transponderCode
* \param mode
* \return
*/
//! \brief Transponder unit
static CTransponder getStandardTransponder(qint32 transponderCode, TransponderMode mode)
{
return CTransponder("Transponder", transponderCode, mode);
}
/*!
* \brief Try to get Transponder unit
* \param[out] o_transponder
* \param transponderCode
* \param mode
* \return
*/
static bool tryGetStandardTransponder(CTransponder &o_transponder, qint32 transponderCode, TransponderMode mode)
{
return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode);
}
/*!
* \brief Try to get Transponder unit
* \param[out] o_transponder
* \param transponderCode
* \param mode
* \return
*/
static bool tryGetStandardTransponder(CTransponder &o_transponder, const QString &transponderCode, TransponderMode mode)
{
return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode);
}
//! \copydoc CValueObject::getValueHash()
virtual uint getValueHash() const override;
@@ -343,7 +236,7 @@ namespace BlackMisc
} // namespace
} // namespace
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTransponder, (o.m_transponderCode))
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTransponder, (o.m_transponderCode, o.m_transponderMode))
Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder)
#endif // guard

View File

@@ -177,7 +177,8 @@ bool BlackMisc::equalQVariants(const QVariant &v1, const QVariant &v2)
const CValueObject *cs2 = CValueObject::fromQVariant(v2);
if (cs1 && cs2)
{
return compare(*cs1, *cs2) == 0;
int c = compare(*cs1, *cs2);
return c == 0;
}
return false;
}