diff --git a/tmp/lanelet2_extension/include/lanelet2_extension/io/autoware_osm_parser.hpp b/tmp/lanelet2_extension/include/lanelet2_extension/io/autoware_osm_parser.hpp index 50d04c65..e498fda0 100644 --- a/tmp/lanelet2_extension/include/lanelet2_extension/io/autoware_osm_parser.hpp +++ b/tmp/lanelet2_extension/include/lanelet2_extension/io/autoware_osm_parser.hpp @@ -24,6 +24,7 @@ #include #include +#include #include namespace lanelet::io_handlers @@ -58,6 +59,12 @@ class AutowareOsmParser : public OsmParser static constexpr const char * name() { return "autoware_osm_handler"; } }; +std::optional parseMajorVersion(const std::string & format_version); + +std::optional parseMinorVersion(const std::string & format_version); + +std::optional parsePatchVersion(const std::string & format_version); + } // namespace lanelet::io_handlers // NOLINTEND(readability-identifier-naming) diff --git a/tmp/lanelet2_extension/include/lanelet2_extension/version.hpp b/tmp/lanelet2_extension/include/lanelet2_extension/version.hpp index 4a88ea82..06dd5df1 100644 --- a/tmp/lanelet2_extension/include/lanelet2_extension/version.hpp +++ b/tmp/lanelet2_extension/include/lanelet2_extension/version.hpp @@ -21,11 +21,15 @@ namespace lanelet::autoware { +/* + * @brief denotes the major format_version + */ enum class Version : int { none = 0, v1, }; +// current format_version static constexpr Version version = Version::v1; } // namespace lanelet::autoware diff --git a/tmp/lanelet2_extension/lib/autoware_osm_parser.cpp b/tmp/lanelet2_extension/lib/autoware_osm_parser.cpp index 5c272004..426748e2 100644 --- a/tmp/lanelet2_extension/lib/autoware_osm_parser.cpp +++ b/tmp/lanelet2_extension/lib/autoware_osm_parser.cpp @@ -24,6 +24,7 @@ #include #include +#include #include namespace lanelet::io_handlers @@ -75,6 +76,63 @@ void AutowareOsmParser::parseVersions( } } +std::optional parseMajorVersion(const std::string & format_version) +{ + std::regex re(R"(^(\d+\.)?(\d+\.)?(\d+)$)"); + // NOTE(Mamoru Sobue): matches `1`, `1.10`, `1.10.100` + // `1` ==> [`1`, ``, ``] + // `1.10` ==> [`1.`, ``, `10`] + // `1.10.100` ==> [`1.`, `10.`, `100`] + std::smatch match; + if (!std::regex_match(format_version, match, re)) { + return std::nullopt; + } + std::string major = match[1].str(); + major.erase(std::remove(major.begin(), major.end(), '.'), major.end()); + return std::stoi(major); +} + +std::optional parseMinorVersion(const std::string & format_version) +{ + std::regex re(R"(^(\d+\.)?(\d+\.)?(\d+)$)"); + // NOTE(Mamoru Sobue): matches `1`, `1.10`, `1.10.100` + // `1` ==> [`1`, ``, ``] + // `1.10` ==> [`1.`, ``, `10`] + // `1.10.100` ==> [`1.`, `10.`, `100`] + std::smatch match; + if (!std::regex_match(format_version, match, re)) { + return std::nullopt; + } + std::string minor = match[2].str(); + if (minor == "") { + if (match[3].str() == "") { + return std::nullopt; + } + minor = match[3].str(); + } + minor.erase(std::remove(minor.begin(), minor.end(), '.'), minor.end()); + return std::stoi(minor); +} + +std::optional parsePatchVersion(const std::string & format_version) +{ + std::regex re(R"(^(\d+\.)?(\d+\.)?(\d+)$)"); + // NOTE(Mamoru Sobue): matches `1`, `1.10`, `1.10.100` + // `1` ==> [`1`, ``, ``] + // `1.10` ==> [`1.`, ``, `10`] + // `1.10.100` ==> [`1.`, `10.`, `100`] + std::smatch match; + if (!std::regex_match(format_version, match, re)) { + return std::nullopt; + } + std::string patch = match[3].str(); + if (patch == "") { + return std::nullopt; + } + patch.erase(std::remove(patch.begin(), patch.end(), '.'), patch.end()); + return std::stoi(patch); +} + } // namespace lanelet::io_handlers // NOLINTEND(readability-identifier-naming)