1 // boost/chrono/stopwatches/strict_stopwatch.hpp ------------------------------------------------------------//
2 // Copyright 2011 Vicente J. Botet Escriba
3 // Copyright (c) Microsoft Corporation 2014
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/libs/chrono/stopwatches for documentation.
8 #ifndef BOOST_CHRONO_STOPWATCHES_STRICT_STOPWATCH__HPP
9 #define BOOST_CHRONO_STOPWATCHES_STRICT_STOPWATCH__HPP
11 #include <boost/chrono/config.hpp>
13 #include <boost/chrono/chrono.hpp>
14 #include <boost/chrono/detail/system.hpp>
15 #include <boost/chrono/thread_clock.hpp>
16 #include <boost/chrono/process_cpu_clocks.hpp>
25 * This class provides the simpler stopwatch which is just able to give the elapsed time since its construction.
27 template<typename Clock=high_resolution_clock>
28 class strict_stopwatch
32 typedef typename Clock::duration duration;
33 typedef typename Clock::time_point time_point;
34 typedef typename Clock::rep rep;
35 typedef typename Clock::period period;
36 BOOST_STATIC_CONSTEXPR bool is_steady = Clock::is_steady;
43 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
44 explicit strict_stopwatch(system::error_code & ec) :
45 start_(duration::zero())
47 time_point tmp = clock::now(ec);
48 if (!BOOST_CHRONO_IS_THROWS(ec))
59 ~strict_stopwatch() BOOST_NOEXCEPT
65 return clock::now() - start_;
68 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
69 duration elapsed(system::error_code & ec)
71 time_point tmp = clock::now(ec);
72 if (!BOOST_CHRONO_IS_THROWS(ec))
75 return duration::zero();
81 * States if the Stopwatch is running.
83 bool is_running() const {
88 strict_stopwatch(const strict_stopwatch&); // = delete;
89 strict_stopwatch& operator=(const strict_stopwatch&); // = delete;
92 typedef strict_stopwatch<system_clock> system_strict_stopwatch;
93 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
94 typedef strict_stopwatch<steady_clock> steady_strict_stopwatch;
96 typedef strict_stopwatch<high_resolution_clock> high_resolution_strict_stopwatch;
98 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
99 typedef strict_stopwatch<process_real_cpu_clock> process_real_cpu_strict_stopwatch;
100 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
101 typedef strict_stopwatch<process_user_cpu_clock> process_user_cpu_strict_stopwatch;
102 typedef strict_stopwatch<process_system_cpu_clock> process_system_cpu_strict_stopwatch;
103 typedef strict_stopwatch<process_cpu_clock> process_cpu_strict_stopwatch;
107 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
108 typedef strict_stopwatch<thread_clock> thread_strict_stopwatch;
112 } // namespace chrono