From 0c0b3c2a3a97342a0a7cc3749fe39e0dd6bededd Mon Sep 17 00:00:00 2001 From: Foaly Date: Wed, 17 Jul 2013 12:24:24 +0200 Subject: [PATCH] Modulo operators for sf::Time (fixes #429) --- include/SFML/System/Time.hpp | 26 +++++++++++++++++++++++++- src/SFML/System/Time.cpp | 12 ++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index 5037f52c9..9d3814860 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -82,7 +82,7 @@ public : //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// - static const Time Zero; ///< Predefined "zero" time value + static const Time Zero; ///< Predefined "zero" time value private : @@ -399,6 +399,30 @@ SFML_SYSTEM_API Time& operator /=(Time& left, float right); //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time& operator /=(Time& left, Int64 right); +//////////////////////////////////////////////////////////// +/// \relates Time +/// \brief Overload of binary % operator to compute remainder of a time value +/// +/// \param left Left operand (a time) +/// \param right Right operand (a time) +/// +/// \return \a left modulo \a right +/// +//////////////////////////////////////////////////////////// +SFML_SYSTEM_API Time operator %(Time left, Time right); + +//////////////////////////////////////////////////////////// +/// \relates Time +/// \brief Overload of binary %= operator to compute/assign remainder of a time value +/// +/// \param left Left operand (a time) +/// \param right Right operand (a time) +/// +/// \return \a left modulo \a right +/// +//////////////////////////////////////////////////////////// +SFML_SYSTEM_API Time& operator %=(Time& left, Time right); + } // namespace sf diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp index 69fd78ef1..3f5faccee 100644 --- a/src/SFML/System/Time.cpp +++ b/src/SFML/System/Time.cpp @@ -236,4 +236,16 @@ Time& operator /=(Time& left, Int64 right) return left = left / right; } +//////////////////////////////////////////////////////////// +Time operator %(Time left, Time right) +{ + return microseconds(left.asMicroseconds() % right.asMicroseconds()); +} + +//////////////////////////////////////////////////////////// +Time& operator %=(Time& left, Time right) +{ + return left = left % right; +} + } // namespace sf