mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
Removed validation by exception (no longer what we use) from com/xpdr
This commit is contained in:
@@ -25,26 +25,12 @@ namespace BlackMisc
|
|||||||
CComSystem::isValidMilitaryFrequency(this->getFrequencyStandby()));
|
CComSystem::isValidMilitaryFrequency(this->getFrequencyStandby()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Validate
|
|
||||||
*/
|
|
||||||
bool CComSystem::validate(bool strict) 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CComSystem::setFrequencyActiveMHz(double frequencyMHz)
|
void CComSystem::setFrequencyActiveMHz(double frequencyMHz)
|
||||||
{
|
{
|
||||||
CFrequency f(frequencyMHz, CFrequencyUnit::MHz());
|
CFrequency f(frequencyMHz, CFrequencyUnit::MHz());
|
||||||
if (f == this->getFrequencyActive()) return; // save all the comparisons / rounding
|
if (f == this->getFrequencyActive()) return; // save all the comparisons / rounding
|
||||||
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
|
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
|
||||||
this->CModulator::setFrequencyActive(f);
|
this->CModulator::setFrequencyActive(f);
|
||||||
this->validate(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CComSystem::setFrequencyStandbyMHz(double frequencyMHz)
|
void CComSystem::setFrequencyStandbyMHz(double frequencyMHz)
|
||||||
@@ -53,7 +39,6 @@ namespace BlackMisc
|
|||||||
if (f == this->getFrequencyStandby()) return; // save all the comparisons / rounding
|
if (f == this->getFrequencyStandby()) return; // save all the comparisons / rounding
|
||||||
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
|
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
|
||||||
CModulator::setFrequencyStandby(f);
|
CModulator::setFrequencyStandby(f);
|
||||||
this->validate(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -32,21 +32,6 @@ namespace BlackMisc
|
|||||||
BLACK_ENABLE_TUPLE_CONVERSION(CComSystem)
|
BLACK_ENABLE_TUPLE_CONVERSION(CComSystem)
|
||||||
ChannelSpacing m_channelSpacing;
|
ChannelSpacing m_channelSpacing;
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Constructor
|
|
||||||
* \param validate
|
|
||||||
* \param name
|
|
||||||
* \param activeFrequency
|
|
||||||
* \param standbyFrequency
|
|
||||||
* \param digits
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
CComSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3):
|
|
||||||
CModulator(name, activeFrequency, standbyFrequency, digits), m_channelSpacing(ChannelSpacing25KHz)
|
|
||||||
{
|
|
||||||
this->validate(validate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Give me channel spacing in KHz
|
* \brief Give me channel spacing in KHz
|
||||||
* \remarks Just a helper method, that is why no CFrequency is returned
|
* \remarks Just a helper method, that is why no CFrequency is returned
|
||||||
@@ -57,15 +42,6 @@ namespace BlackMisc
|
|||||||
//! \copydoc CAvionicsBase::validValues
|
//! \copydoc CAvionicsBase::validValues
|
||||||
virtual bool validValues() const override;
|
virtual bool validValues() const override;
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Validate values by assert and exception
|
|
||||||
* \param strict
|
|
||||||
* \throws std::range_error
|
|
||||||
* \remarks Cannot be virtual because used in constructor
|
|
||||||
* \return
|
|
||||||
*/
|
|
||||||
bool validate(bool strict = true) const;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::marshallFromDbus()
|
//! \copydoc CValueObject::marshallFromDbus()
|
||||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||||
|
|
||||||
@@ -82,15 +58,10 @@ namespace BlackMisc
|
|||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3):
|
CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3):
|
||||||
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits), m_channelSpacing(ChannelSpacing25KHz)
|
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits), m_channelSpacing(ChannelSpacing25KHz)
|
||||||
{
|
{ }
|
||||||
this->validate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant
|
//! \copydoc CValueObject::toQVariant
|
||||||
virtual QVariant toQVariant() const override
|
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||||
{
|
|
||||||
return QVariant::fromValue(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Set active frequency
|
//! \brief Set active frequency
|
||||||
//! \remarks will be rounded to channel spacing
|
//! \remarks will be rounded to channel spacing
|
||||||
|
|||||||
@@ -20,20 +20,6 @@ namespace BlackMisc
|
|||||||
return CTransponder::isValidTransponderCode(this->m_transponderCode);
|
return CTransponder::isValidTransponderCode(this->m_transponderCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
* String representation
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -36,19 +36,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \brief Default value?
|
//! \brief Default value?
|
||||||
virtual bool isDefaultValue() const
|
virtual bool isDefaultValue() const { return this->m_transponderCode == 0; }
|
||||||
{
|
|
||||||
return this->m_transponderCode == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Validate values by assert and exception
|
|
||||||
* \param strict
|
|
||||||
* \throws std::range_error
|
|
||||||
* \remarks Cannot be virtual since already used in constructor
|
|
||||||
* \return
|
|
||||||
*/
|
|
||||||
bool validate(bool strict = true) const;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertToQString
|
//! \copydoc CValueObject::convertToQString
|
||||||
virtual QString convertToQString(bool i18n = false) const override;
|
virtual QString convertToQString(bool i18n = false) const override;
|
||||||
@@ -73,16 +61,13 @@ namespace BlackMisc
|
|||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
CTransponder(const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
|
CTransponder(const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
|
||||||
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
|
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
|
||||||
{
|
{ }
|
||||||
this->validate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Constructor with transponder mode as string
|
//! \brief Constructor with transponder mode as string
|
||||||
CTransponder(const QString &name, qint32 transponderCode, QString transponderMode) :
|
CTransponder(const QString &name, qint32 transponderCode, QString transponderMode) :
|
||||||
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby)
|
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby)
|
||||||
{
|
{
|
||||||
this->setModeAsString(transponderMode);
|
this->setModeAsString(transponderMode);
|
||||||
this->validate(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Constructor, code as string
|
//! \brief Constructor, code as string
|
||||||
@@ -92,7 +77,6 @@ namespace BlackMisc
|
|||||||
bool ok = false;
|
bool ok = false;
|
||||||
this->m_transponderCode = transponderCode.toUInt(&ok);
|
this->m_transponderCode = transponderCode.toUInt(&ok);
|
||||||
if (!ok) this->m_transponderCode = -1; // will cause assert / exception
|
if (!ok) this->m_transponderCode = -1; // will cause assert / exception
|
||||||
this->validate(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
@@ -103,24 +87,6 @@ namespace BlackMisc
|
|||||||
this->m_transponderCode = transponderCode.toUInt(&ok);
|
this->m_transponderCode = transponderCode.toUInt(&ok);
|
||||||
if (!ok) this->m_transponderCode = -1; // will cause assert / exception
|
if (!ok) this->m_transponderCode = -1; // will cause assert / exception
|
||||||
this->setModeAsString(transponderMode);
|
this->setModeAsString(transponderMode);
|
||||||
this->validate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \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
|
//! \copydoc CAvionicsBase::validValues
|
||||||
@@ -169,7 +135,6 @@ namespace BlackMisc
|
|||||||
void setTransponderCode(qint32 transponderCode)
|
void setTransponderCode(qint32 transponderCode)
|
||||||
{
|
{
|
||||||
this->m_transponderCode = transponderCode;
|
this->m_transponderCode = transponderCode;
|
||||||
this->validate(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Set transponder code
|
//! \brief Set transponder code
|
||||||
@@ -182,7 +147,6 @@ namespace BlackMisc
|
|||||||
void setTransponderMode(TransponderMode mode)
|
void setTransponderMode(TransponderMode mode)
|
||||||
{
|
{
|
||||||
this->m_transponderMode = mode ;
|
this->m_transponderMode = mode ;
|
||||||
this->validate(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Set emergency
|
//! \brief Set emergency
|
||||||
|
|||||||
@@ -84,15 +84,15 @@ namespace BlackMiscTest
|
|||||||
QVERIFY2(t1 == t2, "Transponders shall be equal");
|
QVERIFY2(t1 == t2, "Transponders shall be equal");
|
||||||
t2.setTransponderMode(CTransponder::ModeC);
|
t2.setTransponderMode(CTransponder::ModeC);
|
||||||
QVERIFY2(t1 != t2, "Transponders shall not be equal");
|
QVERIFY2(t1 != t2, "Transponders shall not be equal");
|
||||||
CTransponder tv = CTransponder(false, "transponder", 8888, CTransponder::StateStandby);
|
CTransponder tv = CTransponder("transponder", 8888, CTransponder::StateStandby);
|
||||||
QVERIFY2(!tv.validValues(), "No valid transponder");
|
QVERIFY2(!tv.validValues(), "No valid transponder");
|
||||||
tv = CTransponder(false, "transponder", 781, CTransponder::StateStandby);
|
tv = CTransponder("transponder", 781, CTransponder::StateStandby);
|
||||||
QVERIFY2(!tv.validValues(), "No valid transponder");
|
QVERIFY2(!tv.validValues(), "No valid transponder");
|
||||||
tv = CTransponder(false, "transponder", "0781", CTransponder::StateStandby);
|
tv = CTransponder("transponder", "0781", CTransponder::StateStandby);
|
||||||
QVERIFY2(!tv.validValues(), "No valid transponder");
|
QVERIFY2(!tv.validValues(), "No valid transponder");
|
||||||
tv = CTransponder(false, "transponder", "7211", CTransponder::StateStandby);
|
tv = CTransponder("transponder", "7211", CTransponder::StateStandby);
|
||||||
QVERIFY2(tv.validValues(), "No valid transponder");
|
QVERIFY2(tv.validValues(), "No valid transponder");
|
||||||
tv = CTransponder(false, "transponder", "schnitzel", CTransponder::StateStandby);
|
tv = CTransponder("transponder", "schnitzel", CTransponder::StateStandby);
|
||||||
QVERIFY2(!tv.validValues(), "No valid transponder");
|
QVERIFY2(!tv.validValues(), "No valid transponder");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user