rclcpp  master
C++ ROS Client Library API
utilities.hpp
Go to the documentation of this file.
1 // Copyright 2014 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 #ifndef RCLCPP__UTILITIES_HPP_
16 #define RCLCPP__UTILITIES_HPP_
17 
18 #include <chrono>
19 #include <functional>
20 #include <limits>
21 #include <vector>
22 
24 
25 #include "rcl/guard_condition.h"
26 #include "rcl/wait.h"
27 
28 #include "rmw/macros.h"
29 #include "rmw/rmw.h"
30 
31 #ifdef ANDROID
32 #include <string>
33 #include <sstream>
34 
35 namespace std
36 {
37 template<typename T>
38 std::string to_string(T value)
39 {
41  os << value;
42  return os.str();
43 }
44 }
45 #endif
46 
47 namespace rclcpp
48 {
50 
55 void
56 init(int argc, char const * const argv[]);
57 
59 
67 init_and_remove_ros_arguments(int argc, char const * const argv[]);
68 
70 
82 remove_ros_arguments(int argc, char const * const argv[]);
83 
85 
87 bool
88 ok();
89 
92 void
93 shutdown();
94 
96 
98 void
99 on_shutdown(std::function<void(void)> callback);
100 
102 
116 
118 
127 void
129 
131 
136 bool
137 sleep_for(const std::chrono::nanoseconds & nanoseconds);
138 
140 
149 template<typename T>
150 bool
151 add_will_overflow(const T x, const T y)
152 {
153  return (y > 0) && (x > (std::numeric_limits<T>::max() - y));
154 }
155 
157 
166 template<typename T>
167 bool
168 add_will_underflow(const T x, const T y)
169 {
170  return (y < 0) && (x < (std::numeric_limits<T>::min() - y));
171 }
172 
174 
183 template<typename T>
184 bool
185 sub_will_overflow(const T x, const T y)
186 {
187  return (y < 0) && (x > (std::numeric_limits<T>::max() + y));
188 }
189 
191 
200 template<typename T>
201 bool
202 sub_will_underflow(const T x, const T y)
203 {
204  return (y > 0) && (x < (std::numeric_limits<T>::min() + y));
205 }
206 
207 } // namespace rclcpp
208 
209 #endif // RCLCPP__UTILITIES_HPP_
void init(int argc, char const *const argv[])
Initialize communications via the rmw implementation and set up a global signal handler.
rcl_guard_condition_t * get_sigint_guard_condition(rcl_wait_set_t *wait_set)
Get a handle to the rmw guard condition that manages the signal handler.
bool sub_will_overflow(const T x, const T y)
Safely check if subtraction will overflow.
Definition: utilities.hpp:185
T to_string(T... args)
Definition: allocator_common.hpp:24
bool add_will_underflow(const T x, const T y)
Safely check if addition will underflow.
Definition: utilities.hpp:168
bool sleep_for(const std::chrono::nanoseconds &nanoseconds)
Use the global condition variable to block for the specified amount of time.
std::vector< std::string > init_and_remove_ros_arguments(int argc, char const *const argv[])
Initialize communications via the rmw implementation and set up a global signal handler.
void release_sigint_guard_condition(rcl_wait_set_t *wait_set)
Release the previously allocated guard condition that manages the signal handler. ...
void shutdown()
Notify the signal handler and rmw that rclcpp is shutting down.
void on_shutdown(std::function< void(void)> callback)
Register a function to be called when shutdown is called.
bool sub_will_underflow(const T x, const T y)
Safely check if subtraction will underflow.
Definition: utilities.hpp:202
T str(T... args)
bool add_will_overflow(const T x, const T y)
Safely check if addition will overflow.
Definition: utilities.hpp:151
T max(T... args)
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
bool ok()
Check rclcpp&#39;s status.
std::vector< std::string > remove_ros_arguments(int argc, char const *const argv[])
Remove ROS-specific arguments from argument vector.