From 0d9daf8b4fa4d6829afd307af4cf1a1165b67eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 1 May 2025 08:36:55 +0200 Subject: [PATCH] Code cleanup --- src/map/ENC/iso8211.cpp | 27 +++++++++++++++------------ src/map/ENC/iso8211.h | 11 ++++++----- src/map/ENC/mapdata.cpp | 16 ++++++++-------- src/map/encatlas.cpp | 2 +- src/map/encmap.cpp | 10 +++++----- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/map/ENC/iso8211.cpp b/src/map/ENC/iso8211.cpp index bdd198c6..267a2a62 100644 --- a/src/map/ENC/iso8211.cpp +++ b/src/map/ENC/iso8211.cpp @@ -44,6 +44,15 @@ ISO8211::SubFieldDefinition ISO8211::fieldType(const QString &str, int cnt) return SubFieldDefinition(); } +const ISO8211::Field *ISO8211::Record::field(quint32 name) const +{ + for (int i = 0; i < size(); i++) + if (at(i).tag() == name) + return &at(i); + + return 0; +} + int ISO8211::readDR(QVector &fields) { DR ddr; @@ -275,16 +284,12 @@ bool ISO8211::readRecord(Record &record) FieldsMap::const_iterator it(_map.find(def.tag)); if (it == _map.constEnd()) { - QByteArray tag(sizeof(quint32), Qt::Initialization::Uninitialized); - qToLittleEndian(def.tag, tag.data()); - _errorString = QString("%1: unknown record").arg(QString(tag)); + _errorString = QString("%1: unknown record").arg(NAME(def.tag)); return false; } if (!readUDA(pos, def, it->defs(), it->repeat(), data)) { - QByteArray tag(sizeof(quint32), Qt::Initialization::Uninitialized); - qToLittleEndian(def.tag, tag.data()); - _errorString = QString("Error reading %1 record").arg(QString(tag)); + _errorString = QString("Error reading %1 record").arg(NAME(def.tag)); return false; } @@ -294,11 +299,9 @@ bool ISO8211::readRecord(Record &record) return true; } -const ISO8211::Field *ISO8211::Record::field(quint32 name) const +QString ISO8211::NAME(quint32 tag) { - for (int i = 0; i < size(); i++) - if (at(i).tag() == name) - return &at(i); - - return 0; + QByteArray ba(sizeof(quint32), Qt::Initialization::Uninitialized); + qToLittleEndian(tag, ba.data()); + return QString::fromLatin1(ba); } diff --git a/src/map/ENC/iso8211.h b/src/map/ENC/iso8211.h index ab2cb450..6418387d 100644 --- a/src/map/ENC/iso8211.h +++ b/src/map/ENC/iso8211.h @@ -38,13 +38,14 @@ public: bool atEnd() const {return _file.atEnd();} const QString &errorString() const {return _errorString;} - static constexpr quint32 NAME(const char str[4]) + static constexpr quint32 TAG(const char name[4]) { - return static_cast(str[0]) - + (static_cast(str[1]) << 8) - + (static_cast(str[2]) << 16) - + (static_cast(str[3]) << 24); + return static_cast(name[0]) + + (static_cast(name[1]) << 8) + + (static_cast(name[2]) << 16) + + (static_cast(name[3]) << 24); } + static QString NAME(quint32 tag); private: enum FieldType {Unknown, String, Array, S8, S16, S32, U8, U16, U32}; diff --git a/src/map/ENC/mapdata.cpp b/src/map/ENC/mapdata.cpp index 51b5cdcd..e041e929 100644 --- a/src/map/ENC/mapdata.cpp +++ b/src/map/ENC/mapdata.cpp @@ -15,14 +15,14 @@ using namespace ENC; #define PRIM_L 2 #define PRIM_A 3 -constexpr quint32 SG2D = ISO8211::NAME("SG2D"); -constexpr quint32 SG3D = ISO8211::NAME("SG3D"); -constexpr quint32 FSPT = ISO8211::NAME("FSPT"); -constexpr quint32 VRPT = ISO8211::NAME("VRPT"); -constexpr quint32 ATTF = ISO8211::NAME("ATTF"); -constexpr quint32 VRID = ISO8211::NAME("VRID"); -constexpr quint32 FRID = ISO8211::NAME("FRID"); -constexpr quint32 DSPM = ISO8211::NAME("DSPM"); +constexpr quint32 SG2D = ISO8211::TAG("SG2D"); +constexpr quint32 SG3D = ISO8211::TAG("SG3D"); +constexpr quint32 FSPT = ISO8211::TAG("FSPT"); +constexpr quint32 VRPT = ISO8211::TAG("VRPT"); +constexpr quint32 ATTF = ISO8211::TAG("ATTF"); +constexpr quint32 VRID = ISO8211::TAG("VRID"); +constexpr quint32 FRID = ISO8211::TAG("FRID"); +constexpr quint32 DSPM = ISO8211::TAG("DSPM"); static QMap orderMapInit() { diff --git a/src/map/encatlas.cpp b/src/map/encatlas.cpp index 23fb9b14..4cd8585f 100644 --- a/src/map/encatlas.cpp +++ b/src/map/encatlas.cpp @@ -12,7 +12,7 @@ using namespace ENC; #define EPSILON 1e-6 #define TILE_SIZE 512 -constexpr quint32 CATD = ISO8211::NAME("CATD"); +constexpr quint32 CATD = ISO8211::TAG("CATD"); Range ENCAtlas::zooms(IntendedUsage usage) { diff --git a/src/map/encmap.cpp b/src/map/encmap.cpp index 38ff9714..afe1c061 100644 --- a/src/map/encmap.cpp +++ b/src/map/encmap.cpp @@ -15,11 +15,11 @@ using namespace ENC; #define EPSILON 1e-6 #define TILE_SIZE 512 -constexpr quint32 SG2D = ISO8211::NAME("SG2D"); -constexpr quint32 SG3D = ISO8211::NAME("SG3D"); -constexpr quint32 VRID = ISO8211::NAME("VRID"); -constexpr quint32 DSID = ISO8211::NAME("DSID"); -constexpr quint32 DSPM = ISO8211::NAME("DSPM"); +constexpr quint32 SG2D = ISO8211::TAG("SG2D"); +constexpr quint32 SG3D = ISO8211::TAG("SG3D"); +constexpr quint32 VRID = ISO8211::TAG("VRID"); +constexpr quint32 DSID = ISO8211::TAG("DSID"); +constexpr quint32 DSPM = ISO8211::TAG("DSPM"); static Range zooms(const RectC &bounds) {