$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r74210 - trunk/libs/chrono/example
From: vicente.botet_at_[hidden]
Date: 2011-09-03 12:12:29
Author: viboes
Date: 2011-09-03 12:12:27 EDT (Sat, 03 Sep 2011)
New Revision: 74210
URL: http://svn.boost.org/trac/boost/changeset/74210
Log:
Chrono: Move timer.hpp to the example directory
Added:
   trunk/libs/chrono/example/timer.hpp   (contents, props changed)
Text files modified: 
   trunk/libs/chrono/example/chrono_accuracy_test.cpp |    16 ++++++++--------                        
   1 files changed, 8 insertions(+), 8 deletions(-)
Modified: trunk/libs/chrono/example/chrono_accuracy_test.cpp
==============================================================================
--- trunk/libs/chrono/example/chrono_accuracy_test.cpp	(original)
+++ trunk/libs/chrono/example/chrono_accuracy_test.cpp	2011-09-03 12:12:27 EDT (Sat, 03 Sep 2011)
@@ -11,7 +11,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/chrono/thread_clock.hpp>
-#include <boost/chrono/timer.hpp>
+#include "./timer.hpp"
 #include <cstdlib> // for atol()
 #include <iostream>
 #include <sstream>
@@ -40,12 +40,12 @@
     timeout_in_clock_t += (timeout_in_secs * CLOCKS_PER_SEC);
     std::cout << "accuracy test. Timeout=" << timeout_in_clock_t << " ticks...";
 
-    boost::chrono::system_timer           sys;
+    boost_ex::chrono::system_timer           sys;
 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
-    boost::chrono::steady_timer        mono;
+    boost_ex::chrono::steady_timer        mono;
 #endif
-    boost::chrono::high_resolution_timer  hires;
-    boost::chrono::timer<boost::chrono::process_cpu_clock>          process;
+    boost_ex::chrono::high_resolution_timer  hires;
+    boost_ex::chrono::timer<boost::chrono::process_cpu_clock>          process;
 
     std::clock_t now;
     do
@@ -53,11 +53,11 @@
       now = std::clock();
     } while ( now < timeout_in_clock_t );
 
-    boost::chrono::system_timer::duration sys_dur = sys.elapsed();
+    boost_ex::chrono::system_timer::duration sys_dur = sys.elapsed();
 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
-    boost::chrono::steady_timer::duration mono_dur = mono.elapsed();
+    boost_ex::chrono::steady_timer::duration mono_dur = mono.elapsed();
 #endif
-    boost::chrono::high_resolution_timer::duration hires_dur = hires.elapsed();
+    boost_ex::chrono::high_resolution_timer::duration hires_dur = hires.elapsed();
     boost::chrono::process_cpu_clock::duration times;
     times = process.elapsed();
     std::cout << "accuracy test. Now=" << now << " ticks...";
Added: trunk/libs/chrono/example/timer.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/example/timer.hpp	2011-09-03 12:12:27 EDT (Sat, 03 Sep 2011)
@@ -0,0 +1,62 @@
+//  boost/chrono/timer.hpp  ------------------------------------------------------------//
+
+//  Copyright Beman Dawes 2008
+//  Copyright 2009 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 BOOSTEX_CHRONO_TIMER_HPP
+#define BOOSTEX_CHRONO_TIMER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+
+namespace boost_ex
+{
+  namespace chrono
+  {
+
+//--------------------------------------------------------------------------------------//
+//                                    timer                                             //
+//--------------------------------------------------------------------------------------//
+
+    template <class Clock=boost::chrono::high_resolution_clock>
+    class timer
+    {
+    public:
+      typedef Clock                       clock;
+      typedef typename Clock::duration    duration;
+      typedef typename Clock::time_point  time_point;
+
+      explicit timer( boost::system::error_code & ec = BOOST_CHRONO_THROWS )
+        { 
+          start(ec); 
+          }
+
+     ~timer() {}  // never throws
+
+      void start( boost::system::error_code & ec = BOOST_CHRONO_THROWS )
+        { 
+          m_start = clock::now( ec ); 
+          }
+
+      duration elapsed( boost::system::error_code & ec = BOOST_CHRONO_THROWS )
+        { return clock::now( ec ) - m_start; }
+
+    private:
+      time_point m_start;
+    };
+
+    typedef chrono::timer< boost::chrono::system_clock > system_timer;
+#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
+    typedef chrono::timer< boost::chrono::steady_clock > steady_timer;
+#endif
+    typedef chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer;
+
+  } // namespace chrono
+} // namespace boost_ex
+
+#endif