|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58964 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-01-13 06:03:52
Author: viboes
Date: 2010-01-13 06:03:51 EST (Wed, 13 Jan 2010)
New Revision: 58964
URL: http://svn.boost.org/trac/boost/changeset/58964
Log:
Boost.Chrono: Version 0.3.0,
* Added free operator%
* Added digital_time class hh::mm::ss
* renamed cpu_clocks to process_cpu_clocks
Added:
sandbox/chrono/boost/chrono/digital_time.hpp (contents, props changed)
sandbox/chrono/boost/chrono/digital_time_formatter.hpp (contents, props changed)
sandbox/chrono/boost/chrono/process_cpu_clocks.hpp (contents, props changed)
Removed:
sandbox/chrono/boost/chrono/cpu_clocks.hpp
Text files modified:
sandbox/chrono/boost/chrono/chrono.hpp | 61 +++++++++++++++++++++++++++++++++++++--
1 files changed, 57 insertions(+), 4 deletions(-)
Modified: sandbox/chrono/boost/chrono/chrono.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/chrono.hpp (original)
+++ sandbox/chrono/boost/chrono/chrono.hpp 2010-01-13 06:03:51 EST (Wed, 13 Jan 2010)
@@ -169,6 +169,38 @@
: duration_divide_imp<duration<Rep1, Period>, Rep2>
{
};
+
+///
+ template <class Duration, class Rep, bool = is_duration<Rep>::value>
+ struct duration_modulo_result
+ {
+ };
+
+ template <class Duration, class Rep2,
+ bool = (
+ //boost::is_convertible<typename Duration::rep,
+ //typename common_type<typename Duration::rep, Rep2>::type>::value
+ //&&
+ boost::is_convertible<Rep2,
+ typename common_type<typename Duration::rep, Rep2>::type>::value
+ )
+ >
+ struct duration_modulo_imp
+ {
+ };
+
+ template <class Rep1, class Period, class Rep2>
+ struct duration_modulo_imp<duration<Rep1, Period>, Rep2, true>
+ {
+ typedef duration<typename common_type<Rep1, Rep2>::type, Period> type;
+ };
+
+ template <class Rep1, class Period, class Rep2>
+ struct duration_modulo_result<duration<Rep1, Period>, Rep2, false>
+ : duration_modulo_imp<duration<Rep1, Period>, Rep2>
+ {
+ };
+
} // namespace detail
} // namespace chrono
@@ -630,13 +662,10 @@
// Duration /
-
-
template <class Rep1, class Period, class Rep2>
inline
typename boost::disable_if <boost::chrono::detail::is_duration<Rep2>,
- //duration<typename common_type<Rep1, Rep2>::type, Period>
- typename boost::chrono::detail::duration_divide_result<duration<Rep1, Period>, Rep2>::type
+ typename boost::chrono::detail::duration_divide_result<duration<Rep1, Period>, Rep2>::type
>::type
operator/(const duration<Rep1, Period>& d, const Rep2& s)
{
@@ -656,6 +685,30 @@
return CD(lhs).count() / CD(rhs).count();
}
+ // Duration %
+
+ template <class Rep1, class Period, class Rep2>
+ typename boost::disable_if <boost::chrono::detail::is_duration<Rep2>,
+ typename boost::chrono::detail::duration_modulo_result<duration<Rep1, Period>, Rep2>::type
+ >::type
+ operator%(const duration<Rep1, Period>& d, const Rep2& s) {
+ typedef typename common_type<Rep1, Rep2>::type CR;
+ duration<CR, Period> r = d;
+ r %= static_cast<CR>(s);
+ return r;
+ }
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs) {
+ typedef typename common_type<duration<Rep1, Period1>,
+ duration<Rep2, Period2> >::type CD;
+ CD r(lhs);
+ r%=CD(rhs);
+ return r;
+ }
+
+
//----------------------------------------------------------------------------//
// 20.9.3.6 duration comparisons [time.duration.comparisons] //
//----------------------------------------------------------------------------//
Deleted: sandbox/chrono/boost/chrono/cpu_clocks.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/cpu_clocks.hpp 2010-01-13 06:03:51 EST (Wed, 13 Jan 2010)
+++ (empty file)
@@ -1,58 +0,0 @@
-// boost cpu_clocks.hpp -----------------------------------------------------------//
-
-// Copyright 2009 Vicente J. Botet Escriba
-
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt
-
-// See http://www.boost.org/libs/system for documentation.
-
-#ifndef BOOST_CHRONO_CPU_CLOCKS_HPP
-#define BOOST_CHRONO_CPU_CLOCKS_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/system/error_code.hpp>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost { namespace chrono {
-
- class BOOST_CHRONO_DECL process_real_cpu_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_real_cpu_clock> time_point;
- static const bool is_monotonic = true;
-
- static time_point now( system::error_code & ec = system::throws );
- };
-
- class process_user_cpu_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_user_cpu_clock> time_point;
- static const bool is_monotonic = true;
-
- static time_point now( system::error_code & ec = system::throws );
- };
-
- class process_system_cpu_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_system_cpu_clock> time_point;
- static const bool is_monotonic = true;
-
- static time_point now( system::error_code & ec = system::throws );
- };
-
-} // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP
Added: sandbox/chrono/boost/chrono/digital_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/digital_time.hpp 2010-01-13 06:03:51 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,72 @@
+// boost digital_time.hpp -----------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_DIGITAL_TIME_HPP
+#define BOOST_CHRONO_DIGITAL_TIME_HPP
+
+#include <boost/chrono/chrono.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+class digital_time {
+ typedef boost::chrono::duration<boost::int_least32_t, ratio<24*3600> > days;
+ typedef boost::chrono::hours hours;
+ typedef boost::chrono::minutes minutes;
+ typedef boost::chrono::seconds seconds;
+ typedef boost::chrono::nanoseconds nanoseconds;
+public:
+ days days_;
+ hours hours_;
+ minutes minutes_;
+ seconds seconds_;
+ nanoseconds nanoseconds_;
+
+ template <class Rep, class Period>
+ static days get_days(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<days>(d);
+ };
+
+ template <class Rep, class Period>
+ static hours get_hours(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<hours>(d % days(1));
+ };
+
+ template <class Rep, class Period>
+ static minutes get_minutes(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<minutes>(d % hours(1));
+ };
+
+ template <class Rep, class Period>
+ static seconds get_seconds(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<seconds>(d % minutes(1));
+ };
+
+ template <class Rep, class Period>
+ static nanoseconds get_nanoseconds(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<nanoseconds>(d % seconds(1));
+ };
+
+ template <class Rep, class Period>
+ explicit digital_time(const boost::chrono::duration<Rep, Period>& d)
+ : days_ (get_days(d))
+ , hours_ (get_hours(d))
+ , minutes_ (get_minutes(d))
+ , seconds_ (get_seconds(d))
+ , nanoseconds_ (get_nanoseconds(d))
+ {}
+};
+
+} // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_CHRONO_PROCESS_CLOCK_HPP
Added: sandbox/chrono/boost/chrono/digital_time_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/digital_time_formatter.hpp 2010-01-13 06:03:51 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,97 @@
+// boost/chrono/timer.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_DIGITAL_TIME_FORMATTER_HPP
+#define BOOST_CHRONO_DIGITAL_TIME_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/digital_time.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+
+ class digital_time_formatter {
+ public:
+ static std::ostream & m_cout();
+ static const int m_default_places = 3;
+ static const char * default_format;
+ static int default_places() { return m_default_places; }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_
+ , const char * format, int places, std::ostream & os
+ , 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.
+ {
+ typedef typename Stopwatch::duration duration;
+ duration d = stopwatch_.elapsed( ec );
+
+ if ( d < duration(0) ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 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 );
+
+ digital_time dt(d);
+ for ( ; *format; ++format ) {
+ if ( *format != '%' || !*(format+1) || !std::strchr("dhmsn", *(format+1)) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 'd':
+ os << dt.days_.count();
+ break;
+ case 'h':
+ os << dt.hours_.count();
+ break;
+ case 'm':
+ os << dt.minutes_.count();
+ break;
+ case 's':
+ os << dt.seconds_.count();
+ break;
+ case 'n':
+ os << dt.nanoseconds_.count();
+ break;
+ default:
+ assert(0 && "digital_time_formatter internal logic error");
+ }
+ }
+ }
+ }
+ };
+ const char * digital_time_formatter::default_format ="\n%d days(s) %h:%m:%s.%n\n";
+
+ std::ostream & digital_time_formatter::m_cout() { return std::cout; }
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_CHRONO_DIGITAL_TIME_FORMATTER_HPP
Added: sandbox/chrono/boost/chrono/process_cpu_clocks.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/process_cpu_clocks.hpp 2010-01-13 06:03:51 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,120 @@
+// boost process_cpu_clocks.hpp -----------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
+#define BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/operators.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+ class BOOST_CHRONO_DECL process_real_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_real_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+ class BOOST_CHRONO_DECL process_user_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_user_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+ class BOOST_CHRONO_DECL process_system_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_system_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+ class BOOST_CHRONO_DECL process_cpu_clock
+ {
+ public:
+ struct times : arithmetic<times>, less_than_comparable<times>
+ {
+ times(
+ process_real_cpu_clock::rep r,
+ process_user_cpu_clock::rep u,
+ process_system_cpu_clock::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
+
+ times operator+=(times const& rhs) {
+ real+=rhs.real;
+ user+=rhs.user;
+ system+=rhs.system;
+ return *this;
+ }
+ times operator-=(times const& rhs) {
+ real-=rhs.real;
+ user-=rhs.user;
+ system-=rhs.system;
+ return *this;
+ }
+ times operator*=(times const& rhs) {
+ real*=rhs.real;
+ user*=rhs.user;
+ system*=rhs.system;
+ return *this;
+ }
+ times operator/=(times const& rhs) {
+ real/=rhs.real;
+ user/=rhs.user;
+ system/=rhs.system;
+ return *this;
+ }
+ bool operator<(times const & rhs) const {
+ if (real < rhs.real) return true;
+ if (real > rhs.real) return false;
+ if (user < rhs.user) return true;
+ if (user > rhs.user) return false;
+ if (user < rhs.user) return true;
+ else return false;
+ }
+ };
+
+ typedef duration<times, nano> duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+
+} // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_PROCESS_TIMES_HPP
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