Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A044BFDE3 for ; Fri, 19 Apr 2013 19:31:53 +0000 (UTC) Received: (qmail 6104 invoked by uid 500); 19 Apr 2013 19:31:53 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 6082 invoked by uid 500); 19 Apr 2013 19:31:53 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 6069 invoked by uid 99); 19 Apr 2013 19:31:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Apr 2013 19:31:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Apr 2013 19:31:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A941D2388ACC; Fri, 19 Apr 2013 19:31:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@qpid.apache.org From: chug@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130419193129.A941D2388ACC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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