rclcpp  master
C++ ROS Client Library API
duration.hpp
Go to the documentation of this file.
1 // Copyright 2017 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__DURATION_HPP_
16 #define RCLCPP__DURATION_HPP_
17 
18 #include <chrono>
19 
20 #include "builtin_interfaces/msg/duration.hpp"
21 #include "rcl/time.h"
23 
24 namespace rclcpp
25 {
27 {
28 public:
30 
39  Duration(int32_t seconds, uint32_t nanoseconds);
40 
41  // This constructor matches any numeric value - ints or floats.
42  explicit Duration(rcl_duration_value_t nanoseconds);
43 
44  // This constructor matches std::chrono::nanoseconds.
46 
47  // This constructor matches any std::chrono value other than nanoseconds
48  // intentionally not using explicit to create a conversion constructor
49  template<class Rep, class Period>
50  // cppcheck-suppress noExplicitConstructor
51  Duration(const std::chrono::duration<Rep, Period> & duration) // NOLINT(runtime/explicit)
52  : Duration(std::chrono::duration_cast<std::chrono::nanoseconds>(duration))
53  {}
54 
55  // cppcheck-suppress noExplicitConstructor
56  Duration(const builtin_interfaces::msg::Duration & duration_msg); // NOLINT(runtime/explicit)
57 
59 
62  explicit Duration(const rcl_duration_t & duration);
63 
64  Duration(const Duration & rhs);
65 
66  virtual ~Duration() = default;
67 
68  operator builtin_interfaces::msg::Duration() const;
69 
70  // cppcheck-suppress operatorEq // this is a false positive from cppcheck
71  Duration &
72  operator=(const Duration & rhs);
73 
74  Duration &
75  operator=(const builtin_interfaces::msg::Duration & duration_msg);
76 
77  bool
78  operator==(const rclcpp::Duration & rhs) const;
79 
80  bool
81  operator!=(const rclcpp::Duration & rhs) const;
82 
83  bool
84  operator<(const rclcpp::Duration & rhs) const;
85 
86  bool
87  operator<=(const rclcpp::Duration & rhs) const;
88 
89  bool
90  operator>=(const rclcpp::Duration & rhs) const;
91 
92  bool
93  operator>(const rclcpp::Duration & rhs) const;
94 
95  Duration
96  operator+(const rclcpp::Duration & rhs) const;
97 
98  Duration
99  operator-(const rclcpp::Duration & rhs) const;
100 
102 
105  static
106  Duration
107  max();
108 
109  Duration
110  operator*(double scale) const;
111 
113 
116  rcl_duration_value_t
117  nanoseconds() const;
118 
120 
125  double
126  seconds() const;
127 
129  static Duration
130  from_seconds(double seconds);
131 
133  template<class DurationT>
134  DurationT
135  to_chrono() const
136  {
137  return std::chrono::duration_cast<DurationT>(std::chrono::nanoseconds(this->nanoseconds()));
138  }
139 
141  rmw_time_t
142  to_rmw_time() const;
143 
144 private:
145  rcl_duration_t rcl_duration_;
146 };
147 
148 } // namespace rclcpp
149 
150 #endif // RCLCPP__DURATION_HPP_
rclcpp::operator==
bool operator==(const QoS &left, const QoS &right)
Check if two QoS profiles are exactly equal in all policy values.
rmw_time_t
rclcpp::Duration::to_chrono
DurationT to_chrono() const
Convert Duration into a std::chrono::Duration.
Definition: duration.hpp:135
std::chrono::nanoseconds
rclcpp::operator+
Time operator+(const rclcpp::Duration &lhs, const rclcpp::Time &rhs)
rclcpp::Duration::Duration
Duration(const std::chrono::duration< Rep, Period > &duration)
Definition: duration.hpp:51
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::Duration
Definition: duration.hpp:26
visibility_control.hpp
std
rclcpp::operator!=
bool operator!=(const QoS &left, const QoS &right)
rcl_duration_t