$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r74488 - trunk/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2011-09-21 13:00:43
Author: viboes
Date: 2011-09-21 13:00:43 EDT (Wed, 21 Sep 2011)
New Revision: 74488
URL: http://svn.boost.org/trac/boost/changeset/74488
Log:
Chrono: refactor process_cpu_clock_times into a template class so we can cast changingthe representation
Text files modified: 
   trunk/boost/chrono/process_cpu_clocks.hpp |   232 ++++++++++++++++++++++++++------------- 
   1 files changed, 152 insertions(+), 80 deletions(-)
Modified: trunk/boost/chrono/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/process_cpu_clocks.hpp	(original)
+++ trunk/boost/chrono/process_cpu_clocks.hpp	2011-09-21 13:00:43 EDT (Wed, 21 Sep 2011)
@@ -20,6 +20,7 @@
 #include <boost/operators.hpp>
 #include <boost/chrono/detail/system.hpp>
 #include <iostream>
+#include <boost/type_traits/common_type.hpp>
 
 
 #ifndef BOOST_CHRONO_HEADER_ONLY
@@ -64,89 +65,99 @@
         static BOOST_CHRONO_INLINE time_point now(system::error_code & ec );
     };
 
-        struct process_cpu_clock_times 
-            : arithmetic<process_cpu_clock_times, 
-            multiplicative<process_cpu_clock_times, process_real_cpu_clock::rep, 
-            less_than_comparable<process_cpu_clock_times> > >
+        template <typename Rep>
+        struct process_times
+            : arithmetic<process_times<Rep>,
+            multiplicative<process_times<Rep>, Rep,
+            less_than_comparable<process_times<Rep> > > >
         {
-            typedef process_real_cpu_clock::rep rep;
-            process_cpu_clock_times()
+              //typedef process_real_cpu_clock::rep rep;
+              typedef Rep rep;
+            process_times()
                 : real(0)
                 , user(0)
                 , system(0){}
-            explicit process_cpu_clock_times(
-                process_real_cpu_clock::rep r)
+            template <typename Rep2>
+            explicit process_times(
+                Rep2 r)
                 : real(r)
-                , user(0)
-                , system(0){}
-            process_cpu_clock_times(
-                process_real_cpu_clock::rep r,
-                process_user_cpu_clock::rep   u,
-                process_system_cpu_clock::rep s)
+                , user(r)
+                , system(r){}
+            template <typename Rep2>
+            explicit process_times(
+                process_times<Rep2> const& rhs)
+                : real(rhs.real)
+                , user(rhs.user)
+                , system(rhs.system){}
+            process_times(
+                rep r,
+                rep u,
+                rep s)
                 : real(r)
                 , user(u)
                 , system(s){}
 
-            process_real_cpu_clock::rep   real;    // real (i.e wall clock) time
-            process_user_cpu_clock::rep   user;    // user cpu time
-            process_system_cpu_clock::rep system;  // system cpu time
-
-            operator process_real_cpu_clock::rep()
-            {
-              return real;
-            }
-            bool operator==(process_cpu_clock_times const& rhs) {
+            rep   real;    // real (i.e wall clock) time
+            rep   user;    // user cpu time
+            rep system;  // system cpu time
+
+            //            operator rep()
+            //{
+            //  return real;
+            //}
+            template <typename Rep2>
+            bool operator==(process_times<Rep2> const& rhs) {
                 return (real==rhs.real &&
                         user==rhs.user &&
                         system==rhs.system);
             }
 
-            process_cpu_clock_times operator+=(
-                    process_cpu_clock_times const& rhs) 
+            process_times& operator+=(
+                process_times const& rhs)
             {
                 real+=rhs.real;
                 user+=rhs.user;
                 system+=rhs.system;
                 return *this;
             }
-            process_cpu_clock_times operator-=(
-                    process_cpu_clock_times const& rhs) 
+            process_times& operator-=(
+                process_times const& rhs)
             {
                 real-=rhs.real;
                 user-=rhs.user;
                 system-=rhs.system;
                 return *this;
             }
-            process_cpu_clock_times operator*=(
-                    process_cpu_clock_times const& rhs) 
+            process_times& operator*=(
+                process_times const& rhs)
             {
                 real*=rhs.real;
                 user*=rhs.user;
                 system*=rhs.system;
                 return *this;
             }
-            process_cpu_clock_times operator*=(rep const& rhs) 
+            process_times& operator*=(rep const& rhs)
             {
                 real*=rhs;
                 user*=rhs;
                 system*=rhs;
                 return *this;
             }
-            process_cpu_clock_times operator/=(process_cpu_clock_times const& rhs) 
+            process_times& operator/=(process_times const& rhs)
             {
                 real/=rhs.real;
                 user/=rhs.user;
                 system/=rhs.system;
                 return *this;
             }
-            process_cpu_clock_times operator/=(rep const& rhs) 
+            process_times& operator/=(rep const& rhs)
             {
                 real/=rhs;
                 user/=rhs;
                 system/=rhs;
                 return *this;
             }
-            bool operator<(process_cpu_clock_times const & rhs) const 
+            bool operator<(process_times const & rhs) const
             {
                 if (real < rhs.real) return true;
                 if (real > rhs.real) return false;
@@ -181,7 +192,71 @@
                 }
             }
         };
