From ae27fe7f786557515a165babf2243f7ff1497f6a Mon Sep 17 00:00:00 2001 From: Axel Date: Mon, 17 Feb 2020 11:37:15 +0100 Subject: [PATCH] Code cleanup. --- .../carla/opendrive/parser/SignalParser.cpp | 182 +++++++++--------- 1 file changed, 89 insertions(+), 93 deletions(-) diff --git a/LibCarla/source/carla/opendrive/parser/SignalParser.cpp b/LibCarla/source/carla/opendrive/parser/SignalParser.cpp index 27f87fcb5..93d3a56aa 100644 --- a/LibCarla/source/carla/opendrive/parser/SignalParser.cpp +++ b/LibCarla/source/carla/opendrive/parser/SignalParser.cpp @@ -42,102 +42,98 @@ namespace parser { road::RoadId road_id = road_node.attribute("id").as_uint(); const pugi::xml_node signals_node = road_node.child("signals"); - for (pugi::xml_node signal_node = signals_node.child("signal"); - signal_node; - signal_node = signal_node.next_sibling("signal")) { - const double s_position = signal_node.attribute("s").as_double(); - const double t_position = signal_node.attribute("t").as_double(); - const road::SignId signal_id = signal_node.attribute("id").value(); - const std::string name = signal_node.attribute("name").value(); - const std::string dynamic = signal_node.attribute("dynamic").value(); - const std::string orientation = signal_node.attribute("orientation").value(); - const double zOffset = signal_node.attribute("zOffSet").as_double(); - const std::string country = signal_node.attribute("country").value(); - const std::string type = signal_node.attribute("type").value(); - const std::string subtype = signal_node.attribute("subtype").value(); - const double value = signal_node.attribute("value").as_double(); - const std::string unit = signal_node.attribute("unit").value(); - const double height = signal_node.attribute("height").as_double(); - const double width = signal_node.attribute("width").as_double(); - const std::string text = signal_node.attribute("text").value(); - const double hOffset = signal_node.attribute("hOffset").as_double(); - const double pitch = signal_node.attribute("pitch").as_double(); - const double roll = signal_node.attribute("roll").as_double(); - log_debug("Road: ", - road_id, - "Adding Signal: ", - s_position, - t_position, - signal_id, - name, - dynamic, - orientation, - zOffset, - country, - type, - subtype, - value, - unit, - height, - width, - text, - hOffset, - pitch, - roll); + if(signals_node){ + for (pugi::xml_node signal_node : signals_node.children("signal")) { + const double s_position = signal_node.attribute("s").as_double(); + const double t_position = signal_node.attribute("t").as_double(); + const road::SignId signal_id = signal_node.attribute("id").value(); + const std::string name = signal_node.attribute("name").value(); + const std::string dynamic = signal_node.attribute("dynamic").value(); + const std::string orientation = signal_node.attribute("orientation").value(); + const double zOffset = signal_node.attribute("zOffSet").as_double(); + const std::string country = signal_node.attribute("country").value(); + const std::string type = signal_node.attribute("type").value(); + const std::string subtype = signal_node.attribute("subtype").value(); + const double value = signal_node.attribute("value").as_double(); + const std::string unit = signal_node.attribute("unit").value(); + const double height = signal_node.attribute("height").as_double(); + const double width = signal_node.attribute("width").as_double(); + const std::string text = signal_node.attribute("text").value(); + const double hOffset = signal_node.attribute("hOffset").as_double(); + const double pitch = signal_node.attribute("pitch").as_double(); + const double roll = signal_node.attribute("roll").as_double(); + log_debug("Road: ", + road_id, + "Adding Signal: ", + s_position, + t_position, + signal_id, + name, + dynamic, + orientation, + zOffset, + country, + type, + subtype, + value, + unit, + height, + width, + text, + hOffset, + pitch, + roll); - carla::road::Road *road = map_builder.GetRoad(road_id); - auto signal_reference = map_builder.AddSignal(road, - signal_id, - s_position, - t_position, - name, - dynamic, - orientation, - zOffset, - country, - type, - subtype, - value, - unit, - height, - width, - text, - hOffset, - pitch, - roll); - AddValidity(signal_reference, signal_node, "validity", map_builder); + carla::road::Road *road = map_builder.GetRoad(road_id); + auto signal_reference = map_builder.AddSignal(road, + signal_id, + s_position, + t_position, + name, + dynamic, + orientation, + zOffset, + country, + type, + subtype, + value, + unit, + height, + width, + text, + hOffset, + pitch, + roll); + AddValidity(signal_reference, signal_node, "validity", map_builder); - for (pugi::xml_node dependency_node = signal_node.child("dependency"); - dependency_node; - dependency_node = dependency_node.next_sibling("validity")) { - const std::string dependency_id = dependency_node.attribute("id").value(); - const std::string dependency_type = dependency_node.attribute("type").value(); - log_debug("Added dependency to signal ", signal_id, ":", dependency_id, dependency_type); - map_builder.AddDependencyToSignal(signal_id, dependency_id, dependency_type); + for (pugi::xml_node dependency_node : signal_node.children("dependency")) { + const std::string dependency_id = dependency_node.attribute("id").value(); + const std::string dependency_type = dependency_node.attribute("type").value(); + log_debug("Added dependency to signal ", signal_id, ":", dependency_id, dependency_type); + map_builder.AddDependencyToSignal(signal_id, dependency_id, dependency_type); + } + } + for (pugi::xml_node signal_reference_node : signals_node.children("signalReference")) { + const double s_position = signal_reference_node.attribute("s").as_double(); + const double t_position = signal_reference_node.attribute("t").as_double(); + const road::SignId signal_id = signal_reference_node.attribute("id").value(); + const std::string signal_reference_orientation = + signal_reference_node.attribute("orientation").value(); + log_debug("Road: ", + road_id, + "Added SignalReference ", + s_position, + t_position, + signal_reference_orientation); + carla::road::Road *road = map_builder.GetRoad(road_id); + auto signal_reference = map_builder.AddSignalReference( + road, + signal_id, + s_position, + t_position, + signal_reference_orientation); + AddValidity(signal_reference, signal_reference_node, "validity", map_builder); } - } - for (pugi::xml_node signal_reference_node = signals_node.child("signalReference"); - signal_reference_node; - signal_reference_node = signal_reference_node.next_sibling("signalReference")) { - const double s_position = signal_reference_node.attribute("s").as_double(); - const double t_position = signal_reference_node.attribute("t").as_double(); - const road::SignId signal_id = signal_reference_node.attribute("id").value(); - const std::string signal_reference_orientation = - signal_reference_node.attribute("orientation").value(); - log_debug("Road: ", - road_id, - "Added SignalReference ", - s_position, - t_position, - signal_reference_orientation); - carla::road::Road *road = map_builder.GetRoad(road_id); - auto signal_reference = map_builder.AddSignalReference( - road, - signal_id, - s_position, - t_position, - signal_reference_orientation); - AddValidity(signal_reference, signal_reference_node, "validity", map_builder); } } }