mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
[traffxml] Parse and store distance for location points
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -128,6 +128,27 @@ std::optional<uint8_t> 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<float> 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<Point> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user