From 71506d5f12e1e8529be4951ccf45f7144969f841 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Tue, 9 Jan 2024 10:41:06 +0100 Subject: [PATCH] fix the multiple definitions of lexical casts methods (#1281) --- 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 bcd03a0a16..510d970c84 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -27,6 +27,7 @@ add_library(hardware_interface SHARED src/resource_manager.cpp src/sensor.cpp src/system.cpp + src/lexical_casts.cpp ) target_compile_features(hardware_interface PUBLIC cxx_std_17) target_include_directories(hardware_interface PUBLIC 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