All classes which work with QDataStream must provide a header.
--HG-- branch : develop
This commit is contained in:
parent
c536c40628
commit
03b8758781
|
@ -57,6 +57,7 @@
|
||||||
|
|
||||||
#include "vabstractapplication.h"
|
#include "vabstractapplication.h"
|
||||||
#include "vdatastreamenum.h"
|
#include "vdatastreamenum.h"
|
||||||
|
#include "../ifc/exception/vexception.h"
|
||||||
|
|
||||||
const qreal defCurveApproximationScale = 0.5;
|
const qreal defCurveApproximationScale = 0.5;
|
||||||
const qreal minCurveApproximationScale = 0.2;
|
const qreal minCurveApproximationScale = 0.2;
|
||||||
|
@ -722,26 +723,64 @@ void InitLanguages(QComboBox *combobox)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quint32 CustomSARecord::streamHeader = 0xEBFF7586; // CRC-32Q string "CustomSARecord"
|
||||||
|
const quint16 CustomSARecord::classVersion = 1;
|
||||||
|
|
||||||
// Friend functions
|
// Friend functions
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QDataStream &operator<<(QDataStream &out, const CustomSARecord &record)
|
QDataStream &operator<<(QDataStream &out, const CustomSARecord &record)
|
||||||
{
|
{
|
||||||
|
out << CustomSARecord::streamHeader << CustomSARecord::classVersion;
|
||||||
|
|
||||||
|
// Added in classVersion = 1
|
||||||
out << record.startPoint;
|
out << record.startPoint;
|
||||||
out << record.path;
|
out << record.path;
|
||||||
out << record.endPoint;
|
out << record.endPoint;
|
||||||
out << record.reverse;
|
out << record.reverse;
|
||||||
out << record.includeType;
|
out << record.includeType;
|
||||||
|
|
||||||
|
// Added in classVersion = 2
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QDataStream &operator>>(QDataStream &in, CustomSARecord &record)
|
QDataStream &operator>>(QDataStream &in, CustomSARecord &record)
|
||||||
{
|
{
|
||||||
|
quint32 actualStreamHeader = 0;
|
||||||
|
in >> actualStreamHeader;
|
||||||
|
|
||||||
|
if (actualStreamHeader != CustomSARecord::streamHeader)
|
||||||
|
{
|
||||||
|
QString message = QCoreApplication::tr("CustomSARecord prefix mismatch error: actualStreamHeader = 0x%1 "
|
||||||
|
"and streamHeader = 0x%2")
|
||||||
|
.arg(actualStreamHeader, 8, 0x10, QChar('0'))
|
||||||
|
.arg(CustomSARecord::streamHeader, 8, 0x10, QChar('0'));
|
||||||
|
throw VException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 actualClassVersion = 0;
|
||||||
|
in >> actualClassVersion;
|
||||||
|
|
||||||
|
if (actualClassVersion > CustomSARecord::classVersion)
|
||||||
|
{
|
||||||
|
QString message = QCoreApplication::tr("CustomSARecord compatibility error: actualClassVersion = %1 and "
|
||||||
|
"classVersion = %2")
|
||||||
|
.arg(actualClassVersion).arg(CustomSARecord::classVersion);
|
||||||
|
throw VException(message);
|
||||||
|
}
|
||||||
|
|
||||||
in >> record.startPoint;
|
in >> record.startPoint;
|
||||||
in >> record.path;
|
in >> record.path;
|
||||||
in >> record.endPoint;
|
in >> record.endPoint;
|
||||||
in >> record.reverse;
|
in >> record.reverse;
|
||||||
in >> record.includeType;
|
in >> record.includeType;
|
||||||
|
|
||||||
|
// if (actualClassVersion >= 2)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -666,11 +666,15 @@ struct CustomSARecord
|
||||||
friend QDataStream& operator<<(QDataStream& out, const CustomSARecord& record);
|
friend QDataStream& operator<<(QDataStream& out, const CustomSARecord& record);
|
||||||
friend QDataStream& operator>>(QDataStream& in, CustomSARecord& record);
|
friend QDataStream& operator>>(QDataStream& in, CustomSARecord& record);
|
||||||
|
|
||||||
quint32 startPoint;
|
quint32 startPoint{0};
|
||||||
quint32 path;
|
quint32 path{0};
|
||||||
quint32 endPoint;
|
quint32 endPoint{0};
|
||||||
bool reverse;
|
bool reverse{false};
|
||||||
PiecePathIncludeType includeType;
|
PiecePathIncludeType includeType{PiecePathIncludeType::AsCustomSA};
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const quint32 streamHeader;
|
||||||
|
static const quint16 classVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(CustomSARecord)
|
Q_DECLARE_METATYPE(CustomSARecord)
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QtNumeric>
|
#include <QtNumeric>
|
||||||
|
|
||||||
|
const quint32 VPieceNodeData::streamHeader = 0x2198CBC8; // CRC-32Q string "VPieceNodeData"
|
||||||
|
const quint16 VPieceNodeData::classVersion = 1;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPieceNode::VPieceNode()
|
VPieceNode::VPieceNode()
|
||||||
: d(new VPieceNodeData)
|
: d(new VPieceNodeData)
|
||||||
|
|
|
@ -31,7 +31,10 @@
|
||||||
|
|
||||||
#include <QSharedData>
|
#include <QSharedData>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
#include "../ifc/ifcdef.h"
|
#include "../ifc/ifcdef.h"
|
||||||
|
#include "../ifc/exception/vexception.h"
|
||||||
#include "../vmisc/diagnostic.h"
|
#include "../vmisc/diagnostic.h"
|
||||||
#include "../vmisc/vdatastreamenum.h"
|
#include "../vmisc/vdatastreamenum.h"
|
||||||
|
|
||||||
|
@ -119,12 +122,18 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_ASSIGN(VPieceNodeData)
|
Q_DISABLE_ASSIGN(VPieceNodeData)
|
||||||
|
|
||||||
|
static const quint32 streamHeader;
|
||||||
|
static const quint16 classVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Friend functions
|
// Friend functions
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p)
|
QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p)
|
||||||
{
|
{
|
||||||
|
out << VPieceNodeData::streamHeader << VPieceNodeData::classVersion;
|
||||||
|
|
||||||
|
// Added in classVersion = 1
|
||||||
out << p.m_id
|
out << p.m_id
|
||||||
<< p.m_typeTool
|
<< p.m_typeTool
|
||||||
<< p.m_reverse
|
<< p.m_reverse
|
||||||
|
@ -139,12 +148,38 @@ QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p)
|
||||||
<< p.m_isShowSecondPassmark
|
<< p.m_isShowSecondPassmark
|
||||||
<< p.m_checkUniqueness
|
<< p.m_checkUniqueness
|
||||||
<< p.m_manualPassmarkLength;
|
<< p.m_manualPassmarkLength;
|
||||||
|
|
||||||
|
// Added in classVersion = 2
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QDataStream &operator>>(QDataStream &in, VPieceNodeData &p)
|
QDataStream &operator>>(QDataStream &in, VPieceNodeData &p)
|
||||||
{
|
{
|
||||||
|
quint32 actualStreamHeader = 0;
|
||||||
|
in >> actualStreamHeader;
|
||||||
|
|
||||||
|
if (actualStreamHeader != VPieceNodeData::streamHeader)
|
||||||
|
{
|
||||||
|
QString message = QCoreApplication::tr("VPieceNodeData prefix mismatch error: actualStreamHeader = 0x%1 "
|
||||||
|
"and streamHeader = 0x%2")
|
||||||
|
.arg(actualStreamHeader, 8, 0x10, QChar('0'))
|
||||||
|
.arg(VPieceNodeData::streamHeader, 8, 0x10, QChar('0'));
|
||||||
|
throw VException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 actualClassVersion = 0;
|
||||||
|
in >> actualClassVersion;
|
||||||
|
|
||||||
|
if (actualClassVersion > VPieceNodeData::classVersion)
|
||||||
|
{
|
||||||
|
QString message = QCoreApplication::tr("VPieceNodeData compatibility error: actualClassVersion = %1 and "
|
||||||
|
"classVersion = %2")
|
||||||
|
.arg(actualClassVersion).arg(VPieceNodeData::classVersion);
|
||||||
|
throw VException(message);
|
||||||
|
}
|
||||||
|
|
||||||
in >> p.m_id
|
in >> p.m_id
|
||||||
>> p.m_typeTool
|
>> p.m_typeTool
|
||||||
>> p.m_reverse
|
>> p.m_reverse
|
||||||
|
@ -159,6 +194,12 @@ QDataStream &operator>>(QDataStream &in, VPieceNodeData &p)
|
||||||
>> p.m_isShowSecondPassmark
|
>> p.m_isShowSecondPassmark
|
||||||
>> p.m_checkUniqueness
|
>> p.m_checkUniqueness
|
||||||
>> p.m_manualPassmarkLength;
|
>> p.m_manualPassmarkLength;
|
||||||
|
|
||||||
|
// if (actualClassVersion >= 2)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user