Skip to content

Commit cc40d17

Browse files
committed
improvment: make Lane::predecessor/successor optional to comply with odr standard
1 parent cbf9715 commit cc40d17

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

include/Lane.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cstddef>
66
#include <functional>
77
#include <map>
8+
#include <optional>
89
#include <ostream>
910
#include <set>
1011
#include <string>
@@ -56,10 +57,11 @@ struct Lane
5657
LaneKey key;
5758
int id;
5859
bool level = false;
59-
int predecessor = 0;
60-
int successor = 0;
6160
std::string type = "";
6261

62+
std::optional<int> predecessor;
63+
std::optional<int> successor;
64+
6365
CubicSpline lane_width;
6466
CubicSpline outer_border;
6567

src/OpenDriveMap.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
414414
Lane(road_id, s0, lane_id, lane_node.attribute("level").as_bool(false), lane_node.attribute("type").as_string(""))})
415415
.first->second;
416416

417-
if (const pugi::xml_node node = lane_node.child("link").child("predecessor"))
418-
lane.predecessor = node.attribute("id").as_int(0);
419-
if (const pugi::xml_node node = lane_node.child("link").child("successor"))
420-
lane.successor = node.attribute("id").as_int(0);
417+
if (const pugi::xml_attribute id_attr = lane_node.child("link").child("predecessor").attribute("id"))
418+
lane.predecessor = id_attr.as_int();
419+
if (const pugi::xml_attribute id_attr = lane_node.child("link").child("successor").attribute("id"))
420+
lane.successor = id_attr.as_int();
421421

422422
for (const pugi::xml_node lane_width_node : lane_node.children("width"))
423423
{
@@ -895,11 +895,12 @@ RoutingGraph OpenDriveMap::get_routing_graph() const
895895
{
896896
if (target_lanesection)
897897
{
898-
int target_lane_id = predecessors ? lane.predecessor : lane.successor;
899-
auto it = target_lanesection->id_to_lane.find(target_lane_id);
900-
if (it != target_lanesection->id_to_lane.end())
898+
std::optional<int> target_lane_id = predecessors ? lane.predecessor : lane.successor;
899+
if (target_lane_id)
901900
{
902-
return it->second;
901+
auto it = target_lanesection->id_to_lane.find(target_lane_id.value());
902+
if (it != target_lanesection->id_to_lane.end())
903+
return it->second;
903904
}
904905
}
905906
return std::nullopt;

0 commit comments

Comments
 (0)