Refactoring. Use macros FORMAT_VERSION to avoid human mistakes.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-07-30 16:32:45 +03:00
parent 0d9f7fd194
commit ca90ceaada

View File

@ -81,25 +81,24 @@ VVITConverter::VVITConverter(const QString &fileName)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VVITConverter::XSDSchema(int ver) const QString VVITConverter::XSDSchema(int ver) const
{ {
switch (ver) QHash <int, QString> schemas =
{ {
case (0x000200): std::make_pair(FORMAT_VERSION(0, 2, 0), QStringLiteral("://schema/individual_measurements/v0.2.0.xsd")),
return QStringLiteral("://schema/individual_measurements/v0.2.0.xsd"); std::make_pair(FORMAT_VERSION(0, 3, 0), QStringLiteral("://schema/individual_measurements/v0.3.0.xsd")),
case (0x000300): std::make_pair(FORMAT_VERSION(0, 3, 1), QStringLiteral("://schema/individual_measurements/v0.3.1.xsd")),
return QStringLiteral("://schema/individual_measurements/v0.3.0.xsd"); std::make_pair(FORMAT_VERSION(0, 3, 2), QStringLiteral("://schema/individual_measurements/v0.3.2.xsd")),
case (0x000301): std::make_pair(FORMAT_VERSION(0, 3, 3), QStringLiteral("://schema/individual_measurements/v0.3.3.xsd")),
return QStringLiteral("://schema/individual_measurements/v0.3.1.xsd"); std::make_pair(FORMAT_VERSION(0, 4, 0), CurrentSchema),
case (0x000302): };
return QStringLiteral("://schema/individual_measurements/v0.3.2.xsd");
case (0x000303): if (schemas.contains(ver))
return QStringLiteral("://schema/individual_measurements/v0.3.3.xsd"); {
case (0x000400): return schemas.value(ver);
return CurrentSchema; }
default: else
InvalidVersion(ver); {
break; InvalidVersion(ver);
} }
return QString();//unreachable code
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -107,27 +106,27 @@ void VVITConverter::ApplyPatches()
{ {
switch (m_ver) switch (m_ver)
{ {
case (0x000200): case (FORMAT_VERSION(0, 2, 0)):
ToV0_3_0(); ToV0_3_0();
ValidateXML(XSDSchema(0x000300), m_convertedFileName); ValidateXML(XSDSchema(FORMAT_VERSION(0, 3, 0)), m_convertedFileName);
V_FALLTHROUGH V_FALLTHROUGH
case (0x000300): case (FORMAT_VERSION(0, 3, 0)):
ToV0_3_1(); ToV0_3_1();
ValidateXML(XSDSchema(0x000301), m_convertedFileName); ValidateXML(XSDSchema(FORMAT_VERSION(0, 3, 1)), m_convertedFileName);
V_FALLTHROUGH V_FALLTHROUGH
case (0x000301): case (FORMAT_VERSION(0, 3, 1)):
ToV0_3_2(); ToV0_3_2();
ValidateXML(XSDSchema(0x000302), m_convertedFileName); ValidateXML(XSDSchema(FORMAT_VERSION(0, 3, 2)), m_convertedFileName);
V_FALLTHROUGH V_FALLTHROUGH
case (0x000302): case (FORMAT_VERSION(0, 3, 2)):
ToV0_3_3(); ToV0_3_3();
ValidateXML(XSDSchema(0x000303), m_convertedFileName); ValidateXML(XSDSchema(FORMAT_VERSION(0, 3, 3)), m_convertedFileName);
V_FALLTHROUGH V_FALLTHROUGH
case (0x000303): case (FORMAT_VERSION(0, 3, 3)):
ToV0_4_0(); ToV0_4_0();
ValidateXML(XSDSchema(0x000400), m_convertedFileName); ValidateXML(XSDSchema(FORMAT_VERSION(0, 4, 0)), m_convertedFileName);
V_FALLTHROUGH V_FALLTHROUGH
case (0x000400): case (FORMAT_VERSION(0, 4, 0)):
break; break;
default: default:
InvalidVersion(m_ver); InvalidVersion(m_ver);