summaryrefslogtreecommitdiff
path: root/src/third_party/boost-1.60.0/libs/chrono/stopwatches/include/boost/chrono/stopwatches/simple_stopwatch.hpp
blob: f36acbb714129a410d5f4bfb2671da41cd111423 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//  boost/chrono/stopwatches/simple_stopwatch.hpp  ------------------------------------------------------------//
//  Copyright 2011 Vicente J. Botet Escriba
//  Copyright (c) Microsoft Corporation 2014
//  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/libs/chrono/stopwatches for documentation.

#ifndef BOOST_CHRONO_STOPWATCHES_SIMPLE_STOPWATCH__HPP
#define BOOST_CHRONO_STOPWATCHES_SIMPLE_STOPWATCH__HPP

#include <boost/chrono/config.hpp>

#include <boost/chrono/chrono.hpp>
#include <boost/system/error_code.hpp>
#include <boost/chrono/thread_clock.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
#include <utility>

namespace boost
{
  namespace chrono
  {

    /**
     * This class provides the simpler stopwatch which is just able to give the elapsed time since its construction.
     */
    template<typename Clock=high_resolution_clock>
    class simple_stopwatch
    {
    public:
      typedef Clock clock;
      typedef typename Clock::duration duration;
      typedef typename Clock::time_point time_point;
      typedef typename Clock::rep rep;
      typedef typename Clock::period period;
      BOOST_STATIC_CONSTEXPR bool is_steady =             Clock::is_steady;


      simple_stopwatch() :
        start_(clock::now())
      {
      }
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
      explicit simple_stopwatch(system::error_code & ec) :
        start_(duration::zero())
      {
        time_point tmp = clock::now(ec);
        if (!BOOST_CHRONO_IS_THROWS(ec))
        {
          if (ec)
          {
            return;
          }
        }
        start_ = tmp;
      }
#endif

      ~simple_stopwatch() BOOST_NOEXCEPT
      {
      }

      duration elapsed()
      {
        return clock::now() - start_;
      }

#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
      duration elapsed(system::error_code & ec) BOOST_NOEXCEPT
      {
        time_point tmp = clock::now(ec);
        if (!BOOST_CHRONO_IS_THROWS(ec))
        {
          if (ec)
            return duration::zero();
        }
        return tmp - start_;
      }
#endif

    private:
      time_point start_;
      simple_stopwatch(const simple_stopwatch&); // = delete;
      simple_stopwatch& operator=(const simple_stopwatch&); // = delete;
    };

    typedef simple_stopwatch<system_clock> system_simple_stopwatch;
#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
    typedef simple_stopwatch<steady_clock> steady_simple_stopwatch;
#endif
    typedef simple_stopwatch<high_resolution_clock> high_resolution_simple_stopwatch;

#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
    typedef simple_stopwatch<process_real_cpu_clock> process_real_cpu_simple_stopwatch;
#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
    typedef simple_stopwatch<process_user_cpu_clock> process_user_cpu_simple_stopwatch;
    typedef simple_stopwatch<process_system_cpu_clock> process_system_cpu_simple_stopwatch;
    typedef simple_stopwatch<process_cpu_clock> process_cpu_simple_stopwatch;
#endif
#endif

#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
    typedef simple_stopwatch<thread_clock> thread_simple_stopwatch;
#endif


  } // namespace chrono
} // namespace boost

#endif