Utils: Formating helpers (senf::format::eng, senf::format::dumpint)
[senf.git] / senf / Utils / Statistics.cc
index 7506e07..730898d 100644 (file)
@@ -30,6 +30,7 @@
 #include <cmath>
 #include <sstream>
 #include <senf/Utils/Console/Console.hh>
+#include <senf/Utils/Format.hh>
 #include "StatisticsTargets.hh"
 
 //#include "Statistics.mpp"
@@ -82,63 +83,25 @@ senf::StatisticsBase::output(unsigned n)
     return OutputProxy<StatisticsBase>(this, &(i->second));
 }
 
-//
-// generate an engineering style notation 
-//
-std::string format_eng( float f)
-{
-    char buf[16];
-    if (f > 0) {
-        int n = 0;
-        while( f >= 1000.0f) {
-                f /= 1000.0f;
-                n+=3;
-        }
-
-        if( n >=3)
-            sprintf( buf, " %3.2fe%+03d", f, n);
-        else
-            sprintf( buf, "      %3.2f", f);
-    }
-    else if (f < 0) {
-        int n = 0;
-        while( f <= -1000.0f) {
-                f *= 1000.0f;
-                n+=3;
-        }
-        if( n >=3)
-            sprintf( buf, " %3.2fe%+03d", f, n);
-        else
-            sprintf( buf, "      %3.2f", f);
-    }
-    else{
-        sprintf( buf, "        0.00");
-    }
-
-    return buf;
-}
-
-
 prefix_ void senf::StatisticsBase::consoleList(unsigned level, std::ostream & os)
     const
 {
-    os << boost::format("%s%-5d%|15t|  %12s  %12s   %12s  %12s\n") 
+    os << boost::format("%s%-5d%|15t|  %12s  %19.5g  %12s\n") 
         % std::string(2*level,' ') 
         % rank() 
-        % format_eng(min()) 
-        % format_eng(avg()) 
-        % format_eng(dev())
-        % format_eng(max());
+        % boost::io::group(std::setw(1),senf::format::eng(min()))
+        % boost::io::group(std::setw(1),senf::format::eng(avg(),dev()))
+        % boost::io::group(std::setw(1),senf::format::eng(max()));
     {
         OutputMap::const_iterator i (outputs_.begin());
         OutputMap::const_iterator i_end (outputs_.end());
         for (; i != i_end; ++i)
-            os << boost::format("            %3d  %12s  %12s   %12s  %12s\n")
+            os << boost::format("            %3d  %12s  %19.5g  %12s\n")
                 % i->second.n 
-                % format_eng(i->second.min/i->second.n) 
-                % format_eng(i->second.avg/i->second.n)
-                % format_eng(i->second.dev/i->second.n)
-                % format_eng(i->second.max/i->second.n);
+                % boost::io::group(std::setw(1),senf::format::eng(i->second.min/i->second.n))
+                % boost::io::group(std::setw(1),senf::format::eng(i->second.avg/i->second.n,
+                                                                  i->second.dev/i->second.n))
+                % boost::io::group(std::setw(1),senf::format::eng(i->second.max/i->second.n));
     }
     {
         Children::const_iterator i (children_.begin());
@@ -245,7 +208,7 @@ prefix_ senf::Statistics::Statistics()
 
 prefix_ void senf::Statistics::consoleList(std::ostream & os)
 {
-    os << "RANK        WIN           MIN           AVG            DEV           MAX\n";
+    os << "RANK        WIN           MIN                  AVG           MAX\n";
     StatisticsBase::consoleList(0, os);
 }