$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r49813 - in sandbox/chrono/libs/chrono: src test
From: bdawes_at_[hidden]
Date: 2008-11-16 21:38:44
Author: bemandawes
Date: 2008-11-16 21:38:43 EST (Sun, 16 Nov 2008)
New Revision: 49813
URL: http://svn.boost.org/trac/boost/changeset/49813
Log:
Chrono: floating point display now working
Text files modified: 
   sandbox/chrono/libs/chrono/src/run_timer.cpp       |    50 ++++++++--------------------------------
   sandbox/chrono/libs/chrono/test/run_timer_test.cpp |    25 ++++++++++---------                     
   2 files changed, 23 insertions(+), 52 deletions(-)
Modified: sandbox/chrono/libs/chrono/src/run_timer.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/src/run_timer.cpp	(original)
+++ sandbox/chrono/libs/chrono/src/run_timer.cpp	2008-11-16 21:38:43 EST (Sun, 16 Nov 2008)
@@ -47,30 +47,10 @@
 //  }
 //# endif
 
-  const long long scale[10] = { 1000000000LL, 100000000LL, 10000000LL,
-     1000000LL, 100000LL, 10000LL, 1000LL, 100LL, 10LL, 1LL };
-
-  void fixed_point_nano( std::ostream & os, long long value, int places )
-  {
-    if ( places > 0 )
-    {
-      os << value / 1000000000LL
-         << '.';  // TODO: get appropriate char from locale
-      os.width( places );
-      value %= 1000000000LL;
-      value /= scale[places]; 
-      os << value;
-    }
-    else
-    {
-      os << value; 
-    }
-  }
-
   void show_time( const boost::chrono::process_times & times,
                   const char * format, int places, std::ostream & os )
-  ////  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.
+  //  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 ( times.real < nanoseconds(0) ) return;
     if ( places > 9 )
@@ -78,15 +58,10 @@
     else if ( places < 0 )
       places = 0;
 
-    //boost::io::ios_flags_saver ifs( os );
-    //boost::io::ios_precision_saver ips( os );
-    //os.setf( std::ios_base::fixed, std::ios_base::floatfield );
-    //os.precision( places );
-
-    boost::io::ios_flags_saver ifkgs( os );
-    os.setf(std::ios_base::right, std::ios_base::adjustfield);
-    boost::io::ios_fill_saver ifils( os );
-    os.fill( '0' );
+    boost::io::ios_flags_saver ifs( os );
+    os.setf( std::ios_base::fixed, std::ios_base::floatfield );
+    boost::io::ios_precision_saver ips( os );
+    os.precision( places );
 
     nanoseconds total = times.system + times.user;
 
@@ -100,25 +75,20 @@
         switch ( *format )
         {
         case 'r':
-          //os << duration<double>(times.real).count();
-          fixed_point_nano( os, times.real.count(), places );
+          os << duration<double>(times.real).count();
           break;
         case 'u':
-          //os << duration<double>(times.user).count();
-          fixed_point_nano( os, times.user.count(), places );
+          os << duration<double>(times.user).count();
           break;
         case 's':
-          //os << duration<double>(times.system).count();
-          fixed_point_nano( os, times.system.count(), places );
+          os << duration<double>(times.system).count();
           break;
         case 'c':
-          //os << duration<double>(total).count();
-          fixed_point_nano( os, total.count(), places );
+          os << duration<double>(total).count();
           break;
         case 'p':
           {
             boost::io::ios_precision_saver ips( os );
-            os.setf( std::ios_base::fixed, std::ios_base::floatfield );
             os.precision( 1 );
             if ( times.real.count() && total.count() )
               os << duration<double>(total).count()
Modified: sandbox/chrono/libs/chrono/test/run_timer_test.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/run_timer_test.cpp	(original)
+++ sandbox/chrono/libs/chrono/test/run_timer_test.cpp	2008-11-16 21:38:43 EST (Sun, 16 Nov 2008)
@@ -24,7 +24,7 @@
     // exercise each supported combination of constructor arguments
 
     std::ostream &             os   = std::cout;
-    int                        pl   = 6;
+    const int                  pl   = 9;
     boost::system::error_code  ec;
 
     run_timer t1;
@@ -39,28 +39,29 @@
     run_timer t10( os, "t10, default places,  r %r, c %c, p %p, u %u, s %s\n" );
     run_timer t11( "t11, default places,  r %r, c %c, p %p, u %u, s %s\n", ec );
     run_timer t12( os, "t12, default places,  r %r, c %c, p %p, u %u, s %s\n", ec );
-    run_timer t13( pl, "t13, 6 places,  r %r, c %c, p %p, u %u, s %s\n" );
-    run_timer t14( "t14, 6 places,  r %r, c %c, p %p, u %u, s %s\n", pl );
-    run_timer t15( os, pl, "t15, 6 places,  r %r, c %c, p %p, u %u, s %s\n" );
-    run_timer t16( os, "t16, 6 places,  r %r, c %c, p %p, u %u, s %s\n", pl );
-    run_timer t17( pl, "t17, 6 places,  r %r, c %c, p %p, u %u, s %s\n", ec );
-    run_timer t18( "t18, 6 places,  r %r, c %c, p %p, u %u, s %s\n", pl, ec );
-    run_timer t19( os, pl, "t19, 6 places,  r %r, c %c, p %p, u %u, s %s\n", ec );
-    run_timer t20( os, "t20, 6 places,  r %r, c %c, p %p, u %u, s %s\n", pl, ec );
+    run_timer t13( pl, "t13, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n" );
+    run_timer t14( "t14, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n", pl );
+    run_timer t15( os, pl, "t15, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n" );
+    run_timer t16( os, "t16, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n", pl );
+    run_timer t17( pl, "t17, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n", ec );
+    run_timer t18( "t18, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n", pl, ec );
+    run_timer t19( os, pl, "t19, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n", ec );
+    run_timer t20( os, "t20, explicitly code places,  r %r, c %c, p %p, u %u, s %s\n", pl, ec );
 
     std::cout << "Burn some time so run_timers have something to report...";
     boost::chrono::timer<boost::chrono::high_resolution_clock> t;
     while ( t.elapsed() < boost::chrono::seconds(1) ) {}
     std::cout << "\n";
-    std::cout << "default places is " << run_timer::default_places() << "\n";
+    std::cout << run_timer::default_places() << " default places\n";
+    std::cout << pl << " explicitly coded places\n";
 
   }
 }
 
 int main( int argc, char * argv[] )
 {
-  //std::locale loc( "" );
-  //std::cout.imbue( loc );
+  std::locale loc( "" );     // test with appropriate locale
+  std::cout.imbue( loc );
 
   run_timer_constructor_overload_test();