From 517ee08462e1b0a2fda2fa999f04c634ab66801b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Fri, 14 Jul 2023 16:54:54 +0300 Subject: [PATCH] parsing functions --- autoware_version_manager/package.xml | 1 + .../src/include/parse_version.hpp | 14 ++++- .../src/parse_version.cpp | 59 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 autoware_version_manager/src/parse_version.cpp diff --git a/autoware_version_manager/package.xml b/autoware_version_manager/package.xml index ca9e73d7..c79124a9 100644 --- a/autoware_version_manager/package.xml +++ b/autoware_version_manager/package.xml @@ -17,6 +17,7 @@ autoware_system_msgs rclcpp rclcpp_components + yaml_cpp_vendor ament_cmake_ros ament_lint_auto diff --git a/autoware_version_manager/src/include/parse_version.hpp b/autoware_version_manager/src/include/parse_version.hpp index 825ff0b9..d46989e3 100644 --- a/autoware_version_manager/src/include/parse_version.hpp +++ b/autoware_version_manager/src/include/parse_version.hpp @@ -17,12 +17,22 @@ #include "include/version_types.hpp" +#include + +#include + namespace autoware_version_manager { -class ParseVersion +namespace parse_version { -}; +VersionAutoware parse_autoware_version(const YAML::Node & yaml_node); +VersionAutoware parse_autoware_version(const std::filesystem::path & path); + +VersionInterface parse_interface_version(const YAML::Node & yaml_node); +VersionInterface parse_interface_version(const std::filesystem::path & path); + +} // namespace parse_version } // namespace autoware_version_manager #endif // PARSE_VERSION_HPP_ diff --git a/autoware_version_manager/src/parse_version.cpp b/autoware_version_manager/src/parse_version.cpp new file mode 100644 index 00000000..192ebf1b --- /dev/null +++ b/autoware_version_manager/src/parse_version.cpp @@ -0,0 +1,59 @@ +// Copyright 2023 The Autoware Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "include/parse_version.hpp" + +#include "include/version_types.hpp" + +#include + +#include + +namespace autoware_version_manager +{ +namespace parse_version +{ + +VersionAutoware parse_autoware_version(const YAML::Node & yaml_node) +{ + VersionAutoware version; + version.year = yaml_node["year"].as(); + version.minor = yaml_node["minor"].as(); + version.micro = yaml_node["micro"].as(); + return version; +} + +VersionAutoware parse_autoware_version(const std::filesystem::path & path) +{ + YAML::Node yaml_node = YAML::LoadFile(path.string()); + return parse_autoware_version(yaml_node); +} + +VersionInterface parse_interface_version(const YAML::Node & yaml_node) +{ + VersionInterface version; + version.major = yaml_node["major"].as(); + version.minor = yaml_node["minor"].as(); + version.patch = yaml_node["patch"].as(); + return version; +} + +VersionInterface parse_interface_version(const std::filesystem::path & path) +{ + YAML::Node yaml_node = YAML::LoadFile(path.string()); + return parse_interface_version(yaml_node); +} + +} // namespace parse_version +} // namespace autoware_version_manager