+}
+template <class Rep1, class Rep2>
+struct common_type<
+  chrono::process_times<Rep1>,
+  chrono::process_times<Rep2>
+>
+{
+  typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
+};
+
+template <class Rep1, class Rep2>
+struct common_type<
+  chrono::process_times<Rep1>,
+  Rep2
+>
+{
+  typedef chrono::process_times<typename common_type<Rep1, Rep2>::type> type;
+};
+
+
+namespace chrono
+{
+  template <class Rep1, class Period1, class Rep2, class Period2>
+  inline BOOST_CHRONO_CONSTEXPR
+  bool
+  operator==(const duration<process_times<Rep1>, Period1>& lhs,
+        const duration<Rep2, Period2>& rhs)
+  {
+      return boost::chrono::detail::duration_eq<
+          duration<Rep1, Period1>, duration<Rep2, Period2> >()(duration<Rep1, Period1>(lhs.count().real), rhs);
+  }
+
+  template <class Rep1, class Period1, class Rep2, class Period2>
+  inline BOOST_CHRONO_CONSTEXPR
+  bool
+  operator==(const duration<Rep1, Period1>& lhs,
+        const duration<process_times<Rep2>, Period2>& rhs)
+  {
+      return rhs == lhs;
+  }
+
+
+  // Duration <
+
+  template <class Rep1, class Period1, class Rep2, class Period2>
+  inline BOOST_CHRONO_CONSTEXPR
+  bool
+  operator< (const duration<process_times<Rep1>, Period1>& lhs,
+        const duration<Rep2, Period2>& rhs)
+  {
+      return boost::chrono::detail::duration_lt<
+        duration<Rep1, Period1>, duration<Rep2, Period2> >()(duration<Rep1, Period1>(lhs.count().real), rhs);
+  }
+
+  template <class Rep1, class Period1, class Rep2, class Period2>
+  inline BOOST_CHRONO_CONSTEXPR
+  bool
+  operator< (const duration<Rep1, Period1>& lhs,
+        const duration<process_times<Rep2>, Period2>& rhs)
+  {
+    return rhs < lhs;
+  }
+
 
+  typedef process_times<nanoseconds::rep> process_cpu_clock_times;
     class BOOST_CHRONO_DECL process_cpu_clock
     {
     public:
@@ -198,44 +273,44 @@
                     system::error_code & ec );
     };
 
-    template <class CharT, class Traits>
+    template <class CharT, class Traits, typename Rep>
     std::basic_ostream<CharT, Traits>& 
     operator<<(std::basic_ostream<CharT, Traits>& os, 
-            process_cpu_clock_times const& rhs) 
+        process_times<Rep> const& rhs)
     {
         rhs.print(os);
         return os;
     }
 
-    template <class CharT, class Traits>
+    template <class CharT, class Traits, typename Rep>
     std::basic_istream<CharT, Traits>& 
     operator>>(std::basic_istream<CharT, Traits>& is, 
-            process_cpu_clock_times const& rhs) 
+        process_times<Rep> const& rhs)
     {
         rhs.read(is);
         return is;
     }
 
-    template <>
-    struct duration_values<process_cpu_clock_times>
+    template <typename Rep>
+    struct duration_values<process_times<Rep> >
     {
-        typedef process_cpu_clock_times Rep;
+        typedef process_times<Rep> Res;
     public:
-        static Rep zero() 
+        static Res zero()
         {
-            return Rep();
+            return Res();
         }
-        static Rep max BOOST_PREVENT_MACRO_SUBSTITUTION ()  
+        static Res max BOOST_PREVENT_MACRO_SUBSTITUTION ()
         {
-          return Rep((std::numeric_limits<process_real_cpu_clock::rep>::max)(),
-                      (std::numeric_limits<process_user_cpu_clock::rep>::max)(),
-                      (std::numeric_limits<process_system_cpu_clock::rep>::max)());
+          return Res((std::numeric_limits<Rep>::max)(),
+                      (std::numeric_limits<Rep>::max)(),
+                      (std::numeric_limits<Rep>::max)());
         }
-        static Rep min BOOST_PREVENT_MACRO_SUBSTITUTION ()  
+        static Res min BOOST_PREVENT_MACRO_SUBSTITUTION ()
         {
-          return Rep((std::numeric_limits<process_real_cpu_clock::rep>::min)(),
-                      (std::numeric_limits<process_user_cpu_clock::rep>::min)(),
-                      (std::numeric_limits<process_system_cpu_clock::rep>::min)());
+          return Res((std::numeric_limits<Rep>::min)(),
+                      (std::numeric_limits<Rep>::min)(),
+                      (std::numeric_limits<Rep>::min)());
         }
     };
 
