Replace custom SplitString() by absl::StrSplit() (#1026)

code simplification
master
Michael Grupp 2018-09-27 14:12:58 +02:00 committed by Wally B. Feed
parent dd4d2af58b
commit 829e2dc43f
5 changed files with 10 additions and 75 deletions

View File

@ -35,7 +35,6 @@
#include "cartographer/transform/transform_interpolation_buffer.h" #include "cartographer/transform/transform_interpolation_buffer.h"
#include "cartographer_ros/msg_conversion.h" #include "cartographer_ros/msg_conversion.h"
#include "cartographer_ros/ros_map_writing_points_processor.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/time_conversion.h"
#include "cartographer_ros/urdf_reader.h" #include "cartographer_ros/urdf_reader.h"
#include "gflags/gflags.h" #include "gflags/gflags.h"

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "absl/strings/str_split.h"
#include "cartographer_ros/assets_writer.h" #include "cartographer_ros/assets_writer.h"
#include "cartographer_ros/split_string.h"
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "glog/logging.h" #include "glog/logging.h"
@ -55,8 +55,7 @@ int main(int argc, char** argv) {
<< "-pose_graph_filename is missing."; << "-pose_graph_filename is missing.";
::cartographer_ros::AssetsWriter asset_writer( ::cartographer_ros::AssetsWriter asset_writer(
FLAGS_pose_graph_filename, FLAGS_pose_graph_filename, absl::StrSplit(FLAGS_bag_filenames, ','),
cartographer_ros::SplitString(FLAGS_bag_filenames, ','),
FLAGS_output_file_prefix); FLAGS_output_file_prefix);
asset_writer.Run(FLAGS_configuration_directory, FLAGS_configuration_basename, asset_writer.Run(FLAGS_configuration_directory, FLAGS_configuration_basename,

View File

@ -22,9 +22,9 @@
#include <time.h> #include <time.h>
#include <chrono> #include <chrono>
#include "absl/strings/str_split.h"
#include "cartographer_ros/node.h" #include "cartographer_ros/node.h"
#include "cartographer_ros/playable_bag.h" #include "cartographer_ros/playable_bag.h"
#include "cartographer_ros/split_string.h"
#include "cartographer_ros/urdf_reader.h" #include "cartographer_ros/urdf_reader.h"
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "ros/callback_queue.h" #include "ros/callback_queue.h"
@ -86,11 +86,11 @@ void RunOfflineNode(const MapBuilderFactory& map_builder_factory) {
<< "-configuration_basenames is missing."; << "-configuration_basenames is missing.";
CHECK(!(FLAGS_bag_filenames.empty() && FLAGS_load_state_filename.empty())) CHECK(!(FLAGS_bag_filenames.empty() && FLAGS_load_state_filename.empty()))
<< "-bag_filenames and -load_state_filename cannot both be unspecified."; << "-bag_filenames and -load_state_filename cannot both be unspecified.";
const auto bag_filenames = const std::vector<std::string> bag_filenames =
cartographer_ros::SplitString(FLAGS_bag_filenames, ','); absl::StrSplit(FLAGS_bag_filenames, ',');
cartographer_ros::NodeOptions node_options; cartographer_ros::NodeOptions node_options;
const auto configuration_basenames = const std::vector<std::string> configuration_basenames =
cartographer_ros::SplitString(FLAGS_configuration_basenames, ','); absl::StrSplit(FLAGS_configuration_basenames, ',');
std::vector<TrajectoryOptions> bag_trajectory_options(1); std::vector<TrajectoryOptions> bag_trajectory_options(1);
std::tie(node_options, bag_trajectory_options.at(0)) = std::tie(node_options, bag_trajectory_options.at(0)) =
LoadOptions(FLAGS_configuration_directory, configuration_basenames.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; tf2_ros::Buffer tf_buffer;
std::vector<geometry_msgs::TransformStamped> urdf_transforms; std::vector<geometry_msgs::TransformStamped> urdf_transforms;
for (const std::string& urdf_filename : const std::vector<std::string> urdf_filenames =
cartographer_ros::SplitString(FLAGS_urdf_filenames, ',')) { absl::StrSplit(FLAGS_urdf_filenames, ',');
for (const auto& urdf_filename : urdf_filenames) {
const auto current_urdf_transforms = const auto current_urdf_transforms =
ReadStaticTransformsFromUrdf(urdf_filename, &tf_buffer); ReadStaticTransformsFromUrdf(urdf_filename, &tf_buffer);
urdf_transforms.insert(urdf_transforms.end(), urdf_transforms.insert(urdf_transforms.end(),

View File

@ -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 <sstream>
namespace cartographer_ros {
std::vector<std::string> SplitString(const std::string& input,
const char delimiter) {
std::istringstream stream(input);
std::string token;
std::vector<std::string> tokens;
while (std::getline(stream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
} // namespace cartographer_ros

View File

@ -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 <string>
#include <vector>
namespace cartographer_ros {
// Split 'input' at 'delimiter'.
std::vector<std::string> SplitString(const std::string& input, char delimiter);
} // namespace cartographer_ros
#endif // CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_SPLIT_STRING_H