From c473a65a5ea4ae2dbc69ecf88e8b4bd4c46c2f80 Mon Sep 17 00:00:00 2001 From: Alexander Belyaev <32522095+pifon2a@users.noreply.github.com> Date: Fri, 20 Jul 2018 10:07:45 +0200 Subject: [PATCH] Move FindOrNull to common/utils.h. (#1305) --- cartographer/common/utils.h | 29 +++++++++++++++++++ .../constraint/relative_pose_constraint_2d.cc | 17 ++--------- 2 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 cartographer/common/utils.h diff --git a/cartographer/common/utils.h b/cartographer/common/utils.h new file mode 100644 index 0000000..47fce47 --- /dev/null +++ b/cartographer/common/utils.h @@ -0,0 +1,29 @@ +/* + * Copyright 2018 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. + */ + +namespace cartographer { +namespace common { + +template +ValueType* FindOrNull(MapType& map, const KeyType& key) { + auto it = map.find(key); + if (it == map.end()) return nullptr; + return &(it->second); +} + +} // namespace common +} // namespace cartographer diff --git a/cartographer/pose_graph/constraint/relative_pose_constraint_2d.cc b/cartographer/pose_graph/constraint/relative_pose_constraint_2d.cc index 2634e77..f4c6dd0 100644 --- a/cartographer/pose_graph/constraint/relative_pose_constraint_2d.cc +++ b/cartographer/pose_graph/constraint/relative_pose_constraint_2d.cc @@ -17,21 +17,10 @@ #include "cartographer/pose_graph/constraint/relative_pose_constraint_2d.h" #include "cartographer/common/make_unique.h" +#include "cartographer/common/utils.h" namespace cartographer { namespace pose_graph { -namespace { - -// TODO(pifon): Move to common/utils.h. -template -ValueType* FindOrNull(MapType& map, const KeyType& key) { - auto it = map.find(key); - if (it == map.end()) return nullptr; - return &(it->second); -} - -} // namespace RelativePoseConstraint2D::RelativePoseConstraint2D( const ConstraintId& id, const proto::RelativePose2D& proto) @@ -43,13 +32,13 @@ RelativePoseConstraint2D::RelativePoseConstraint2D( void RelativePoseConstraint2D::AddToOptimizer(Nodes* nodes, ceres::Problem* problem) const { - auto first_node = FindOrNull(nodes->pose_2d_nodes, first_); + auto first_node = common::FindOrNull(nodes->pose_2d_nodes, first_); if (first_node == nullptr) { LOG(INFO) << "First node was not found in pose_2d_nodes."; return; } - auto second_node = FindOrNull(nodes->pose_2d_nodes, second_); + auto second_node = common::FindOrNull(nodes->pose_2d_nodes, second_); if (second_node == nullptr) { LOG(INFO) << "Second node was not found in pose_2d_nodes."; return;