Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65069 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-08-28 04:06:32


Author: viboes
Date: 2010-08-28 04:06:17 EDT (Sat, 28 Aug 2010)
New Revision: 65069
URL: http://svn.boost.org/trac/boost/changeset/65069

Log:
improve error code handling
Text files modified:
   sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp | 7 ++-
   sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp | 11 ++++-
   sandbox/chrono/boost/chrono/stopwatch_reporter.hpp | 80 ++++++++++++++++++++++++++++++----------
   sandbox/chrono/boost/chrono/t24_hours_formatter.hpp | 1
   sandbox/chrono/boost/chrono/time_formatter.hpp | 5 ++
   5 files changed, 79 insertions(+), 25 deletions(-)

Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp 2010-08-28 04:06:17 EDT (Sat, 28 Aug 2010)
@@ -65,11 +65,14 @@
         // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         // be as low as 10, although will be 15 for many common platforms.
         {
+ if (&ec==&system::throws) ec.clear();
+
             typedef typename Stopwatch::accumulator accumulator;
             typedef typename Stopwatch::duration duration_t;
             accumulator& acc = stopwatch_.accumulated();
- duration_t lt= stopwatch_.lifetime();
-
+ duration_t lt= stopwatch_.lifetime(ec);
+ if (ec) return;
+
             //if ( d < duration_t::zero() ) return;
             if ( places > 9 )
                 places = 9; // sanity check

Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp 2010-08-28 04:06:17 EDT (Sat, 28 Aug 2010)
@@ -67,6 +67,8 @@
         // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         // be as low as 10, although will be 15 for many common platforms.
         {
+ if (&ec==&system::throws) ec.clear();
+
             typedef typename Stopwatch::accumulator accumulator;
             typedef typename Stopwatch::duration duration_t;
             accumulator& acc = stopwatch_.accumulated();
@@ -97,25 +99,30 @@
                     case 's':
                         //~ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count();
                         time_formatter::show_time<process_cpu_clock>(accumulators::sum(acc), format2, places, os, ec);
+ if (ec) return;
                         //~ os << accumulators::sum(acc);
                         break;
                     case 'm':
                         //~ os << boost::chrono::duration<double>(duration_t((accumulators::min)(acc))).count();
                         time_formatter::show_time<process_cpu_clock>((accumulators::min)(acc), format2, places, os, ec);
+ if (ec) return;
                         //~ os << (accumulators::min)(acc);
                         break;
                     case 'M':
                         //~ os << boost::chrono::duration<double>(duration_t((accumulators::max)(acc))).count();
                         time_formatter::show_time<process_cpu_clock>((accumulators::max)(acc), format2, places, os, ec);
+ if (ec) return;
                         //~ os << (accumulators::max)(acc);
                         break;
                     case 'a':
- if (accumulators::count(acc)>0)
+ if (accumulators::count(acc)>0) {
                          //? os << boost::chrono::duration<double>(duration_t(typename duration_t::rep(accumulators::mean(acc)))).count()
                                 //~ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count() / accumulators::count(acc)
                             time_formatter::show_time<process_cpu_clock>(accumulators::sum(acc) / accumulators::count(acc), format2, places, os, ec);
- else
+ if (ec) return;
+ } else {
                             os << 0;
+ }
                         break;
                     case 'c':
                         os << accumulators::count(acc);

Modified: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp 2010-08-28 04:06:17 EDT (Sat, 28 Aug 2010)
@@ -10,6 +10,16 @@
 #ifndef BOOST_CHRONO_STOPWATCH_REPORTER_HPP
 #define BOOST_CHRONO_STOPWATCH_REPORTER_HPP
 
+#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_CHRONO_ENABLE_WARNINGS)
+#if defined __GNUC__
+#pragma GCC system_header
+#elif defined __SUNPRO_CC
+#pragma disable_warn
+#elif defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#endif
+
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/stopwatch_scoped.hpp>
 #include <boost/system/error_code.hpp>
@@ -75,43 +85,63 @@
         typedef typename Formatter::char_type char_type;
         typedef typename Formatter::ostream_type ostream_type;
 
- explicit basic_stopwatch_reporter( system::error_code & /*ec*/ = system::throws )
- : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) { }
+ explicit basic_stopwatch_reporter( system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
         explicit basic_stopwatch_reporter( ostream_type & os,
- system::error_code & /*ec*/ = system::throws )
- : m_places(Formatter::default_places()), m_os(os), m_format(Formatter::default_format()), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(os), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         explicit basic_stopwatch_reporter( const string_type & format,
- system::error_code & /*ec*/ = system::throws )
- : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(format), m_reported(false) {}
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         explicit basic_stopwatch_reporter( int places,
- system::error_code & /*ec*/ = system::throws )
- : m_places(places), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         basic_stopwatch_reporter( ostream_type & os, const string_type & format,
- system::error_code & /*ec*/ = system::throws )
- : m_places(Formatter::default_places()), m_os(os), m_format(format), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(os), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         basic_stopwatch_reporter( const string_type & format, int places,
- system::error_code & /*ec*/ = system::throws )
- : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         basic_stopwatch_reporter( ostream_type & os, int places,
- system::error_code & /*ec*/ = system::throws )
- : m_places(places), m_os(os), m_format(Formatter::default_format()), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         basic_stopwatch_reporter( int places, const string_type & format,
- system::error_code & /*ec*/ = system::throws )
- : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         basic_stopwatch_reporter( ostream_type & os, const string_type & format, int places,
- system::error_code & /*ec*/ = system::throws )
- : m_places(places), m_os(os), m_format(format), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         basic_stopwatch_reporter( ostream_type & os, int places, const string_type & format,
- system::error_code & /*ec*/ = system::throws )
- : m_places(places), m_os(os), m_format(format), m_reported(false) { }
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
 
         ~basic_stopwatch_reporter() {// never throws
             system::error_code ec;
@@ -146,6 +176,7 @@
     template <class Stopwatch, class Formatter>
     void basic_stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
         chrono::scoped_suspend<typename Stopwatch::clock> _(ec);
+ if (ec) return;
         if ( m_format.empty() ) m_format = Formatter::default_format();
 
         m_reported = true;
@@ -306,4 +337,13 @@
 
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
+#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_CHRONO_ENABLE_WARNINGS)
+#if defined __SUNPRO_CC
+#pragma enable_warn
+#elif defined _MSC_VER
+#pragma warning(pop)
+#endif
+#endif
+
+
 #endif

Modified: sandbox/chrono/boost/chrono/t24_hours_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/t24_hours_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/t24_hours_formatter.hpp 2010-08-28 04:06:17 EDT (Sat, 28 Aug 2010)
@@ -65,6 +65,7 @@
         {
             typedef typename Stopwatch::duration duration_t;
             duration_t d = stopwatch_.elapsed( ec );
+ if (ec) return;
 
             if ( d < duration_t::zero() ) return;
 

Modified: sandbox/chrono/boost/chrono/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/time_formatter.hpp 2010-08-28 04:06:17 EDT (Sat, 28 Aug 2010)
@@ -65,10 +65,12 @@
         template <class Stopwatch >
         static void show_time( typename Stopwatch::duration::rep const & times
             , const char_type* format, int places, ostream_type & os
- , system::error_code & ec)
+ , system::error_code & ec
+ )
           // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
           // be as low as 10, although will be 15 for many common platforms.
           {
+ if (&ec != &system::throws) ec.clear();
             typedef typename Stopwatch::duration duration;
             typedef typename duration::rep rep;
             if ( times.real < 0 ) return;
@@ -133,6 +135,7 @@
             typedef typename Stopwatch::duration duration;
             typedef typename duration::rep rep;
             duration d = stopwatch_.elapsed( ec );
+ if (ec) return;
             rep times=d.count();
             show_time<Stopwatch>(times, format, places, os, ec);
         }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk