/Src/Dependencies/Boost/boost/chrono/timer.hpp

http://hadesmem.googlecode.com/ · C++ Header · 62 lines · 37 code · 16 blank · 9 comment · 0 complexity · a2b24508292764848893694499ecb12a MD5 · raw file

  1. // boost/chrono/timer.hpp ------------------------------------------------------------//
  2. // Copyright Beman Dawes 2008
  3. // Copyright 2009 Vicente J. Botet Escriba
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org/libs/system for documentation.
  7. #ifndef BOOST_CHRONO_TIMER_HPP
  8. #define BOOST_CHRONO_TIMER_HPP
  9. #include <boost/chrono/chrono.hpp>
  10. #include <boost/system/error_code.hpp>
  11. namespace boost
  12. {
  13. namespace chrono
  14. {
  15. //--------------------------------------------------------------------------------------//
  16. // timer //
  17. //--------------------------------------------------------------------------------------//
  18. template <class Clock=high_resolution_clock>
  19. class timer
  20. {
  21. public:
  22. typedef Clock clock;
  23. typedef typename Clock::duration duration;
  24. typedef typename Clock::time_point time_point;
  25. explicit timer( system::error_code & ec = BOOST_CHRONO_THROWS )
  26. {
  27. start(ec);
  28. }
  29. ~timer() {} // never throws
  30. void start( system::error_code & ec = BOOST_CHRONO_THROWS )
  31. {
  32. m_start = clock::now( ec );
  33. }
  34. duration elapsed( system::error_code & ec = BOOST_CHRONO_THROWS )
  35. { return clock::now( ec ) - m_start; }
  36. private:
  37. time_point m_start;
  38. };
  39. typedef boost::chrono::timer< boost::chrono::system_clock > system_timer;
  40. #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
  41. typedef boost::chrono::timer< boost::chrono::steady_clock > steady_timer;
  42. #endif
  43. typedef boost::chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer;
  44. } // namespace chrono
  45. } // namespace boost
  46. #endif