From 829e2dc43f087668c0ae0cf8613c21ef83acf7fe Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Thu, 27 Sep 2018 14:12:58 +0200 Subject: [PATCH] Replace custom SplitString() by absl::StrSplit() (#1026) code simplification --- .../cartographer_ros/assets_writer.cc | 1 - .../cartographer_ros/assets_writer_main.cc | 5 ++- .../cartographer_ros/offline_node.cc | 15 ++++---- .../cartographer_ros/split_string.cc | 34 ------------------- .../cartographer_ros/split_string.h | 30 ---------------- 5 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 cartographer_ros/cartographer_ros/split_string.cc delete mode 100644 cartographer_ros/cartographer_ros/split_string.h diff --git a/cartographer_ros/cartographer_ros/assets_writer.cc b/cartographer_ros/cartographer_ros/assets_writer.cc index 51875b5..688168b 100644 --- a/cartographer_ros/cartographer_ros/assets_writer.cc +++ b/cartographer_ros/cartographer_ros/assets_writer.cc @@ -35,7 +35,6 @@ #include "cartographer/transform/transform_interpolation_buffer.h" #include "cartographer_ros/msg_conversion.h" #include "cartographer_ros/ros_map_writing_points_processor.h" -#include "cartographer_ros/split_string.h" #include "cartographer_ros/time_conversion.h" #include "cartographer_ros/urdf_reader.h" #include "gflags/gflags.h" diff --git a/cartographer_ros/cartographer_ros/assets_writer_main.cc b/cartographer_ros/cartographer_ros/assets_writer_main.cc index d931abf..c4dff01 100644 --- a/cartographer_ros/cartographer_ros/assets_writer_main.cc +++ b/cartographer_ros/cartographer_ros/assets_writer_main.cc @@ -14,8 +14,8 @@ * limitations under the License. */ +#include "absl/strings/str_split.h" #include "cartographer_ros/assets_writer.h" -#include "cartographer_ros/split_string.h" #include "gflags/gflags.h" #include "glog/logging.h" @@ -55,8 +55,7 @@ int main(int argc, char** argv) { << "-pose_graph_filename is missing."; ::cartographer_ros::AssetsWriter asset_writer( - FLAGS_pose_graph_filename, - cartographer_ros::SplitString(FLAGS_bag_filenames, ','), + FLAGS_pose_graph_filename, absl::StrSplit(FLAGS_bag_filenames, ','), FLAGS_output_file_prefix); asset_writer.Run(FLAGS_configuration_directory, FLAGS_configuration_basename, diff --git a/cartographer_ros/cartographer_ros/offline_node.cc b/cartographer_ros/cartographer_ros/offline_node.cc index 4268083..58bca6a 100644 --- a/cartographer_ros/cartographer_ros/offline_node.cc +++ b/cartographer_ros/cartographer_ros/offline_node.cc @@ -22,9 +22,9 @@ #include #include +#include "absl/strings/str_split.h" #include "cartographer_ros/node.h" #include "cartographer_ros/playable_bag.h" -#include "cartographer_ros/split_string.h" #include "cartographer_ros/urdf_reader.h" #include "gflags/gflags.h" #include "ros/callback_queue.h" @@ -86,11 +86,11 @@ void RunOfflineNode(const MapBuilderFactory& map_builder_factory) { << "-configuration_basenames is missing."; CHECK(!(FLAGS_bag_filenames.empty() && FLAGS_load_state_filename.empty())) << "-bag_filenames and -load_state_filename cannot both be unspecified."; - const auto bag_filenames = - cartographer_ros::SplitString(FLAGS_bag_filenames, ','); + const std::vector bag_filenames = + absl::StrSplit(FLAGS_bag_filenames, ','); cartographer_ros::NodeOptions node_options; - const auto configuration_basenames = - cartographer_ros::SplitString(FLAGS_configuration_basenames, ','); + const std::vector configuration_basenames = + absl::StrSplit(FLAGS_configuration_basenames, ','); std::vector bag_trajectory_options(1); std::tie(node_options, bag_trajectory_options.at(0)) = LoadOptions(FLAGS_configuration_directory, configuration_basenames.at(0)); @@ -122,8 +122,9 @@ void RunOfflineNode(const MapBuilderFactory& map_builder_factory) { tf2_ros::Buffer tf_buffer; std::vector urdf_transforms; - for (const std::string& urdf_filename : - cartographer_ros::SplitString(FLAGS_urdf_filenames, ',')) { + const std::vector urdf_filenames = + absl::StrSplit(FLAGS_urdf_filenames, ','); + for (const auto& urdf_filename : urdf_filenames) { const auto current_urdf_transforms = ReadStaticTransformsFromUrdf(urdf_filename, &tf_buffer); urdf_transforms.insert(urdf_transforms.end(), diff --git a/cartographer_ros/cartographer_ros/split_string.cc b/cartographer_ros/cartographer_ros/split_string.cc deleted file mode 100644 index 4924e69..0000000 --- a/cartographer_ros/cartographer_ros/split_string.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2016 The Cartographer Authors - * - * 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 "cartographer_ros/split_string.h" - -#include - -namespace cartographer_ros { - -std::vector SplitString(const std::string& input, - const char delimiter) { - std::istringstream stream(input); - std::string token; - std::vector tokens; - while (std::getline(stream, token, delimiter)) { - tokens.push_back(token); - } - return tokens; -} - -} // namespace cartographer_ros diff --git a/cartographer_ros/cartographer_ros/split_string.h b/cartographer_ros/cartographer_ros/split_string.h deleted file mode 100644 index f12afbb..0000000 --- a/cartographer_ros/cartographer_ros/split_string.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2016 The Cartographer Authors - * - * 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. - */ - -#ifndef CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_SPLIT_STRING_H -#define CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_SPLIT_STRING_H - -#include -#include - -namespace cartographer_ros { - -// Split 'input' at 'delimiter'. -std::vector SplitString(const std::string& input, char delimiter); - -} // namespace cartographer_ros - -#endif // CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_SPLIT_STRING_H