susumu.yata
null+****@clear*****
Thu Dec 6 12:55:57 JST 2012
susumu.yata 2012-12-06 12:55:57 +0900 (Thu, 06 Dec 2012) New Revision: ab521bb08e6ad09a1a6e1b63d3b5e60528e10d18 https://github.com/groonga/grnxx/commit/ab521bb08e6ad09a1a6e1b63d3b5e60528e10d18 Log: Add min/max() to grnxx::Time and grnxx::Duration. Modified files: lib/duration.hpp lib/time.hpp test/test_duration.cpp test/test_time.cpp Modified: lib/duration.hpp (+9 -0) =================================================================== --- lib/duration.hpp 2012-12-06 10:59:14 +0900 (1b72c98) +++ lib/duration.hpp 2012-12-06 12:55:57 +0900 (c88f03d) @@ -63,6 +63,15 @@ class Duration { StringBuilder &write_to(StringBuilder &builder) const; + static constexpr Duration max() { + // TODO: This should use std::numeric_limits<T>::max(). + return Duration(static_cast<int64_t>((uint64_t(1) << 63) - 1)); + } + static constexpr Duration min() { + // TODO: This should use std::numeric_limits<T>::min(). + return Duration(static_cast<int64_t>(uint64_t(1) << 63)); + } + private: int64_t nanoseconds_; Modified: lib/time.hpp (+9 -0) =================================================================== --- lib/time.hpp 2012-12-06 10:59:14 +0900 (f5c007e) +++ lib/time.hpp 2012-12-06 12:55:57 +0900 (ca25bfe) @@ -40,6 +40,15 @@ class Time { StringBuilder &write_to(StringBuilder &builder) const; + static constexpr Time max() { + // TODO: This should use std::numeric_limits<T>::max(). + return Time(static_cast<int64_t>((uint64_t(1) << 63) - 1)); + } + static constexpr Time min() { + // TODO: This should use std::numeric_limits<T>::min(). + return Time(static_cast<int64_t>(uint64_t(1) << 63)); + } + private: int64_t nanoseconds_; Modified: test/test_duration.cpp (+5 -0) =================================================================== --- test/test_duration.cpp 2012-12-06 10:59:14 +0900 (4cb437a) +++ test/test_duration.cpp 2012-12-06 12:55:57 +0900 (fe8db77) @@ -26,6 +26,11 @@ int main() { grnxx::LOGGER_ENABLE_COUT); grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER); + assert(grnxx::Duration::max().nanoseconds() == + std::numeric_limits<std::int64_t>::max()); + assert(grnxx::Duration::min().nanoseconds() == + std::numeric_limits<std::int64_t>::min()); + assert(grnxx::Duration(123).nanoseconds() == 123); assert(grnxx::Duration::nanoseconds(123).nanoseconds() == 123); Modified: test/test_time.cpp (+5 -0) =================================================================== --- test/test_time.cpp 2012-12-06 10:59:14 +0900 (d415dcf) +++ test/test_time.cpp 2012-12-06 12:55:57 +0900 (8a5d013) @@ -25,6 +25,11 @@ int main() { grnxx::LOGGER_ENABLE_COUT); grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER); + assert(grnxx::Time::max().nanoseconds() == + std::numeric_limits<std::int64_t>::max()); + assert(grnxx::Time::min().nanoseconds() == + std::numeric_limits<std::int64_t>::min()); + grnxx::Time time = grnxx::Time::now(); GRNXX_NOTICE() << "grnxx::Time::now: " << time; -------------- next part -------------- HTML����������������������������...Download