diff --git a/traffxml/traff_model.cpp b/traffxml/traff_model.cpp index f0178b1d2..886515777 100644 --- a/traffxml/traff_model.cpp +++ b/traffxml/traff_model.cpp @@ -550,7 +550,7 @@ std::string DebugPrint(Point point) std::ostringstream os; os << "Point { "; os << "coordinates: " << DebugPrint(point.m_coordinates) << ", "; - // TODO optional float m_distance; (not in struct yet) + os << "distance: " << (point.m_distance ? std::to_string(point.m_distance.value()) : "nullopt") << ", "; os << "junctionName: " << point.m_junctionName.value_or("nullopt") << ", "; os << "junctionRef: " << point.m_junctionRef.value_or("nullopt"); os << " }"; diff --git a/traffxml/traff_model.hpp b/traffxml/traff_model.hpp index 50a08e646..b36a36748 100644 --- a/traffxml/traff_model.hpp +++ b/traffxml/traff_model.hpp @@ -275,7 +275,7 @@ struct Point // TODO role? ms::LatLon m_coordinates = ms::LatLon::Zero(); - // TODO optional float m_distance; + std::optional m_distance; std::optional m_junctionName; std::optional m_junctionRef; }; diff --git a/traffxml/traff_model_xml.cpp b/traffxml/traff_model_xml.cpp index a9d612465..5a3606971 100644 --- a/traffxml/traff_model_xml.cpp +++ b/traffxml/traff_model_xml.cpp @@ -128,6 +128,27 @@ std::optional OptionalIntegerFromXml(pugi::xml_attribute attribute) } } +/** + * @brief Retrieves a float value from an attribute. + * + * @param attribute The XML attribute to retrieve. + * @return `true` on success, `false` if the attribute is not set or does not contain a float value. + */ +std::optional OptionalFloatFromXml(pugi::xml_attribute attribute) +{ + if (attribute.empty()) + return std::nullopt; + try + { + float result = std::stof(attribute.as_string()); + return result; + } + catch (std::invalid_argument const& ex) + { + return std::nullopt; + } +} + /** * @brief Retrieves a string from an attribute. * @@ -405,6 +426,7 @@ std::optional OptionalPointFromXml(pugi::xml_node node) result.m_junctionName = OptionalStringFromXml(node.attribute("junction_name")); result.m_junctionRef = OptionalStringFromXml(node.attribute("junction_ref")); + result.m_distance = OptionalFloatFromXml(node.attribute("distance")); return result; }