]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/stopwatches/include/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / include / boost / chrono / stopwatches / reporters / stopwatch_reporter.hpp
1 // boost/chrono/stopwatches/stopwatch_reporter.hpp
2 // Copyright 2011 Vicente J. Botet Escriba
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or
5 // copy at http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
7
8 #ifndef BOOST_CHRONO_STOPWATCHES_REPORTERS_STOPWATCH_REPORTER_HPP
9 #define BOOST_CHRONO_STOPWATCHES_REPORTERS_STOPWATCH_REPORTER_HPP
10
11 #include <boost/chrono/config.hpp>
12
13 #if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_CHRONO_ENABLE_WARNINGS)
14 #if defined __GNUC__
15 #pragma GCC system_header
16 #elif defined __SUNPRO_CC
17 #pragma disable_warn
18 #elif defined _MSC_VER
19 #pragma warning(push, 1)
20 #endif
21 #endif
22
23 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
24 #include <boost/chrono/stopwatches/stopwatch_scoped.hpp>
25 #include <boost/chrono/stopwatches/dont_start.hpp>
26 #include <boost/chrono/chrono.hpp>
27 #include <boost/chrono/detail/system.hpp>
28 #include <boost/cstdint.hpp>
29 #include <cassert>
30
31 namespace boost
32 {
33 namespace chrono
34 {
35
36 template<class CharT, class Stopwatch, class Formatter=basic_stopwatch_reporter_default_formatter<CharT, Stopwatch> >
37 class basic_stopwatch_reporter: public Stopwatch
38 {
39 public:
40 typedef Stopwatch base_type;
41 typedef typename Stopwatch::clock clock;
42 typedef Stopwatch stopwatch_type;
43 typedef Formatter formatter_type;
44
45 basic_stopwatch_reporter() BOOST_NOEXCEPT :
46 formatter_(), reported_(false)
47 {
48 }
49
50 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
51 explicit basic_stopwatch_reporter(system::error_code & ec) :
52 base_type(ec), formatter_(), reported_(false)
53 {
54 }
55 #endif
56
57 explicit basic_stopwatch_reporter(
58 const dont_start_t& tag
59 ) BOOST_NOEXCEPT :
60 base_type(tag),
61 formatter_(), reported_(false)
62 {
63 }
64
65 explicit basic_stopwatch_reporter(const typename Formatter::char_type* fmt) :
66 formatter_(fmt), reported_(false)
67 {
68 }
69 explicit basic_stopwatch_reporter(typename Formatter::string_type const& fmt) :
70 formatter_(fmt), reported_(false)
71 {
72 }
73 explicit basic_stopwatch_reporter(formatter_type fmt) :
74 formatter_(fmt), reported_(false)
75 {
76 }
77
78 ~basic_stopwatch_reporter() BOOST_NOEXCEPT
79 {
80 if (!reported())
81 {
82 this->report();
83 }
84 }
85
86 inline void report() BOOST_NOEXCEPT
87 {
88 formatter_(*this);
89 reported_ = true;
90 }
91 // inline void report(system::error_code & ec)
92 // {
93 // formatter_(*this, ec);
94 // reported_ = true;
95 // }
96
97 bool reported() const
98 {
99 return reported_;
100 }
101
102 formatter_type& format()
103 {
104 return formatter_;
105 }
106
107 protected:
108 formatter_type formatter_;
109 bool reported_;
110
111 basic_stopwatch_reporter(const basic_stopwatch_reporter&); // = delete;
112 basic_stopwatch_reporter& operator=(const basic_stopwatch_reporter&); // = delete;
113 };
114
115
116 template<class Stopwatch,
117 class Formatter = typename basic_stopwatch_reporter_default_formatter<char, Stopwatch>::type>
118 class stopwatch_reporter;
119
120 template<class Stopwatch, class Formatter>
121 struct basic_stopwatch_reporter_default_formatter<char, stopwatch_reporter<Stopwatch, Formatter> >
122 {
123 typedef Formatter type;
124 };
125
126 template<class Stopwatch, class Formatter>
127 class stopwatch_reporter: public basic_stopwatch_reporter<char, Stopwatch,
128 Formatter>
129 {
130 typedef basic_stopwatch_reporter<char, Stopwatch, Formatter> base_type;
131 public:
132 typedef typename Stopwatch::clock clock;
133 typedef Stopwatch stopwatch_type;
134 typedef Formatter formatter_type;
135
136 stopwatch_reporter()
137 {
138 }
139
140 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
141 explicit stopwatch_reporter(system::error_code & ec) :
142 base_type(ec)
143 {
144 }
145 #endif
146 explicit stopwatch_reporter(
147 const dont_start_t& tag
148 ) BOOST_NOEXCEPT :
149 base_type(tag)
150 {
151 }
152
153 explicit stopwatch_reporter(formatter_type const& fmt) :
154 base_type(fmt)
155 {
156 }
157
158 explicit stopwatch_reporter(const typename Formatter::char_type* fmt) :
159 base_type(fmt)
160 {
161 }
162 explicit stopwatch_reporter(typename Formatter::string_type const& fmt) :
163 base_type(fmt)
164 {
165 }
166 typedef stopwatch_runner<stopwatch_reporter<Stopwatch, Formatter> >
167 scoped_run;
168 typedef stopwatch_stopper<stopwatch_reporter<Stopwatch, Formatter> >
169 scoped_stop;
170 typedef stopwatch_suspender<stopwatch_reporter<Stopwatch, Formatter> >
171 scoped_suspend;
172 typedef stopwatch_resumer<stopwatch_reporter<Stopwatch, Formatter> >
173 scoped_resume;
174
175 protected:
176
177 stopwatch_reporter(const stopwatch_reporter&); // = delete;
178 stopwatch_reporter& operator=(const stopwatch_reporter&); // = delete;
179 };
180
181 template<class Stopwatch,
182 class Formatter = typename basic_stopwatch_reporter_default_formatter<wchar_t,
183 Stopwatch>::type>
184 class wstopwatch_reporter;
185
186 template<class Stopwatch, class Formatter>
187 struct basic_stopwatch_reporter_default_formatter<wchar_t, wstopwatch_reporter<Stopwatch, Formatter> >
188 {
189 typedef Formatter type;
190 };
191
192 template<class Stopwatch, class Formatter>
193 class wstopwatch_reporter: public basic_stopwatch_reporter<wchar_t, Stopwatch, Formatter>
194 {
195 typedef basic_stopwatch_reporter<wchar_t, Stopwatch, Formatter> base_type;
196 public:
197 typedef typename Stopwatch::clock clock;
198 typedef Stopwatch stopwatch_type;
199 typedef Formatter formatter_type;
200
201 wstopwatch_reporter() :
202 base_type()
203 {
204 }
205 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
206 explicit wstopwatch_reporter(system::error_code & ec) :
207 base_type(ec)
208 {
209 }
210 #endif
211 explicit wstopwatch_reporter(
212 const dont_start_t& tag
213 ) BOOST_NOEXCEPT :
214 base_type(tag)
215 {
216 }
217
218 explicit wstopwatch_reporter(formatter_type const& fmt) :
219 base_type(fmt)
220 {
221 }
222 explicit wstopwatch_reporter(const typename Formatter::char_type* fmt) :
223 base_type(fmt)
224 {
225 }
226 explicit wstopwatch_reporter(typename Formatter::string_type const& fmt) :
227 base_type(fmt)
228 {
229 }
230 typedef stopwatch_runner<wstopwatch_reporter<Stopwatch, Formatter> >
231 scoped_run;
232 typedef stopwatch_stopper<wstopwatch_reporter<Stopwatch, Formatter> >
233 scoped_stop;
234 typedef stopwatch_suspender<wstopwatch_reporter<Stopwatch, Formatter> >
235 scoped_suspend;
236 typedef stopwatch_resumer<wstopwatch_reporter<Stopwatch, Formatter> >
237 scoped_resume;
238
239 protected:
240
241 wstopwatch_reporter(const wstopwatch_reporter&); // = delete;
242 wstopwatch_reporter& operator=(const wstopwatch_reporter&); // = delete;
243 };
244
245 } // namespace chrono
246 } // namespace boost
247
248
249 #if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_CHRONO_ENABLE_WARNINGS)
250 #if defined __SUNPRO_CC
251 #pragma enable_warn
252 #elif defined _MSC_VER
253 #pragma warning(pop)
254 #endif
255 #endif
256
257 #endif
258
259