From dcfde3a40622e8be5f9c2f67a2d4383df6356374 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:09:34 +0000 Subject: [PATCH] fix the multiple definitions of lexical casts methods (#1281) (#1282) --- hardware_interface/CMakeLists.txt | 1 + .../hardware_interface/lexical_casts.hpp | 19 +--------- hardware_interface/src/lexical_casts.cpp | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 hardware_interface/src/lexical_casts.cpp diff --git a/hardware_interface/CMakeLists.txt b/hardware_interface/CMakeLists.txt index 2fb31641b0..aa7ca933ff 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -29,6 +29,7 @@ add_library( src/resource_manager.cpp src/sensor.cpp src/system.cpp + src/lexical_casts.cpp ) target_include_directories( ${PROJECT_NAME} diff --git a/hardware_interface/include/hardware_interface/lexical_casts.hpp b/hardware_interface/include/hardware_interface/lexical_casts.hpp index e0333756f4..1b9bad7018 100644 --- a/hardware_interface/include/hardware_interface/lexical_casts.hpp +++ b/hardware_interface/include/hardware_interface/lexical_casts.hpp @@ -28,24 +28,9 @@ namespace hardware_interface * from https://github.com/ros-planning/srdfdom/blob/ad17b8d25812f752c397a6011cec64aeff090c46/src/model.cpp#L53 */ -double stod(const std::string & s) -{ - // convert from string using no locale - std::istringstream stream(s); - stream.imbue(std::locale::classic()); - double result; - stream >> result; - if (stream.fail() || !stream.eof()) - { - throw std::invalid_argument("Failed converting string to real number"); - } - return result; -} +double stod(const std::string & s); -bool parse_bool(const std::string & bool_string) -{ - return bool_string == "true" || bool_string == "True"; -} +bool parse_bool(const std::string & bool_string); } // namespace hardware_interface diff --git a/hardware_interface/src/lexical_casts.cpp b/hardware_interface/src/lexical_casts.cpp new file mode 100644 index 0000000000..c9adcccf83 --- /dev/null +++ b/hardware_interface/src/lexical_casts.cpp @@ -0,0 +1,37 @@ +// Copyright 2024 ros2_control Development Team +// +// 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 "hardware_interface/lexical_casts.hpp" + +namespace hardware_interface +{ +double stod(const std::string & s) +{ + // convert from string using no locale + std::istringstream stream(s); + stream.imbue(std::locale::classic()); + double result; + stream >> result; + if (stream.fail() || !stream.eof()) + { + throw std::invalid_argument("Failed converting string to real number"); + } + return result; +} + +bool parse_bool(const std::string & bool_string) +{ + return bool_string == "true" || bool_string == "True"; +} +} // namespace hardware_interface