rclcpp  master
C++ ROS Client Library API
time.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__TIME_HPP_
16 #define RCLCPP__TIME_HPP_
17 
18 #include "builtin_interfaces/msg/time.hpp"
19 
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 
46  Time(int32_t seconds, uint32_t nanoseconds, rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
47 
49 
54  explicit Time(int64_t nanoseconds = 0, rcl_clock_type_t clock_type = RCL_SYSTEM_TIME);
55 
58  Time(const Time & rhs);
59 
61 
67  Time(
68  const builtin_interfaces::msg::Time & time_msg,
69  rcl_clock_type_t clock_type = RCL_ROS_TIME);
70 
72 
76  explicit Time(const rcl_time_point_t & time_point);
77 
80  virtual ~Time();
81 
84  operator builtin_interfaces::msg::Time() const;
85 
90  Time &
91  operator=(const Time & rhs);
92 
100  Time &
101  operator=(const builtin_interfaces::msg::Time & time_msg);
102 
107  bool
108  operator==(const rclcpp::Time & rhs) const;
109 
111  bool
112  operator!=(const rclcpp::Time & rhs) const;
113 
118  bool
119  operator<(const rclcpp::Time & rhs) const;
120 
125  bool
126  operator<=(const rclcpp::Time & rhs) const;
127 
132  bool
133  operator>=(const rclcpp::Time & rhs) const;
134 
139  bool
140  operator>(const rclcpp::Time & rhs) const;
141 
146  Time
147  operator+(const rclcpp::Duration & rhs) const;
148 
154  Duration
155  operator-(const rclcpp::Time & rhs) const;
156 
161  Time
162  operator-(const rclcpp::Duration & rhs) const;
163 
168  Time &
169  operator+=(const rclcpp::Duration & rhs);
170 
175  Time &
176  operator-=(const rclcpp::Duration & rhs);
177 
179 
184  nanoseconds() const;
185 
187 
191  static Time
192  max();
193 
195 
202  double
203  seconds() const;
204 
206 
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 
222 Time
223 operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs);
224 
225 } // namespace rclcpp
226 
227 #endif // RCLCPP__TIME_HPP_
rclcpp::Time::get_clock_type
rcl_clock_type_t get_clock_type() const
Get the clock type.
rclcpp::Time::operator>=
bool operator>=(const rclcpp::Time &rhs) const
rclcpp::Time::operator!=
bool operator!=(const rclcpp::Time &rhs) const
rclcpp::Time::operator==
bool operator==(const rclcpp::Time &rhs) const
rcl_clock_type_t
rcl_clock_type_t
time.h
std::chrono::nanoseconds
rclcpp::operator+
Time operator+(const rclcpp::Duration &lhs, const rclcpp::Time &rhs)
rclcpp::Time
Definition: time.hpp:31
rcl_time_point_value_t
rcutils_time_point_value_t rcl_time_point_value_t
rclcpp::Time::~Time
virtual ~Time()
Time destructor.
rclcpp::Time::operator+=
Time & operator+=(const rclcpp::Duration &rhs)
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::Time::nanoseconds
rcl_time_point_value_t nanoseconds() const
Get the nanoseconds since epoch.
RCL_ROS_TIME
RCL_ROS_TIME
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::Time::operator>
bool operator>(const rclcpp::Time &rhs) const
rcl_time_point_t
rclcpp::Time::operator<=
bool operator<=(const rclcpp::Time &rhs) const
RCL_SYSTEM_TIME
RCL_SYSTEM_TIME
rclcpp::Duration
Definition: duration.hpp:26
rclcpp::Time::seconds
double seconds() const
Get the seconds since epoch.
rclcpp::Time::operator-=
Time & operator-=(const rclcpp::Duration &rhs)
rclcpp::Clock
Definition: clock.hpp:53
visibility_control.hpp
rclcpp::Time::operator+
Time operator+(const rclcpp::Duration &rhs) const
rclcpp::Time::operator-
Duration operator-(const rclcpp::Time &rhs) const
rclcpp::Time::operator=
Time & operator=(const Time &rhs)
rclcpp::Time::operator<
bool operator<(const rclcpp::Time &rhs) const
rclcpp::Time::max
static Time max()
Get the maximum representable value.
duration.hpp
rclcpp::Time::Time
Time(int32_t seconds, uint32_t nanoseconds, rcl_clock_type_t clock_type=RCL_SYSTEM_TIME)
Time constructor.