summaryrefslogtreecommitdiff
path: root/src/third_party/boost-1.56.0/libs/chrono/stopwatches/include/boost/chrono/stopwatches/stopwatch_scoped.hpp
blob: 836d0a95526040118a10e1120d368ec40ad49e9d (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//  boost/chrono/stopwatches/stopwatch_scoped.hpp  ------------------------------------------------------------//
//  Copyright 2009-2011 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/chrono/stopwatches for documentation.

#ifndef BOOST_CHRONO_STOPWATCHES_STOPWATCH_SCOPED_HPP
#define BOOST_CHRONO_STOPWATCHES_STOPWATCH_SCOPED_HPP

#include <boost/chrono/config.hpp>

#include <boost/chrono/chrono.hpp>
#include <boost/chrono/detail/system.hpp>

namespace boost
{
  namespace chrono
  {

    //--------------------------------------------------------------------------------------//
    template<class Stopwatch>
    class stopwatch_runner
    {
    public:
      typedef Stopwatch stopwatch;
      stopwatch_runner(stopwatch & a) :
        stopwatch_(a)
      {
        stopwatch_.start();
      }
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
      stopwatch_runner(stopwatch & a, system::error_code & ec) :
        stopwatch_(a)
      {
        stopwatch_.start(ec);
      }
#endif
      ~stopwatch_runner()
      {
        stopwatch_.stop();
      }
    private:
      stopwatch& stopwatch_;
      stopwatch_runner();//= delete;
      stopwatch_runner(const stopwatch_runner&); // = delete;
      stopwatch_runner& operator=(const stopwatch_runner&); // = delete;

    };

    //--------------------------------------------------------------------------------------//
    template<class Stopwatch>
    class stopwatch_stopper
    {
    public:
      typedef Stopwatch stopwatch;
      stopwatch_stopper(stopwatch & a) :
        stopwatch_(a)
      {
        stopwatch_.stop();
      }
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
      stopwatch_stopper(stopwatch & a, system::error_code & ec) :
        stopwatch_(a)
      {
        stopwatch_.stop(ec);
      }
#endif
      ~stopwatch_stopper()
      {
        stopwatch_.start();
      }
    private:
      stopwatch& stopwatch_;
      stopwatch_stopper();//= delete;
      stopwatch_stopper(const stopwatch_stopper&); // = delete;
      stopwatch_stopper& operator=(const stopwatch_stopper&); // = delete;

    };

    //--------------------------------------------------------------------------------------//
    template<class Stopwatch>
    class stopwatch_suspender
    {
    public:
      typedef Stopwatch stopwatch;
      stopwatch_suspender(stopwatch & a) :
        stopwatch_(a)
      {
        stopwatch_.suspend();
      }
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
      stopwatch_suspender(stopwatch & a, system::error_code & ec) :
        stopwatch_(a)
      {
        stopwatch_.suspend(ec);
      }
#endif

      ~stopwatch_suspender()
      {
        stopwatch_.resume();
      }
    private:
      stopwatch& stopwatch_;
      stopwatch_suspender(); // = delete;
      stopwatch_suspender(const stopwatch_suspender&); // = delete;
      stopwatch_suspender& operator=(const stopwatch_suspender&); // = delete;
    };

    //--------------------------------------------------------------------------------------//
    template<class Stopwatch>
    class stopwatch_resumer
    {
    public:
      typedef Stopwatch stopwatch;
      stopwatch_resumer(stopwatch & a) :
        stopwatch_(a)
      {
        stopwatch_.resume();
      }
#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
      stopwatch_resumer(stopwatch & a, system::error_code & ec) :
        stopwatch_(a)
      {
        stopwatch_.resume(ec);
      }
#endif
      ~stopwatch_resumer()
      {
        stopwatch_.suspend();
      }
    private:
      stopwatch& stopwatch_;
      stopwatch_resumer(); // = delete;
      stopwatch_resumer(const stopwatch_resumer&); // = delete;
      stopwatch_resumer& operator=(const stopwatch_resumer&); // = delete;
    };

  } // namespace chrono
} // namespace boost

#endif