From 0b5d01a1f66879353d15e2e150c053bffa10f64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 26 Aug 2020 17:58:21 +0200 Subject: [PATCH] A little bit more sane subfile interface --- src/map/IMG/bitstream.cpp | 10 +++++----- src/map/IMG/bitstream.h | 2 +- src/map/IMG/huffmantable.cpp | 2 +- src/map/IMG/rgnfile.cpp | 24 ++++++++++++------------ src/map/IMG/style.cpp | 2 +- src/map/IMG/subfile.h | 3 +-- src/map/IMG/trefile.cpp | 2 +- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/map/IMG/bitstream.cpp b/src/map/IMG/bitstream.cpp index 57302d18..f652f13d 100644 --- a/src/map/IMG/bitstream.cpp +++ b/src/map/IMG/bitstream.cpp @@ -32,7 +32,7 @@ bool BitStream1::read(int bits, quint32 &val) bool BitStream1::flush() { - if (_length && !_file.seek(_hdl, _hdl.pos() + _length)) + if (_length && !_file.seek(_hdl, _file.pos(_hdl) + _length)) return false; _length = 0; @@ -43,7 +43,7 @@ bool BitStream1::flush() bool BitStream4::flush() { - if (_length && !_file.seek(_hdl, _hdl.pos() + _length)) + if (_length && !_file.seek(_hdl, _file.pos(_hdl) + _length)) return false; _length = 0; @@ -82,7 +82,7 @@ bool BitStream4F::read(int bits, quint32 &val) BitStream4R::BitStream4R(const SubFile &file, SubFile::Handle &hdl, quint32 length) : BitStream4(file, hdl, length) { - _file.seek(_hdl, _hdl.pos() - 4); + _file.seek(_hdl, _file.pos(_hdl) - 4); } bool BitStream4R::readBytes(int bytes, quint32 &val) @@ -169,14 +169,14 @@ bool BitStream4R::skip(quint32 bytes) else { quint32 seek = ((bytes - ab)/4)*4; quint32 read = (bytes - ab)%4; - if (seek && !_file.seek(_hdl, _hdl.pos() - seek)) + if (seek && !_file.seek(_hdl, _file.pos(_hdl) - seek)) return false; _length -= seek; if (read) { quint32 rb = qMin(_length, 4U); if (!_file.readUInt32(_hdl, _data)) return false; - if (!_file.seek(_hdl, _hdl.pos() - 8)) + if (!_file.seek(_hdl, _file.pos(_hdl) - 8)) return false; _length -= rb; _unused = (4 - rb) * 8; diff --git a/src/map/IMG/bitstream.h b/src/map/IMG/bitstream.h index 0e159222..353c4742 100644 --- a/src/map/IMG/bitstream.h +++ b/src/map/IMG/bitstream.h @@ -73,7 +73,7 @@ bool BitStream4R::read(int bits, T &val) if (!_file.readUInt32(_hdl, _data)) return false; - if (!_file.seek(_hdl, _hdl.pos() - 8)) + if (!_file.seek(_hdl, _file.pos(_hdl) - 8)) return false; _length -= bytes; diff --git a/src/map/IMG/huffmantable.cpp b/src/map/IMG/huffmantable.cpp index ad35f116..f3120617 100644 --- a/src/map/IMG/huffmantable.cpp +++ b/src/map/IMG/huffmantable.cpp @@ -57,7 +57,7 @@ bool HuffmanTable::getBuffer(const SubFile &file, SubFile::Handle &hdl, return false; if (!file.readVUInt32(hdl, recordSize)) return false; - recordOffset = hdl.pos() + recordSize; + recordOffset = file.pos(hdl) + recordSize; if (recordOffset > offset + size) return false; }; diff --git a/src/map/IMG/rgnfile.cpp b/src/map/IMG/rgnfile.cpp index 03d12988..dfb84899 100644 --- a/src/map/IMG/rgnfile.cpp +++ b/src/map/IMG/rgnfile.cpp @@ -51,7 +51,7 @@ bool RGNFile::skipClassFields(Handle &hdl) const break; } - return seek(hdl, hdl.pos() + rs); + return seek(hdl, pos(hdl) + rs); } bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const @@ -73,7 +73,7 @@ bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const return false; } else skip = m + 1; - if (!seek(hdl, hdl.pos() + skip)) + if (!seek(hdl, pos(hdl) + skip)) return false; } bitfield >>= 1; @@ -93,7 +93,7 @@ bool RGNFile::skipGblFields(Handle &hdl, quint32 flags) const flags = flags >> 2; } while (flags != 0); - return seek(hdl, hdl.pos() + cnt); + return seek(hdl, pos(hdl) + cnt); } bool RGNFile::init(Handle &hdl) @@ -158,7 +158,7 @@ bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv, qint16 lon, lat; quint16 len; - while (hdl.pos() < (int)segment.end()) { + while (pos(hdl) < segment.end()) { IMG::Poly poly; if (!(readUInt8(hdl, type) && readUInt24(hdl, labelPtr) @@ -233,7 +233,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift, if (!seek(hdl, segment.offset())) return false; - while (hdl.pos() < (int)segment.end()) { + while (pos(hdl) < segment.end()) { IMG::Poly poly; QPoint pos; @@ -241,7 +241,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift, && readInt16(hdl, lon) && readInt16(hdl, lat) && readVUInt32(hdl, len))) return false; - Q_ASSERT(hdl.pos() + len <= segment.end()); + Q_ASSERT(SubFile::pos(hdl) + len <= segment.end()); poly.type = 0x10000 | (quint16(type)<<8) | (subtype & 0x1F); labelPtr = 0; @@ -341,7 +341,7 @@ bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv, if (!seek(hdl, segment.offset())) return false; - while (hdl.pos() < (int)segment.end()) { + while (pos(hdl) < segment.end()) { IMG::Point point; quint8 type, subtype; qint16 lon, lat; @@ -384,7 +384,7 @@ bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv, LBLFile *lbl, if (!seek(hdl, segment.offset())) return false; - while (hdl.pos() < (int)segment.end()) { + while (pos(hdl) < segment.end()) { IMG::Point point; qint16 lon, lat; quint8 type, subtype; @@ -441,11 +441,11 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, NETFile *net, if (!(blockIndexIdSize = nod->indexIdSize(nodHdl))) return false; - while (hdl.pos() < (int)segment.end()) { + while (pos(hdl) < segment.end()) { if (!readVUInt32(hdl, size)) return false; - int pos = hdl.pos(); + quint32 pos = SubFile::pos(hdl); if (!(readUInt8(hdl, flags) && readVUInt32(hdl, blockIndexIdSize, blockIndexId))) @@ -482,7 +482,7 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, NETFile *net, lineId = (((v16 >> shift) >> 8) & 3) + 1; if (shift < 6 && i < b8 + b10 + b16 - 1) - seek(hdl, hdl.pos() - 1); + seek(hdl, SubFile::pos(hdl) - 1); } else { linkId = (quint8)v16; lineId = v16 >> 8; @@ -498,7 +498,7 @@ bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, NETFile *net, _huffmanTable, lines); } - Q_ASSERT(pos + (int)size == hdl.pos()); + Q_ASSERT(pos + size == SubFile::pos(hdl)); } return true; diff --git a/src/map/IMG/style.cpp b/src/map/IMG/style.cpp index d3a24468..32fe2d86 100644 --- a/src/map/IMG/style.cpp +++ b/src/map/IMG/style.cpp @@ -359,7 +359,7 @@ static bool skipLocalization(SubFile *file, SubFile::Handle &hdl) len = len >> 2; } - if (!file->seek(hdl, hdl.pos() + len)) + if (!file->seek(hdl, file->pos(hdl) + len)) return false; return true; diff --git a/src/map/IMG/subfile.h b/src/map/IMG/subfile.h index 6c870010..74129c65 100644 --- a/src/map/IMG/subfile.h +++ b/src/map/IMG/subfile.h @@ -28,8 +28,6 @@ public: } ~Handle() {delete _file;} - int pos() const {return _pos;} - private: friend class SubFile; @@ -57,6 +55,7 @@ public: void addBlock(quint16 block) {_blocks->append(block);} bool seek(Handle &handle, quint32 pos) const; + quint32 pos(Handle &handle) const {return handle._pos;} template bool readUInt8(Handle &handle, T &val) const diff --git a/src/map/IMG/trefile.cpp b/src/map/IMG/trefile.cpp index 793f9708..6273623c 100644 --- a/src/map/IMG/trefile.cpp +++ b/src/map/IMG/trefile.cpp @@ -233,7 +233,7 @@ bool TREFile::load(int idx) if (i) sl.at(i-1)->setExtEnds(polygons, lines, points); - if (!seek(hdl, hdl.pos() + _extended.itemSize - rb)) + if (!seek(hdl, pos(hdl) + _extended.itemSize - rb)) goto error; }