From 18ad26e6543bc1467fec6d053ed4e2b7ca90627c Mon Sep 17 00:00:00 2001 From: Sagnik Basu Date: Tue, 28 Aug 2018 00:14:25 +0530 Subject: [PATCH] Add TIME_MAX and DURATION_MAX functions (#538) * Add TIME_MAX and DURATION_MAX functions * Fix Linting Errors * change funtion name as per coding style * change function name as per coding style * Update duration.cpp * Update time.cpp * Update test_duration.cpp * Update time.hpp * remove extra empty line --- rclcpp/include/rclcpp/duration.hpp | 4 ++++ rclcpp/include/rclcpp/time.hpp | 4 ++++ rclcpp/src/rclcpp/duration.cpp | 6 ++++++ rclcpp/src/rclcpp/time.cpp | 6 ++++++ rclcpp/test/test_duration.cpp | 7 +++++++ 5 files changed, 27 insertions(+) diff --git a/rclcpp/include/rclcpp/duration.hpp b/rclcpp/include/rclcpp/duration.hpp index 11fc2e2..b92ea42 100644 --- a/rclcpp/include/rclcpp/duration.hpp +++ b/rclcpp/include/rclcpp/duration.hpp @@ -89,6 +89,10 @@ public: Duration operator-(const rclcpp::Duration & rhs) const; + RCLCPP_PUBLIC + static Duration + max(); + RCLCPP_PUBLIC Duration operator*(double scale) const; diff --git a/rclcpp/include/rclcpp/time.hpp b/rclcpp/include/rclcpp/time.hpp index e93cb64..c10b6ce 100644 --- a/rclcpp/include/rclcpp/time.hpp +++ b/rclcpp/include/rclcpp/time.hpp @@ -102,6 +102,10 @@ public: rcl_time_point_value_t nanoseconds() const; + RCLCPP_PUBLIC + static Time + max(); + /// \return the seconds since epoch as a floating point number. /// \warning Depending on sizeof(double) there could be significant precision loss. /// When an exact time is required use nanoseconds() instead. diff --git a/rclcpp/src/rclcpp/duration.cpp b/rclcpp/src/rclcpp/duration.cpp index 0455abe..cb84e05 100644 --- a/rclcpp/src/rclcpp/duration.cpp +++ b/rclcpp/src/rclcpp/duration.cpp @@ -214,6 +214,12 @@ Duration::nanoseconds() const return rcl_duration_.nanoseconds; } +Duration +Duration::max() +{ + return Duration(std::numeric_limits::max(), 999999999); +} + double Duration::seconds() const { diff --git a/rclcpp/src/rclcpp/time.cpp b/rclcpp/src/rclcpp/time.cpp index 9ab924a..980b6a5 100644 --- a/rclcpp/src/rclcpp/time.cpp +++ b/rclcpp/src/rclcpp/time.cpp @@ -251,5 +251,11 @@ operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs) return Time(lhs.nanoseconds() + rhs.nanoseconds(), rhs.get_clock_type()); } +Time +Time::max() +{ + return Time(std::numeric_limits::max(), 999999999); +} + } // namespace rclcpp diff --git a/rclcpp/test/test_duration.cpp b/rclcpp/test/test_duration.cpp index a6d099f..7d61c68 100644 --- a/rclcpp/test/test_duration.cpp +++ b/rclcpp/test/test_duration.cpp @@ -120,3 +120,10 @@ TEST(TestDuration, negative_duration) { EXPECT_EQ(expected_value, assignable_duration.nanoseconds()); } } + +TEST(TestDuration, maximum_duration) { + rclcpp::Duration max_duration = rclcpp::Duration::max(); + rclcpp::Duration max(std::numeric_limits::max(), 999999999); + + EXPECT_EQ(max_duration, max); +}