|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65267 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-09-04 12:51:18
Author: viboes
Date: 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
New Revision: 65267
URL: http://svn.boost.org/trac/boost/changeset/65267
Log:
Create new files time_point.hp and system_clocks.hpp and simplify the dependencies from the other files respect to chrono.hpp
Added:
sandbox/chrono/boost/chrono/system_clocks.hpp (contents, props changed)
sandbox/chrono/boost/chrono/time_point.hpp (contents, props changed)
Text files modified:
sandbox/chrono/boost/chrono/chrono.hpp | 107 -----------------
sandbox/chrono/boost/chrono/duration.hpp | 237 ---------------------------------------
sandbox/chrono/boost/chrono/process_cpu_clocks.hpp | 3
sandbox/chrono/boost/chrono/suspendible_clock.hpp | 4
sandbox/chrono/boost/chrono/thread_clock.hpp | 7
5 files changed, 11 insertions(+), 347 deletions(-)
Modified: sandbox/chrono/boost/chrono/chrono.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/chrono.hpp (original)
+++ sandbox/chrono/boost/chrono/chrono.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -59,111 +59,8 @@
#ifndef BOOST_CHRONO_CHRONO_HPP
#define BOOST_CHRONO_CHRONO_HPP
-#include <boost/chrono/config.hpp>
-#include <boost/chrono/detail/static_assert.hpp>
#include <boost/chrono/duration.hpp>
-
-//~ #include <iostream>
-
-#include <boost/system/error_code.hpp>
-
-
-#ifdef BOOST_CHRONO_WINDOWS_API
-// The system_clock tick is 100 nanoseconds
-# define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::duration<boost::int_least64_t, ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(10000000)> >
-#else
-# define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::nanoseconds
-#endif
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-//----------------------------------------------------------------------------//
-// //
-// 20.9 Time utilities [time] //
-// synopsis //
-// //
-//----------------------------------------------------------------------------//
-
-namespace boost {
-namespace chrono {
-
- // Clocks
- class BOOST_CHRONO_DECL system_clock;
-#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- class BOOST_CHRONO_DECL monotonic_clock; // as permitted by [time.clock.monotonic]
-#endif
-
-#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef monotonic_clock high_resolution_clock; // as permitted by [time.clock.hires]
-#else
- typedef system_clock high_resolution_clock; // as permitted by [time.clock.hires]
-#endif
-
-//----------------------------------------------------------------------------//
-// //
-// 20.9.5 Clocks [time.clock] //
-// //
-//----------------------------------------------------------------------------//
-
-// If you're porting, clocks are the system-specific (non-portable) part.
-// You'll need to know how to get the current time and implement that under now().
-// You'll need to know what units (tick period) and representation makes the most
-// sense for your clock and set those accordingly.
-// If you know how to map this clock to time_t (perhaps your clock is std::time, which
-// makes that trivial), then you can fill out system_clock's to_time_t() and from_time_t().
-
-//----------------------------------------------------------------------------//
-// 20.9.5.1 Class system_clock [time.clock.system] //
-//----------------------------------------------------------------------------//
-
- class BOOST_CHRONO_DECL system_clock
- {
- public:
- typedef BOOST_SYSTEM_CLOCK_DURATION duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<system_clock> time_point;
- static const bool is_monotonic = false;
-
- static time_point now(); // throws on error
- static time_point now(system::error_code & ec); // never throws
-
- static std::time_t to_time_t(const time_point& t);
- static time_point from_time_t(std::time_t t);
- };
-
-//----------------------------------------------------------------------------//
-// 20.9.5.2 Class monotonic_clock [time.clock.monotonic] //
-//----------------------------------------------------------------------------//
-
-// As permitted by [time.clock.monotonic]
-// The class monotonic_clock is conditionally supported.
-
-#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- class BOOST_CHRONO_DECL monotonic_clock
- {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<monotonic_clock> time_point;
- static const bool is_monotonic = true;
-
- static time_point now(); // throws on error
- static time_point now(system::error_code & ec); // never throws
- };
-#endif
-//----------------------------------------------------------------------------//
-// 20.9.5.3 Class high_resolution_clock [time.clock.hires] //
-//----------------------------------------------------------------------------//
-
-// As permitted, monotonic_clock or system_clock is a typedef for high_resolution_clock.
-// See synopsis.
-
-
-} // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+#include <boost/chrono/time_point.hpp>
+#include <boost/chrono/system_clocks.hpp>
#endif // BOOST_CHRONO_CHRONO_HPP
Modified: sandbox/chrono/boost/chrono/duration.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/duration.hpp (original)
+++ sandbox/chrono/boost/chrono/duration.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -35,7 +35,6 @@
//~ #include <iostream>
-#include <ctime>
#include <climits>
#include <limits>
@@ -43,7 +42,6 @@
#include <boost/mpl/logical.hpp>
#include <boost/ratio.hpp>
#include <boost/type_traits/common_type.hpp>
-//~ #include <boost/system/error_code.hpp>
#include <boost/cstdint.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp>
@@ -70,8 +68,6 @@
template <class Rep, class Period = ratio<1> >
class duration;
- template <class Clock, class Duration = typename Clock::duration>
- class time_point;
namespace detail
{
@@ -187,9 +183,6 @@
struct common_type<chrono::duration<Rep1, Period1>,
chrono::duration<Rep2, Period2> >;
-template <class Clock, class Duration1, class Duration2>
- struct common_type<chrono::time_point<Clock, Duration1>,
- chrono::time_point<Clock, Duration2> >;
namespace chrono {
@@ -258,45 +251,6 @@
typedef duration<boost::int_least32_t, ratio< 60> > minutes; // at least 29 bits needed
typedef duration<boost::int_least32_t, ratio<3600> > hours; // at least 23 bits needed
- // time_point arithmetic
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Clock, class Duration2>
- time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
- operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- typename common_type<Duration1, Duration2>::type
- operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
-
- // time_point comparisons
- template <class Clock, class Duration1, class Duration2>
- bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
-
- // time_point_cast
- template <class ToDuration, class Clock, class Duration>
- time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
-
//----------------------------------------------------------------------------//
// duration helpers //
//----------------------------------------------------------------------------//
@@ -444,13 +398,6 @@
typename boost::detail::ratio_gcd<Period1, Period2>::type> type;
};
-template <class Clock, class Duration1, class Duration2>
-struct common_type<chrono::time_point<Clock, Duration1>,
- chrono::time_point<Clock, Duration2> >
-{
- typedef chrono::time_point<Clock,
- typename common_type<Duration1, Duration2>::type> type;
-};
//----------------------------------------------------------------------------//
// //
@@ -788,188 +735,6 @@
return boost::chrono::detail::duration_cast<duration<Rep, Period>, ToDuration>()(fd);
}
-//----------------------------------------------------------------------------//
-// //
-// 20.9.4 Class template time_point [time.point] //
-// //
-//----------------------------------------------------------------------------//
-
-template <class Clock, class Duration>
- class time_point
- {
- BOOST_CHRONO_STATIC_ASSERT(boost::chrono::detail::is_duration<Duration>::value,
- BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION, (Duration));
- public:
- typedef Clock clock;
- typedef Duration duration;
- typedef typename duration::rep rep;
- typedef typename duration::period period;
- private:
- duration d_;
-
- public:
- time_point() : d_(duration::zero()) {}
- explicit time_point(const duration& d) : d_(d) {}
-
- // conversions
- template <class Duration2>
- time_point(const time_point<clock, Duration2>& t,
- typename boost::enable_if
- <
- boost::is_convertible<Duration2, duration>
- >::type* = 0)
- : d_(t.time_since_epoch()) {}
-
- // observer
-
- duration time_since_epoch() const {return d_;}
-
- // arithmetic
-
- time_point& operator+=(const duration& d) {d_ += d; return *this;}
- time_point& operator-=(const duration& d) {d_ -= d; return *this;}
-
- // special values
-
- static BOOST_CHRONO_CONSTEXPR time_point min BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::min)());}
- static BOOST_CHRONO_CONSTEXPR time_point max BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::max)());}
- };
-
-//----------------------------------------------------------------------------//
-// 20.9.4.5 time_point non-member arithmetic [time.point.nonmember] //
-//----------------------------------------------------------------------------//
-
- // time_point operator+(time_point x, duration y);
-
- template <class Clock, class Duration1, class Rep2, class Period2>
- inline
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator+(const time_point<Clock, Duration1>& lhs,
- const duration<Rep2, Period2>& rhs)
- {
- typedef time_point<Clock,
- typename common_type<Duration1, duration<Rep2, Period2> >::type> TimeResult;
- TimeResult r(lhs);
- r += rhs;
- return r;
- }
-
- // time_point operator+(duration x, time_point y);
-
- template <class Rep1, class Period1, class Clock, class Duration2>
- inline
- time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
- operator+(const duration<Rep1, Period1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return rhs + lhs;
- }
-
- // time_point operator-(time_point x, duration y);
-
- template <class Clock, class Duration1, class Rep2, class Period2>
- inline
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator-(const time_point<Clock, Duration1>& lhs,
- const duration<Rep2, Period2>& rhs)
- {
- return lhs + (-rhs);
- }
-
- // duration operator-(time_point x, time_point y);
-
- template <class Clock, class Duration1, class Duration2>
- inline
- typename common_type<Duration1, Duration2>::type
- operator-(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return lhs.time_since_epoch() - rhs.time_since_epoch();
- }
-
-//----------------------------------------------------------------------------//
-// 20.9.4.6 time_point comparisons [time.point.comparisons] //
-//----------------------------------------------------------------------------//
-
- // time_point ==
-
- template <class Clock, class Duration1, class Duration2>
- inline
- bool
- operator==(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return lhs.time_since_epoch() == rhs.time_since_epoch();
- }
-
- // time_point !=
-
- template <class Clock, class Duration1, class Duration2>
- inline
- bool
- operator!=(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return !(lhs == rhs);
- }
-
- // time_point <
-
- template <class Clock, class Duration1, class Duration2>
- inline
- bool
- operator<(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return lhs.time_since_epoch() < rhs.time_since_epoch();
- }
-
- // time_point >
-
- template <class Clock, class Duration1, class Duration2>
- inline
- bool
- operator>(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return rhs < lhs;
- }
-
- // time_point <=
-
- template <class Clock, class Duration1, class Duration2>
- inline
- bool
- operator<=(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return !(rhs < lhs);
- }
-
- // time_point >=
-
- template <class Clock, class Duration1, class Duration2>
- inline
- bool
- operator>=(const time_point<Clock, Duration1>& lhs,
- const time_point<Clock, Duration2>& rhs)
- {
- return !(lhs < rhs);
- }
-
-//----------------------------------------------------------------------------//
-// 20.9.4.7 time_point_cast [time.point.cast] //
-//----------------------------------------------------------------------------//
-
- template <class ToDuration, class Clock, class Duration>
- inline
- time_point<Clock, ToDuration>
- time_point_cast(const time_point<Clock, Duration>& t)
- {
- return time_point<Clock, ToDuration>(
- duration_cast<ToDuration>(t.time_since_epoch()));
- }
-
//----------------------------------------------------------------------------//
// duration constructor implementation //
@@ -996,4 +761,4 @@
} // namespace chrono
} // namespace boost
-#endif // BOOST_CHRONO_CHRONO_HPP
+#endif // BOOST_CHRONO_DURATION_HPP
Modified: sandbox/chrono/boost/chrono/process_cpu_clocks.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_cpu_clocks.hpp (original)
+++ sandbox/chrono/boost/chrono/process_cpu_clocks.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -10,7 +10,8 @@
#ifndef BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
#define BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP
-#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/duration.hpp>
+#include <boost/chrono/time_point.hpp>
#include <boost/system/error_code.hpp>
#include <boost/operators.hpp>
Modified: sandbox/chrono/boost/chrono/suspendible_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/suspendible_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/suspendible_clock.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -17,7 +17,7 @@
#include <boost/thread/tss.hpp>
#include <memory>
-#include <boost/config/abi_prefix.hpp> // must be the last #include
+//~ #include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost { namespace chrono {
@@ -190,6 +190,6 @@
} // namespace chrono
} // namespace boost
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+//~ #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_CHRONO_SUSPENDIBLE_CLOCK_HPP
Added: sandbox/chrono/boost/chrono/system_clocks.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/system_clocks.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -0,0 +1,168 @@
+// chrono.hpp --------------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// 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
+
+/*
+
+This code was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+/*
+
+TODO:
+
+ * Fully implement error handling, with test cases.
+ * Use boost::throw_exception. (Currently not used because of an issue with Intel 11.0.)
+ * Consider issues raised by Michael Marcin:
+
+ > In the past I've seen QueryPerformanceCounter give incorrect results,
+ > especially with SpeedStep processors on laptops. This was many years ago and
+ > might have been fixed by service packs and drivers.
+ >
+ > Typically you check the results of QPC against GetTickCount to see if the
+ > results are reasonable.
+ > http://support.microsoft.com/kb/274323
+ >
+ > I've also heard of problems with QueryPerformanceCounter in multi-processor
+ > systems.
+ >
+ > I know some people SetThreadAffinityMask to 1 for the current thread call
+ > their QueryPerformance* functions then restore SetThreadAffinityMask. This
+ > seems horrible to me because it forces your program to jump to another
+ > physical processor if it isn't already on cpu0 but they claim it worked well
+ > in practice because they called the timing functions infrequently.
+ >
+ > In the past I have chosen to use timeGetTime with timeBeginPeriod(1) for
+ > high resolution timers to avoid these issues.
+
+*/
+
+#ifndef BOOST_CHRONO_SYSTEM_CLOCKS_HPP
+#define BOOST_CHRONO_SYSTEM_CLOCKS_HPP
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/duration.hpp>
+#include <boost/chrono/time_point.hpp>
+
+#include <ctime>
+#include <boost/system/error_code.hpp>
+
+
+#ifdef BOOST_CHRONO_WINDOWS_API
+// The system_clock tick is 100 nanoseconds
+# define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::duration<boost::int_least64_t, ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(10000000)> >
+#else
+# define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::nanoseconds
+#endif
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9 Time utilities [time] //
+// synopsis //
+// //
+//----------------------------------------------------------------------------//
+
+namespace boost {
+namespace chrono {
+
+ // Clocks
+ class BOOST_CHRONO_DECL system_clock;
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ class BOOST_CHRONO_DECL monotonic_clock; // as permitted by [time.clock.monotonic]
+#endif
+
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef monotonic_clock high_resolution_clock; // as permitted by [time.clock.hires]
+#else
+ typedef system_clock high_resolution_clock; // as permitted by [time.clock.hires]
+#endif
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9.5 Clocks [time.clock] //
+// //
+//----------------------------------------------------------------------------//
+
+// If you're porting, clocks are the system-specific (non-portable) part.
+// You'll need to know how to get the current time and implement that under now().
+// You'll need to know what units (tick period) and representation makes the most
+// sense for your clock and set those accordingly.
+// If you know how to map this clock to time_t (perhaps your clock is std::time, which
+// makes that trivial), then you can fill out system_clock's to_time_t() and from_time_t().
+
+//----------------------------------------------------------------------------//
+// 20.9.5.1 Class system_clock [time.clock.system] //
+//----------------------------------------------------------------------------//
+
+ class BOOST_CHRONO_DECL system_clock
+ {
+ public:
+ typedef BOOST_SYSTEM_CLOCK_DURATION duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<system_clock> time_point;
+ static const bool is_monotonic = false;
+
+ static time_point now(); // throws on error
+ static time_point now(system::error_code & ec); // never throws
+
+ static std::time_t to_time_t(const time_point& t);
+ static time_point from_time_t(std::time_t t);
+ };
+
+//----------------------------------------------------------------------------//
+// 20.9.5.2 Class monotonic_clock [time.clock.monotonic] //
+//----------------------------------------------------------------------------//
+
+// As permitted by [time.clock.monotonic]
+// The class monotonic_clock is conditionally supported.
+
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ class BOOST_CHRONO_DECL monotonic_clock
+ {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<monotonic_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now(); // throws on error
+ static time_point now(system::error_code & ec); // never throws
+ };
+#endif
+//----------------------------------------------------------------------------//
+// 20.9.5.3 Class high_resolution_clock [time.clock.hires] //
+//----------------------------------------------------------------------------//
+
+// As permitted, monotonic_clock or system_clock is a typedef for high_resolution_clock.
+// See synopsis.
+
+
+} // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_CHRONO_SYSTEM_CLOCKS_HPP
Modified: sandbox/chrono/boost/chrono/thread_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/thread_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/thread_clock.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -11,10 +11,11 @@
#define BOOST_CHRONO_THREAD_CLOCK_HPP
#include <boost/chrono/config.hpp>
-#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/duration.hpp>
+#include <boost/chrono/time_point.hpp>
#include <boost/system/error_code.hpp>
-#include <boost/throw_exception.hpp>
-#include <boost/system/system_error.hpp>
+//~ #include <boost/throw_exception.hpp>
+//~ #include <boost/system/system_error.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include
Added: sandbox/chrono/boost/chrono/time_point.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/time_point.hpp 2010-09-04 12:51:15 EDT (Sat, 04 Sep 2010)
@@ -0,0 +1,301 @@
+// duration.hpp --------------------------------------------------------------//
+
+// Copyright 2008 Howard Hinnant
+// Copyright 2008 Beman Dawes
+// 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
+
+/*
+
+This code was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
+Many thanks to Howard for making his code available under the Boost license.
+The original code was modified to conform to Boost conventions and to section
+20.9 Time utilities [time] of the C++ committee's working paper N2798.
+See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
+
+time2_demo contained this comment:
+
+ Much thanks to Andrei Alexandrescu,
+ Walter Brown,
+ Peter Dimov,
+ Jeff Garland,
+ Terry Golubiewski,
+ Daniel Krügler,
+ Anthony Williams.
+*/
+
+
+#ifndef BOOST_CHRONO_TIME_POINT_HPP
+#define BOOST_CHRONO_TIME_POINT_HPP
+
+#include <boost/chrono/duration.hpp>
+
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9 Time utilities [time] //
+// synopsis //
+// //
+//----------------------------------------------------------------------------//
+
+namespace boost {
+namespace chrono {
+
+ template <class Clock, class Duration = typename Clock::duration>
+ class time_point;
+
+
+} // namespace chrono
+
+
+// common_type trait specializations
+
+template <class Clock, class Duration1, class Duration2>
+ struct common_type<chrono::time_point<Clock, Duration1>,
+ chrono::time_point<Clock, Duration2> >;
+
+
+//----------------------------------------------------------------------------//
+// 20.9.2.3 Specializations of common_type [time.traits.specializations] //
+//----------------------------------------------------------------------------//
+
+
+template <class Clock, class Duration1, class Duration2>
+struct common_type<chrono::time_point<Clock, Duration1>,
+ chrono::time_point<Clock, Duration2> >
+{
+ typedef chrono::time_point<Clock,
+ typename common_type<Duration1, Duration2>::type> type;
+};
+
+
+
+namespace chrono {
+
+ // time_point arithmetic
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Rep1, class Period1, class Clock, class Duration2>
+ time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
+ operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ typename common_type<Duration1, Duration2>::type
+ operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+
+ // time_point comparisons
+ template <class Clock, class Duration1, class Duration2>
+ bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+
+ // time_point_cast
+ template <class ToDuration, class Clock, class Duration>
+ time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
+
+//----------------------------------------------------------------------------//
+// //
+// 20.9.4 Class template time_point [time.point] //
+// //
+//----------------------------------------------------------------------------//
+
+template <class Clock, class Duration>
+ class time_point
+ {
+ BOOST_CHRONO_STATIC_ASSERT(boost::chrono::detail::is_duration<Duration>::value,
+ BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION, (Duration));
+ public:
+ typedef Clock clock;
+ typedef Duration duration;
+ typedef typename duration::rep rep;
+ typedef typename duration::period period;
+ private:
+ duration d_;
+
+ public:
+ time_point() : d_(duration::zero()) {}
+ explicit time_point(const duration& d) : d_(d) {}
+
+ // conversions
+ template <class Duration2>
+ time_point(const time_point<clock, Duration2>& t,
+ typename boost::enable_if
+ <
+ boost::is_convertible<Duration2, duration>
+ >::type* = 0)
+ : d_(t.time_since_epoch()) {}
+
+ // observer
+
+ duration time_since_epoch() const {return d_;}
+
+ // arithmetic
+
+ time_point& operator+=(const duration& d) {d_ += d; return *this;}
+ time_point& operator-=(const duration& d) {d_ -= d; return *this;}
+
+ // special values
+
+ static BOOST_CHRONO_CONSTEXPR time_point min BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::min)());}
+ static BOOST_CHRONO_CONSTEXPR time_point max BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::max)());}
+ };
+
+//----------------------------------------------------------------------------//
+// 20.9.4.5 time_point non-member arithmetic [time.point.nonmember] //
+//----------------------------------------------------------------------------//
+
+ // time_point operator+(time_point x, duration y);
+
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ inline
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator+(const time_point<Clock, Duration1>& lhs,
+ const duration<Rep2, Period2>& rhs)
+ {
+ typedef time_point<Clock,
+ typename common_type<Duration1, duration<Rep2, Period2> >::type> TimeResult;
+ TimeResult r(lhs);
+ r += rhs;
+ return r;
+ }
+
+ // time_point operator+(duration x, time_point y);
+
+ template <class Rep1, class Period1, class Clock, class Duration2>
+ inline
+ time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
+ operator+(const duration<Rep1, Period1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return rhs + lhs;
+ }
+
+ // time_point operator-(time_point x, duration y);
+
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ inline
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator-(const time_point<Clock, Duration1>& lhs,
+ const duration<Rep2, Period2>& rhs)
+ {
+ return lhs + (-rhs);
+ }
+
+ // duration operator-(time_point x, time_point y);
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ typename common_type<Duration1, Duration2>::type
+ operator-(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return lhs.time_since_epoch() - rhs.time_since_epoch();
+ }
+
+//----------------------------------------------------------------------------//
+// 20.9.4.6 time_point comparisons [time.point.comparisons] //
+//----------------------------------------------------------------------------//
+
+ // time_point ==
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ bool
+ operator==(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return lhs.time_since_epoch() == rhs.time_since_epoch();
+ }
+
+ // time_point !=
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ bool
+ operator!=(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
+ // time_point <
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ bool
+ operator<(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return lhs.time_since_epoch() < rhs.time_since_epoch();
+ }
+
+ // time_point >
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ bool
+ operator>(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return rhs < lhs;
+ }
+
+ // time_point <=
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ bool
+ operator<=(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return !(rhs < lhs);
+ }
+
+ // time_point >=
+
+ template <class Clock, class Duration1, class Duration2>
+ inline
+ bool
+ operator>=(const time_point<Clock, Duration1>& lhs,
+ const time_point<Clock, Duration2>& rhs)
+ {
+ return !(lhs < rhs);
+ }
+
+//----------------------------------------------------------------------------//
+// 20.9.4.7 time_point_cast [time.point.cast] //
+//----------------------------------------------------------------------------//
+
+ template <class ToDuration, class Clock, class Duration>
+ inline
+ time_point<Clock, ToDuration>
+ time_point_cast(const time_point<Clock, Duration>& t)
+ {
+ return time_point<Clock, ToDuration>(
+ duration_cast<ToDuration>(t.time_since_epoch()));
+ }
+
+} // namespace chrono
+} // namespace boost
+
+#endif // BOOST_CHRONO_TIME_POINT_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