From a2acb032a259314b18029e395185b3c9eeab0700 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 7 Jul 2016 18:04:26 +0300 Subject: [PATCH] Use static assert to check if minimal version is high enough to delete code that needed for backward compatibility. --HG-- branch : develop --- src/app/valentina/xml/vpattern.h | 5 ++++ src/libs/ifc/xml/vabstractconverter.h | 2 ++ src/libs/ifc/xml/vpatternconverter.cpp | 27 ++--------------- src/libs/ifc/xml/vpatternconverter.h | 32 +++++++++++++++++++-- src/libs/ifc/xml/vvitconverter.cpp | 27 ++--------------- src/libs/ifc/xml/vvitconverter.h | 32 +++++++++++++++++++-- src/libs/ifc/xml/vvstconverter.cpp | 27 ++--------------- src/libs/ifc/xml/vvstconverter.h | 32 +++++++++++++++++++-- src/libs/vtools/tools/vtooluniondetails.cpp | 5 ++++ 9 files changed, 108 insertions(+), 81 deletions(-) diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index c23accf08..9ccf41aa6 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -32,6 +32,7 @@ #include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vtoolrecord.h" #include "../vpatterndb/vcontainer.h" +#include "../ifc/xml/vpatternconverter.h" class VDataTool; class VMainGraphicsScene; @@ -171,12 +172,16 @@ private: void ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); // TODO. Delete if minimal supported version is 0.2.7 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 7), + "Time to refactor the code."); void ParseOldToolSpline(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); // TODO. Delete if minimal supported version is 0.2.7 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 2, 7), + "Time to refactor the code."); void ParseOldToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index 6fa3599ee..5a3060664 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -31,6 +31,8 @@ #include "vdomdocument.h" +#define CONVERTER_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) + class VAbstractConverter :public VDomDocument { Q_DECLARE_TR_FUNCTIONS(VAbstractConverter) diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index cb16a65fc..dd72da2b6 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -46,6 +46,9 @@ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.2"); const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.2.xsd"); +constexpr int VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! +constexpr int VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! + //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) :VAbstractConverter(fileName) @@ -57,30 +60,6 @@ VPatternConverter::VPatternConverter(const QString &fileName) VPatternConverter::~VPatternConverter() {} -//--------------------------------------------------------------------------------------------------------------------- -int VPatternConverter::MinVer() const -{ - return GetVersion(PatternMinVerStr); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VPatternConverter::MaxVer() const -{ - return GetVersion(PatternMaxVerStr); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VPatternConverter::MinVerStr() const -{ - return PatternMinVerStr; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VPatternConverter::MaxVerStr() const -{ - return PatternMaxVerStr; -} - //--------------------------------------------------------------------------------------------------------------------- QString VPatternConverter::XSDSchema(int ver) const { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 99f3f5638..cbecfa5f0 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -38,8 +38,10 @@ public: explicit VPatternConverter(const QString &fileName); virtual ~VPatternConverter() Q_DECL_OVERRIDE; - static const QString PatternMaxVerStr; - static const QString CurrentSchema; + static const QString PatternMaxVerStr; + static const QString CurrentSchema; + static constexpr int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); + static constexpr int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 2); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -54,7 +56,7 @@ protected: private: Q_DISABLE_COPY(VPatternConverter) - static const QString PatternMinVerStr; + static const QString PatternMinVerStr; void ToV0_1_1(); void ToV0_1_2(); @@ -105,4 +107,28 @@ private: static QMap OldNamesToNewNames_InV0_2_1(); }; +//--------------------------------------------------------------------------------------------------------------------- +inline int VPatternConverter::MinVer() const +{ + return PatternMinVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int VPatternConverter::MaxVer() const +{ + return PatternMaxVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VPatternConverter::MinVerStr() const +{ + return PatternMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VPatternConverter::MaxVerStr() const +{ + return PatternMaxVerStr; +} + #endif // VPATTERNCONVERTER_H diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp index 0cf65d017..adbc1a058 100644 --- a/src/libs/ifc/xml/vvitconverter.cpp +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -43,6 +43,9 @@ const QString VVITConverter::MeasurementMinVerStr = QStringLiteral("0.2.0"); const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.3.3"); const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.3.3.xsd"); +constexpr int VVITConverter::MeasurementMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! +constexpr int VVITConverter::MeasurementMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! + //--------------------------------------------------------------------------------------------------------------------- VVITConverter::VVITConverter(const QString &fileName) :VAbstractMConverter(fileName) @@ -54,30 +57,6 @@ VVITConverter::VVITConverter(const QString &fileName) VVITConverter::~VVITConverter() {} -//--------------------------------------------------------------------------------------------------------------------- -int VVITConverter::MinVer() const -{ - return GetVersion(MeasurementMinVerStr); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VVITConverter::MaxVer() const -{ - return GetVersion(MeasurementMaxVerStr); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VVITConverter::MinVerStr() const -{ - return MeasurementMinVerStr; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VVITConverter::MaxVerStr() const -{ - return MeasurementMaxVerStr; -} - //--------------------------------------------------------------------------------------------------------------------- QString VVITConverter::XSDSchema(int ver) const { diff --git a/src/libs/ifc/xml/vvitconverter.h b/src/libs/ifc/xml/vvitconverter.h index ac6fa638e..b72d43e5c 100644 --- a/src/libs/ifc/xml/vvitconverter.h +++ b/src/libs/ifc/xml/vvitconverter.h @@ -38,8 +38,10 @@ public: explicit VVITConverter(const QString &fileName); virtual ~VVITConverter() Q_DECL_OVERRIDE; - static const QString MeasurementMaxVerStr; - static const QString CurrentSchema; + static const QString MeasurementMaxVerStr; + static const QString CurrentSchema; + static constexpr int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 2, 0); + static constexpr int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 3, 3); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -54,7 +56,7 @@ protected: private: Q_DISABLE_COPY(VVITConverter) - static const QString MeasurementMinVerStr; + static const QString MeasurementMinVerStr; void AddNewTagsForV0_3_0(); QString MUnitV0_2_0(); @@ -70,4 +72,28 @@ private: void ToV0_3_3(); }; +//--------------------------------------------------------------------------------------------------------------------- +inline int VVITConverter::MinVer() const +{ + return MeasurementMinVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int VVITConverter::MaxVer() const +{ + return MeasurementMaxVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VVITConverter::MinVerStr() const +{ + return MeasurementMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VVITConverter::MaxVerStr() const +{ + return MeasurementMaxVerStr; +} + #endif // VVITCONVERTER_H diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp index e1385205c..56b428588 100644 --- a/src/libs/ifc/xml/vvstconverter.cpp +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -43,6 +43,9 @@ const QString VVSTConverter::MeasurementMinVerStr = QStringLiteral("0.3.0"); const QString VVSTConverter::MeasurementMaxVerStr = QStringLiteral("0.4.2"); const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/standard_measurements/v0.4.2.xsd"); +constexpr int VVSTConverter::MeasurementMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! +constexpr int VVSTConverter::MeasurementMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! + //--------------------------------------------------------------------------------------------------------------------- VVSTConverter::VVSTConverter(const QString &fileName) :VAbstractMConverter(fileName) @@ -54,30 +57,6 @@ VVSTConverter::VVSTConverter(const QString &fileName) VVSTConverter::~VVSTConverter() {} -//--------------------------------------------------------------------------------------------------------------------- -int VVSTConverter::MinVer() const -{ - return GetVersion(MeasurementMinVerStr); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VVSTConverter::MaxVer() const -{ - return GetVersion(MeasurementMaxVerStr); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VVSTConverter::MinVerStr() const -{ - return MeasurementMinVerStr; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VVSTConverter::MaxVerStr() const -{ - return MeasurementMaxVerStr; -} - //--------------------------------------------------------------------------------------------------------------------- QString VVSTConverter::XSDSchema(int ver) const { diff --git a/src/libs/ifc/xml/vvstconverter.h b/src/libs/ifc/xml/vvstconverter.h index 2d1672250..7619f3ebe 100644 --- a/src/libs/ifc/xml/vvstconverter.h +++ b/src/libs/ifc/xml/vvstconverter.h @@ -38,8 +38,10 @@ public: explicit VVSTConverter(const QString &fileName); virtual ~VVSTConverter() Q_DECL_OVERRIDE; - static const QString MeasurementMaxVerStr; - static const QString CurrentSchema; + static const QString MeasurementMaxVerStr; + static const QString CurrentSchema; + static constexpr int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 3, 0); + static constexpr int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 4, 2); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -54,7 +56,7 @@ protected: private: Q_DISABLE_COPY(VVSTConverter) - static const QString MeasurementMinVerStr; + static const QString MeasurementMinVerStr; void AddNewTagsForV0_4_0(); void RemoveTagsForV0_4_0(); @@ -68,4 +70,28 @@ private: void ToV0_4_2(); }; +//--------------------------------------------------------------------------------------------------------------------- +inline int VVSTConverter::MinVer() const +{ + return MeasurementMinVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline int VVSTConverter::MaxVer() const +{ + return MeasurementMaxVer; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VVSTConverter::MinVerStr() const +{ + return MeasurementMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString VVSTConverter::MaxVerStr() const +{ + return MeasurementMaxVerStr; +} + #endif // VMEASUREMENTCONVERTER_H diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 33a07eef4..dffd23f26 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -33,6 +33,7 @@ #include "../../vgeometry/varc.h" #include "../../vgeometry/vsplinepath.h" #include "../dialogs/tools/dialoguniondetails.h" +#include "../ifc/xml/vpatternconverter.h" #include @@ -649,6 +650,8 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d // Remove it if min version is 0.3.2 // Instead: // UpdatePoints(data, d1.RemoveEdge(indexD1), i, children); + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 2), + "Time to refactor the code."); if (children.size() != countNodeD2) { UpdatePoints(data, d1.RemoveEdge(indexD1), i, children); @@ -671,6 +674,8 @@ VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d } while (pointsD2 < countNodeD2-1); // This check need for backward compatibility // Remove it if min version is 0.3.2 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 3, 2), + "Time to refactor the code."); if (children.size() == countNodeD2) { break;