diff options
author | Charles E. Rolke <chug@apache.org> | 2013-04-19 19:31:29 +0000 |
---|---|---|
committer | Charles E. Rolke <chug@apache.org> | 2013-04-19 19:31:29 +0000 |
commit | 4889235edfd1da572a040d0bbdb0924e4303b0f2 (patch) | |
tree | a42cd12509c2ab2a94d12ca7b75a12ad91b46861 | |
parent | 4b59e2ce1f5f7f8e3171e19a04185f3b133a6b38 (diff) | |
download | qpid-python-4889235edfd1da572a040d0bbdb0924e4303b0f2.tar.gz |
QPID-4748: Consistent handling of durations - apply changes to Windows platform
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1470002 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/include/qpid/sys/Time.h | 4 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/sys/windows/Time.cpp | 26 |
2 files changed, 27 insertions, 3 deletions
diff --git a/qpid/cpp/include/qpid/sys/Time.h b/qpid/cpp/include/qpid/sys/Time.h index 8e99356409..2ccff92e7c 100644 --- a/qpid/cpp/include/qpid/sys/Time.h +++ b/qpid/cpp/include/qpid/sys/Time.h @@ -124,8 +124,8 @@ public: inline operator int64_t() const; }; -std::ostream& operator << (std::ostream&, const Duration&); -std::istream& operator >> (std::istream&, Duration&); +QPID_COMMON_EXTERN std::ostream& operator << (std::ostream&, const Duration&); +QPID_COMMON_EXTERN std::istream& operator >> (std::istream&, Duration&); inline AbsTime now() { return AbsTime::now(); } diff --git a/qpid/cpp/src/qpid/sys/windows/Time.cpp b/qpid/cpp/src/qpid/sys/windows/Time.cpp index 700a25391f..a144a2dd5f 100644 --- a/qpid/cpp/src/qpid/sys/windows/Time.cpp +++ b/qpid/cpp/src/qpid/sys/windows/Time.cpp @@ -86,7 +86,31 @@ Duration::Duration(const AbsTime& start, const AbsTime& finish) { } std::ostream& operator<<(std::ostream& o, const Duration& d) { - return o << int64_t(d) << "ns"; + if (d >= TIME_SEC) return o << (double(d)/TIME_SEC) << "s"; + if (d >= TIME_MSEC) return o << (double(d)/TIME_MSEC) << "ms"; + if (d >= TIME_USEC) return o << (double(d)/TIME_USEC) << "us"; + return o << int64_t(d) << "ns"; +} + +std::istream& operator>>(std::istream& i, Duration& d) { + // Don't throw, let the istream throw if it's configured to do so. + double number; + i >> number; + if (i.fail()) return i; + + if (i.eof() || std::isspace(i.peek())) // No suffix + d = number*TIME_SEC; + else { + std::string suffix; + i >> suffix; + if (i.fail()) return i; + if (suffix.compare("s") == 0) d = number*TIME_SEC; + else if (suffix.compare("ms") == 0) d = number*TIME_MSEC; + else if (suffix.compare("us") == 0) d = number*TIME_USEC; + else if (suffix.compare("ns") == 0) d = number*TIME_NSEC; + else i.setstate(std::ios::failbit); + } + return i; } std::ostream& operator<<(std::ostream& o, const AbsTime& t) { |