diff options
author | Marc Laukien <marc@zeroc.com> | 2004-11-03 13:35:36 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-11-03 13:35:36 +0000 |
commit | ffe3e8cee236c66d8092a17fd933b3d18a265f9c (patch) | |
tree | 668335c3a068671edb64eb7d2348eb9c7b214f84 | |
parent | make depend. (diff) | |
download | ice-ffe3e8cee236c66d8092a17fd933b3d18a265f9c.tar.bz2 ice-ffe3e8cee236c66d8092a17fd933b3d18a265f9c.tar.xz ice-ffe3e8cee236c66d8092a17fd933b3d18a265f9c.zip |
time changes
-rw-r--r-- | cpp/include/IceUtil/Time.h | 74 | ||||
-rw-r--r-- | cpp/src/IceUtil/Time.cpp | 18 |
2 files changed, 64 insertions, 28 deletions
diff --git a/cpp/include/IceUtil/Time.h b/cpp/include/IceUtil/Time.h index e69c99c5404..bff307bd12c 100644 --- a/cpp/include/IceUtil/Time.h +++ b/cpp/include/IceUtil/Time.h @@ -36,6 +36,10 @@ public: Int64 toMilliSeconds() const; Int64 toMicroSeconds() const; + double toSecondsDouble() const; + double toMilliSecondsDouble() const; + double toMicroSecondsDouble() const; + std::string toString() const; Time operator-() const // Inlined for performance reasons. @@ -95,20 +99,58 @@ public: return _usec != rhs._usec; } - template<typename T> - Time& operator*=(T rhs) + template<typename T> Time& operator*=(T rhs) { _usec *= rhs; return *this; } - template<typename T> - Time& operator/=(T rhs) + Time& operator*=(const Time& rhs) + { + _usec *= rhs._usec; + return *this; + } + + template<typename T> Time operator*(T rhs) const + { + Time t; + t._usec = _usec * rhs; + return t; + } + + Time operator*(const Time& rhs) const + { + Time t; + t._usec = _usec * rhs._usec; + return t; + } + + template<typename T> Time& operator/=(T rhs) { _usec /= rhs; return *this; } + Time& operator/=(const Time& rhs) + { + _usec /= rhs._usec; + return *this; + } + + template<typename T> Time operator/(T rhs) const + { + Time t; + t._usec = _usec / rhs; + return t; + } + + Time operator/(const Time& rhs) const + { + Time t; + t._usec = _usec / rhs._usec; + return t; + } + private: Time(Int64); @@ -116,30 +158,6 @@ private: Int64 _usec; }; -template<typename T> -Time operator*(const Time& lhs, T rhs) -{ - return Time::microSeconds(static_cast<Int64>(lhs.toMicroSeconds() * rhs)); -} - -template<typename T> -Time operator*(T rhs, const Time& lhs) -{ - return Time::microSeconds(static_cast<Int64>(lhs * rhs.toMicroSeconds())); -} - -template<typename T> -Time operator/(const Time& lhs, T rhs) -{ - return Time::microSeconds(static_cast<Int64>(lhs.toMicroSeconds() / rhs)); -} - -template<typename T> -T operator/(T lhs, const Time& rhs) -{ - return lhs * 1000000 / static_cast<T>(rhs.toMicroSeconds()); -} - ICE_UTIL_API std::ostream& operator<<(std::ostream&, const Time&); } // End namespace IceUtil diff --git a/cpp/src/IceUtil/Time.cpp b/cpp/src/IceUtil/Time.cpp index 718ae15beae..ea6840d0d82 100644 --- a/cpp/src/IceUtil/Time.cpp +++ b/cpp/src/IceUtil/Time.cpp @@ -81,6 +81,24 @@ IceUtil::Time::toMicroSeconds() const return _usec; } +double +IceUtil::Time::toSecondsDouble() const +{ + return _usec / 1000000.0; +} + +double +IceUtil::Time::toMilliSecondsDouble() const +{ + return _usec / 1000.0; +} + +double +IceUtil::Time::toMicroSecondsDouble() const +{ + return static_cast<double>(_usec); +} + std::string IceUtil::Time::toString() const { |