Skip to content

Commit

Permalink
also implement direct jump to node/way/rel start in XMLSource
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Nov 11, 2024
1 parent 1a4e67b commit 27e6323
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/pfaedle/osm/source/XMLSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ using pfaedle::osm::source::OsmSourceAttr;

// _____________________________________________________________________________
XMLSource::XMLSource(const std::string& path) : _path(path), _xml(path) {
// init states
_start = _xml.state();
_nodeBeg = _xml.state();
_wayBeg = _xml.state();
_relBeg = _xml.state();

// seek node begin
seekNodes();

// set individual states to node begin
_nodeBeg = _xml.state();
_wayBeg = _xml.state();
_relBeg = _xml.state();
}

// _____________________________________________________________________________
Expand All @@ -27,36 +40,39 @@ const OsmSourceNode* XMLSource::nextNode() {

if (_inNodeBlock) {
// block ended
if (strcmp(cur.name, "node")) return 0;
if (strcmp(cur.name, "node")) {
_wayBeg = _xml.state();
return 0;
}

_curNode.lon = util::atof(cur.attr("lon"), 7);
_curNode.lat = util::atof(cur.attr("lat"), 7);

_curNode.id = util::atoul(cur.attr("id"));

return &_curNode;
}

} while (_xml.next());

return 0;
}

// _____________________________________________________________________________
void XMLSource::seekNodes() {
_xml.reset();
while (_xml.next() && strcmp(_xml.get().name, "node")) {}
_xml.set_state(_nodeBeg);
while (strcmp(_xml.get().name, "node") && _xml.next()) {}
}

// _____________________________________________________________________________
void XMLSource::seekWays() {
_xml.reset();
while (_xml.next() && strcmp(_xml.get().name, "way")) {}
_xml.set_state(_wayBeg);
while (strcmp(_xml.get().name, "way") && _xml.next()) {}
}

// _____________________________________________________________________________
void XMLSource::seekRels() {
_xml.reset();
while (_xml.next() && strcmp(_xml.get().name, "relation")) {}
_xml.set_state(_relBeg);
while (strcmp(_xml.get().name, "relation") && _xml.next()) {}
}

// _____________________________________________________________________________
Expand All @@ -74,7 +90,10 @@ const OsmSourceWay* XMLSource::nextWay() {

if (_inWayBlock) {
// block ended
if (strcmp(cur.name, "way")) return 0;
if (strcmp(cur.name, "way")) {
_relBeg = _xml.state();
return 0;
}
_curWay.id = util::atoul(cur.attr("id"));

return &_curWay;
Expand Down Expand Up @@ -166,7 +185,8 @@ const OsmSourceAttr XMLSource::nextAttr() {

// _____________________________________________________________________________
util::geo::Box<double> XMLSource::getBounds() {
_xml.reset();
_xml.set_state(_start);

while (_xml.next() && strcmp(_xml.get().name, "node")) {}

const pfxml::tag& cur = _xml.get();
Expand Down
5 changes: 5 additions & 0 deletions src/pfaedle/osm/source/XMLSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class XMLSource : public OsmSource {

pfxml::file _xml;

pfxml::parser_state _start;
pfxml::parser_state _nodeBeg;
pfxml::parser_state _wayBeg;
pfxml::parser_state _relBeg;

bool _inNodeBlock = false;
bool _inWayBlock = false;
bool _inRelBlock = false;
Expand Down

0 comments on commit 27e6323

Please sign in to comment.