@@ -244,44 +319,41 @@
 
 namespace std {
 
-    template <>
-    class numeric_limits<boost::chrono::process_cpu_clock::times>
+    template <typename Rep>
+    struct numeric_limits<boost::chrono::process_times<Rep> >
     {
-        typedef boost::chrono::process_cpu_clock::times Rep;
+        typedef boost::chrono::process_times<Rep> Res;
 
         public:
         static const bool is_specialized = true;
-        static Rep min BOOST_PREVENT_MACRO_SUBSTITUTION ()  
+        static Res min BOOST_PREVENT_MACRO_SUBSTITUTION ()
         {
-          return Rep((std::numeric_limits<boost::chrono::process_real_cpu_clock::rep>::min)(),
-                      (std::numeric_limits<boost::chrono::process_user_cpu_clock::rep>::min)(),
-                      (std::numeric_limits<boost::chrono::process_system_cpu_clock::rep>::min)());
+          return Res((std::numeric_limits<Rep>::min)(),
+                      (std::numeric_limits<Rep>::min)(),
+                      (std::numeric_limits<Rep>::min)());
         }
-        static Rep max BOOST_PREVENT_MACRO_SUBSTITUTION ()  
+        static Res max BOOST_PREVENT_MACRO_SUBSTITUTION ()
         {
-          return Rep((std::numeric_limits<boost::chrono::process_real_cpu_clock::rep>::max)(),
-                      (std::numeric_limits<boost::chrono::process_user_cpu_clock::rep>::max)(),
-                      (std::numeric_limits<boost::chrono::process_system_cpu_clock::rep>::max)());
+          return Res((std::numeric_limits<Rep>::max)(),
+                      (std::numeric_limits<Rep>::max)(),
+                      (std::numeric_limits<Rep>::max)());
         }
-        static Rep lowest() throw() 
+        static Res lowest() throw()
         { 
             return (min)(); 
         }
-        static const int digits = std::numeric_limits<boost::chrono::process_real_cpu_clock::rep>::digits+
-                        std::numeric_limits<boost::chrono::process_user_cpu_clock::rep>::digits+
-                        std::numeric_limits<boost::chrono::process_system_cpu_clock::rep>::digits;
-        static const int digits10 = std::numeric_limits<boost::chrono::process_real_cpu_clock::rep>::digits10+
-                        std::numeric_limits<boost::chrono::process_user_cpu_clock::rep>::digits10+
-                        std::numeric_limits<boost::chrono::process_system_cpu_clock::rep>::digits10;
-        //~ static const int max_digits10 = std::numeric_limits<boost::chrono::process_real_cpu_clock::rep>::max_digits10+
-                        //~ std::numeric_limits<boost::chrono::process_user_cpu_clock::rep>::max_digits10+
-                        //~ std::numeric_limits<boost::chrono::process_system_cpu_clock::rep>::max_digits10;
-        static const bool is_signed = false;
-        static const bool is_integer = true;
-        static const bool is_exact = true;
+        static const int digits = std::numeric_limits<Rep>::digits+
+                        std::numeric_limits<Rep>::digits+
+                        std::numeric_limits<Rep>::digits;
+        static const int digits10 = std::numeric_limits<Rep>::digits10+
+                        std::numeric_limits<Rep>::digits10+
+                        std::numeric_limits<Rep>::digits10;
+        static const bool is_signed = Rep::is_signed;
+        static const bool is_integer = Rep::is_integer;
+        static const bool is_exact = Rep::is_exact;
         static const int radix = 0;
-        //~ static Rep epsilon() throw() { return 0; }
-        //~ static Rep round_error() throw() { return 0; }
+        //~ static Res epsilon() throw() { return 0; }
+        //~ static Res round_error() throw() { return 0; }
         //~ static const int min_exponent = 0;
         //~ static const int min_exponent10 = 0;
         //~ static const int max_exponent = 0;
@@ -291,10 +363,10 @@
         //~ static const bool has_signaling_NaN = false;
         //~ static const float_denorm_style has_denorm = denorm_absent;
         //~ static const bool has_denorm_loss = false;
-        //~ static Rep infinity() throw() { return 0; }
-        //~ static Rep quiet_NaN() throw() { return 0; }
-        //~ static Rep signaling_NaN() throw() { return 0; }
-        //~ static Rep denorm_min() throw() { return 0; }
+        //~ static Res infinity() throw() { return 0; }
+        //~ static Res quiet_NaN() throw() { return 0; }
+        //~ static Res signaling_NaN() throw() { return 0; }
+        //~ static Res denorm_min() throw() { return 0; }
         //~ static const bool is_iec559 = false;
         //~ static const bool is_bounded = true;
         //~ static const bool is_modulo = false;