qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1470002 - in /qpid/trunk/qpid/cpp: include/qpid/sys/Time.h src/qpid/sys/windows/Time.cpp
Date Fri, 19 Apr 2013 19:31:29 GMT
Author: chug
Date: Fri Apr 19 19:31:29 2013
New Revision: 1470002

URL: http://svn.apache.org/r1470002
Log:
QPID-4748: Consistent handling of durations - apply changes to Windows platform

Modified:
    qpid/trunk/qpid/cpp/include/qpid/sys/Time.h
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp

Modified: qpid/trunk/qpid/cpp/include/qpid/sys/Time.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/sys/Time.h?rev=1470002&r1=1470001&r2=1470002&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/sys/Time.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/sys/Time.h Fri Apr 19 19:31:29 2013
@@ -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(); }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp?rev=1470002&r1=1470001&r2=1470002&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp Fri Apr 19 19:31:29 2013
@@ -86,7 +86,31 @@ Duration::Duration(const AbsTime& start,
 }
 
 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) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message