ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
scope_exit.hpp
1 // Copyright 2015 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Based on: http://the-witness.net/news/2012/11/scopeexit-in-c11/
16 // But I changed the lambda to include by reference rather than value, see:
17 // http://the-witness.net/news/2012/11/scopeexit-in-c11/comment-page-1/#comment-86873
18 
19 #ifndef RCLCPP__SCOPE_EXIT_HPP_
20 #define RCLCPP__SCOPE_EXIT_HPP_
21 
22 // TODO(christophebedard) remove this header completely in I-turtle
23 
24 #warning rclcpp/scope_exit.hpp has been deprecated, please use rcpputils/scope_exit.hpp instead
25 
26 #include <functional>
27 
28 #include "rclcpp/macros.hpp"
29 
30 namespace rclcpp
31 {
32 
33 template<typename Callable>
34 struct ScopeExit
35 {
36  explicit ScopeExit(Callable callable)
37  : callable_(callable) {}
38  ~ScopeExit() {callable_();}
39 
40 private:
41  Callable callable_;
42 };
43 
44 template<typename Callable>
46 make_scope_exit(Callable callable)
47 {
48  return ScopeExit<Callable>(callable);
49 }
50 
51 } // namespace rclcpp
52 
53 #define RCLCPP_SCOPE_EXIT(code) \
54  auto RCLCPP_STRING_JOIN(scope_exit_, __LINE__) = rclcpp::make_scope_exit([&]() {code;})
55 
56 #endif // RCLCPP__SCOPE_EXIT_HPP_
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.