ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
time.hpp
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__TIME_HPP_
16 #define RCLCPP__TIME_HPP_
17 
18 #include "builtin_interfaces/msg/time.hpp"
19 
20 #include "rclcpp/visibility_control.hpp"
21 
22 #include "rcl/time.h"
23 
24 #include "rclcpp/duration.hpp"
25 
26 namespace rclcpp
27 {
28 
29 class Clock;
30 
31 class Time
32 {
33 public:
35 
45  RCLCPP_PUBLIC
46  Time(int32_t seconds, uint32_t nanoseconds, rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
47 
49 
53  RCLCPP_PUBLIC
54  explicit Time(int64_t nanoseconds = 0, rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
55 
57  RCLCPP_PUBLIC
58  Time(const Time & rhs);
59 
61 
66  RCLCPP_PUBLIC
67  Time(
68  const builtin_interfaces::msg::Time & time_msg,
69  rcl_clock_type_t clock_type = RCL_ROS_TIME);
70 
72 
75  RCLCPP_PUBLIC
76  explicit Time(const rcl_time_point_t & time_point);
77 
79  RCLCPP_PUBLIC
80  virtual ~Time();
81 
83  RCLCPP_PUBLIC
84  operator builtin_interfaces::msg::Time() const;
85 
89  RCLCPP_PUBLIC
90  Time &
91  operator=(const Time & rhs);
92 
99  RCLCPP_PUBLIC
100  Time &
101  operator=(const builtin_interfaces::msg::Time & time_msg);
102 
106  RCLCPP_PUBLIC
107  bool
108  operator==(const rclcpp::Time & rhs) const;
109 
110  RCLCPP_PUBLIC
111  bool
112  operator!=(const rclcpp::Time & rhs) const;
113 
117  RCLCPP_PUBLIC
118  bool
119  operator<(const rclcpp::Time & rhs) const;
120 
124  RCLCPP_PUBLIC
125  bool
126  operator<=(const rclcpp::Time & rhs) const;
127 
131  RCLCPP_PUBLIC
132  bool
133  operator>=(const rclcpp::Time & rhs) const;
134 
138  RCLCPP_PUBLIC
139  bool
140  operator>(const rclcpp::Time & rhs) const;
141 
145  RCLCPP_PUBLIC
146  Time
147  operator+(const rclcpp::Duration & rhs) const;
148 
153  RCLCPP_PUBLIC
154  Duration
155  operator-(const rclcpp::Time & rhs) const;
156 
160  RCLCPP_PUBLIC
161  Time
162  operator-(const rclcpp::Duration & rhs) const;
163 
167  RCLCPP_PUBLIC
168  Time &
169  operator+=(const rclcpp::Duration & rhs);
170 
174  RCLCPP_PUBLIC
175  Time &
176  operator-=(const rclcpp::Duration & rhs);
177 
179 
182  RCLCPP_PUBLIC
184  nanoseconds() const;
185 
187 
190  RCLCPP_PUBLIC
191  static Time
192  max();
193 
195 
201  RCLCPP_PUBLIC
202  double
203  seconds() const;
204 
206 
209  RCLCPP_PUBLIC
211  get_clock_type() const;
212 
213 private:
214  rcl_time_point_t rcl_time_;
215  friend Clock; // Allow clock to manipulate internal data
216 };
217 
221 RCLCPP_PUBLIC
222 Time
223 operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs);
224 
225 } // namespace rclcpp
226 
227 #endif // RCLCPP__TIME_HPP_
RCLCPP_PUBLIC Time & operator-=(const rclcpp::Duration &rhs)
Definition: time.cpp:264
static RCLCPP_PUBLIC Time max()
Get the maximum representable value.
Definition: time.cpp:279
RCLCPP_PUBLIC Time(const Time &rhs)
Copy constructor.
RCLCPP_PUBLIC Time & operator+=(const rclcpp::Duration &rhs)
Definition: time.cpp:249
RCLCPP_PUBLIC bool operator>=(const rclcpp::Time &rhs) const
Definition: time.cpp:153
RCLCPP_PUBLIC double seconds() const
Get the seconds since epoch.
Definition: time.cpp:225
virtual RCLCPP_PUBLIC ~Time()
Time destructor.
Definition: time.cpp:87
RCLCPP_PUBLIC Duration operator-(const rclcpp::Time &rhs) const
Definition: time.cpp:185
RCLCPP_PUBLIC rcl_time_point_value_t nanoseconds() const
Get the nanoseconds since epoch.
Definition: time.cpp:219
RCLCPP_PUBLIC bool operator<(const rclcpp::Time &rhs) const
Definition: time.cpp:133
RCLCPP_PUBLIC Time & operator=(const Time &rhs)
RCLCPP_PUBLIC rcl_clock_type_t get_clock_type() const
Get the clock type.
Definition: time.cpp:231
RCLCPP_PUBLIC bool operator<=(const rclcpp::Time &rhs) const
Definition: time.cpp:143
RCLCPP_PUBLIC bool operator==(const rclcpp::Time &rhs) const
Definition: time.cpp:117
RCLCPP_PUBLIC Time operator+(const rclcpp::Duration &rhs) const
Definition: time.cpp:173
RCLCPP_PUBLIC bool operator>(const rclcpp::Time &rhs) const
Definition: time.cpp:163
RCLCPP_PUBLIC Time(int32_t seconds, uint32_t nanoseconds, rcl_clock_type_t clock_type=RCL_SYSTEM_TIME)
Time constructor.
Definition: time.cpp:49
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC Time operator+(const rclcpp::Duration &lhs, const rclcpp::Time &rhs)
Definition: time.cpp:237
A single point in time, measured in nanoseconds, the reference point is based on the source.
Definition: time.h:156
enum rcl_clock_type_e rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
rcutils_time_point_value_t rcl_time_point_value_t
A single point in time, measured in nanoseconds since the Unix epoch.
Definition: time.h:46
@ RCL_ROS_TIME
Use ROS time.
Definition: time.h:66
@ RCL_SYSTEM_TIME
Use system time.
Definition: time.h:68