Use static assert to check if minimal version is high enough to delete code that

needed for backward compatibility.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-07-07 18:04:26 +03:00
parent a78a516ce9
commit a2acb032a2
9 changed files with 108 additions and 81 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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
{

View File

@ -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<QString, QString> 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

View File

@ -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
{

View File

@ -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

View File

@ -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
{

View File

@ -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

View File

@ -33,6 +33,7 @@
#include "../../vgeometry/varc.h"
#include "../../vgeometry/vsplinepath.h"
#include "../dialogs/tools/dialoguniondetails.h"
#include "../ifc/xml/vpatternconverter.h"
#include <QUndoStack>
@ -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;