Removed validation by exception (no longer what we use) from com/xpdr

This commit is contained in:
Klaus Basan
2014-06-30 23:54:27 +02:00
parent ef93477a82
commit f989acb42e
5 changed files with 9 additions and 103 deletions

View File

@@ -25,26 +25,12 @@ namespace BlackMisc
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)
{
CFrequency f(frequencyMHz, CFrequencyUnit::MHz());
if (f == this->getFrequencyActive()) return; // save all the comparisons / rounding
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
this->CModulator::setFrequencyActive(f);
this->validate(true);
}
void CComSystem::setFrequencyStandbyMHz(double frequencyMHz)
@@ -53,7 +39,6 @@ namespace BlackMisc
if (f == this->getFrequencyStandby()) return; // save all the comparisons / rounding
CComSystem::roundToChannelSpacing(f, this->m_channelSpacing);
CModulator::setFrequencyStandby(f);
this->validate(true);
}
/*

View File

@@ -32,21 +32,6 @@ namespace BlackMisc
BLACK_ENABLE_TUPLE_CONVERSION(CComSystem)
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
* \remarks Just a helper method, that is why no CFrequency is returned
@@ -57,15 +42,6 @@ namespace BlackMisc
//! \copydoc CAvionicsBase::validValues
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()
virtual void marshallToDbus(QDBusArgument &argument) const override;
@@ -82,15 +58,10 @@ namespace BlackMisc
//! \brief Constructor
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)
{
this->validate(true);
}
{ }
//! \copydoc CValueObject::toQVariant
virtual QVariant toQVariant() const override
{
return QVariant::fromValue(*this);
}
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
//! \brief Set active frequency
//! \remarks will be rounded to channel spacing

View File

@@ -20,20 +20,6 @@ namespace BlackMisc
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
*/

View File

@@ -36,19 +36,7 @@ namespace BlackMisc
protected:
//! \brief Default value?
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 virtual since already used in constructor
* \return
*/
bool validate(bool strict = true) const;
virtual bool isDefaultValue() const { return this->m_transponderCode == 0; }
//! \copydoc CValueObject::convertToQString
virtual QString convertToQString(bool i18n = false) const override;
@@ -73,16 +61,13 @@ namespace BlackMisc
//! \brief Constructor
CTransponder(const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
{
this->validate(true);
}
{ }
//! \brief Constructor with transponder mode as string
CTransponder(const QString &name, qint32 transponderCode, QString transponderMode) :
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby)
{
this->setModeAsString(transponderMode);
this->validate(true);
}
//! \brief Constructor, code as string
@@ -92,7 +77,6 @@ namespace BlackMisc
bool ok = false;
this->m_transponderCode = transponderCode.toUInt(&ok);
if (!ok) this->m_transponderCode = -1; // will cause assert / exception
this->validate(true);
}
//! \brief Constructor
@@ -103,24 +87,6 @@ namespace BlackMisc
this->m_transponderCode = transponderCode.toUInt(&ok);
if (!ok) this->m_transponderCode = -1; // will cause assert / exception
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
@@ -169,7 +135,6 @@ namespace BlackMisc
void setTransponderCode(qint32 transponderCode)
{
this->m_transponderCode = transponderCode;
this->validate(true);
}
//! \brief Set transponder code
@@ -182,7 +147,6 @@ namespace BlackMisc
void setTransponderMode(TransponderMode mode)
{
this->m_transponderMode = mode ;
this->validate(true);
}
//! \brief Set emergency