diff --git a/src/qlever-petrimaps/GeoJSONCache.h b/src/qlever-petrimaps/GeoJSONCache.h index 8a3cb9c..85d8b60 100644 --- a/src/qlever-petrimaps/GeoJSONCache.h +++ b/src/qlever-petrimaps/GeoJSONCache.h @@ -22,6 +22,16 @@ class GeoJSONCache : public GeomCache { return *this; }; + const util::geo::FPoint& getPoint(ID_TYPE id) const { + return std::get<0>(_points[id]); + } + size_t getLine(ID_TYPE id) const { + return std::get<0>(_lines[id]); + } + size_t getLineEnd(ID_TYPE id) const { + return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size(); + } + void load(); void setContent(const std::string& content); std::vector> getRelObjects() const; @@ -36,6 +46,8 @@ class GeoJSONCache : public GeomCache { // Map geomID to map std::map> _attr; // ------------------------ + std::vector> _points; + std::vector> _lines; protected: diff --git a/src/qlever-petrimaps/GeomCache.h b/src/qlever-petrimaps/GeomCache.h index 78a4623..b563edc 100644 --- a/src/qlever-petrimaps/GeomCache.h +++ b/src/qlever-petrimaps/GeomCache.h @@ -40,18 +40,13 @@ class GeomCache { return ready; } - const util::geo::FPoint& getPoint(ID_TYPE id) const { - return std::get<0>(_points[id]); - } + const virtual util::geo::FPoint& getPoint(ID_TYPE id) const = 0; + virtual size_t getLine(ID_TYPE id) const = 0; + virtual size_t getLineEnd(ID_TYPE id) const = 0; + const std::vector>& getLinePoints() const { return _linePoints; } - size_t getLine(ID_TYPE id) const { - return std::get<0>(_lines[id]); - } - size_t getLineEnd(ID_TYPE id) const { - return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size(); - } util::geo::DBox getLineBBox(size_t id) const; @@ -74,8 +69,6 @@ class GeomCache { mutable std::mutex _m; bool _ready = false; - std::vector> _points; - std::vector> _lines; std::vector> _linePoints; static bool pointValid(const util::geo::FPoint& p); diff --git a/src/qlever-petrimaps/SPARQLCache.cpp b/src/qlever-petrimaps/SPARQLCache.cpp index adcda49..9c1ec11 100644 --- a/src/qlever-petrimaps/SPARQLCache.cpp +++ b/src/qlever-petrimaps/SPARQLCache.cpp @@ -629,7 +629,7 @@ void SPARQLCache::request() { _points.resize(_pointsFSize); _pointsF.seekg(0); _pointsF.read(reinterpret_cast(&_points[0]), - sizeof(std::tuple) * _pointsFSize); + sizeof(util::geo::FPoint) * _pointsFSize); _pointsF.close(); _linePoints.resize(_linePointsFSize); @@ -641,7 +641,7 @@ void SPARQLCache::request() { _lines.resize(_linesFSize); _linesF.seekg(0); _linesF.read(reinterpret_cast(&_lines[0]), - sizeof(std::tuple) * _linesFSize); + sizeof(size_t) * _linesFSize); _linesF.close(); _qidToId.resize(_qidToIdFSize); @@ -950,7 +950,7 @@ void SPARQLCache::fromDisk(const std::string& fname) { f.read(reinterpret_cast(&numPoints), sizeof(size_t)); _points.resize(numPoints); posPoints = f.tellg(); - f.seekg(sizeof(std::tuple) * numPoints, f.cur); + f.seekg(sizeof(util::geo::FPoint) * numPoints, f.cur); // linePoints f.read(reinterpret_cast(&numLinePoints), sizeof(size_t)); @@ -962,7 +962,7 @@ void SPARQLCache::fromDisk(const std::string& fname) { f.read(reinterpret_cast(&numLines), sizeof(size_t)); _lines.resize(numLines); posLines = f.tellg(); - f.seekg(sizeof(std::tuple) * numLines, f.cur); + f.seekg(sizeof(size_t) * numLines, f.cur); // qidToId f.read(reinterpret_cast(&numQidToId), sizeof(size_t)); @@ -1020,7 +1020,7 @@ void SPARQLCache::serializeToDisk(const std::string& fname) const { size_t num = _points.size(); f.write(reinterpret_cast(&num), sizeof(size_t)); f.write(reinterpret_cast(&_points[0]), - sizeof(std::tuple) * num); + sizeof(util::geo::FPoint) * num); num = _linePoints.size(); f.write(reinterpret_cast(&num), sizeof(size_t)); @@ -1029,7 +1029,7 @@ void SPARQLCache::serializeToDisk(const std::string& fname) const { num = _lines.size(); f.write(reinterpret_cast(&num), sizeof(size_t)); - f.write(reinterpret_cast(&_lines[0]), sizeof(std::tuple) * num); + f.write(reinterpret_cast(&_lines[0]), sizeof(size_t) * num); num = _qidToId.size(); f.write(reinterpret_cast(&num), sizeof(size_t)); diff --git a/src/qlever-petrimaps/SPARQLCache.h b/src/qlever-petrimaps/SPARQLCache.h index 154cbf0..18aefef 100644 --- a/src/qlever-petrimaps/SPARQLCache.h +++ b/src/qlever-petrimaps/SPARQLCache.h @@ -27,6 +27,16 @@ class SPARQLCache : public GeomCache { return *this; }; + const util::geo::FPoint& getPoint(ID_TYPE id) const { + return _points[id]; + } + size_t getLine(ID_TYPE id) const { + return _lines[id]; + } + size_t getLineEnd(ID_TYPE id) const { + return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size(); + } + std::string load(const std::string& cacheFile); void request(); size_t requestSize(); @@ -83,6 +93,8 @@ class SPARQLCache : public GeomCache { IdMapping _lastQidToId; std::vector _qidToId; + std::vector _points; + std::vector _lines; std::string _dangling, _prev, _raw; ParseState _state;