OpenMesh
Timer.hh
Go to the documentation of this file.
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
44#ifndef TIMER_HH
45#define TIMER_HH
46// ----------------------------------------------------------------------------
47
53// ----------------------------------------------------------------------------
54
55#include <OpenMesh/Core/System/config.hh>
56//
57#include <ostream>
58#include <string>
59#if defined(OM_CC_MIPS)
60# include <assert.h>
61#else
62# include <cassert>
63#endif
64
65
66// ------------------------------------------------------------- namespace ----
67
68namespace OpenMesh {
69namespace Utils {
70
71
72// -------------------------------------------------------------- forwards ----
73
74
75class TimerImpl;
76
77
78// ----------------------------------------------------------------- class ----
79
82class OPENMESHDLLEXPORT Timer
83{
84public:
85
87 enum Format {
88 Automatic,
89 Long,
90 Hours,
91 Minutes,
92 Seconds,
93 HSeconds,
94 MSeconds,
95 MicroSeconds,
96 NanoSeconds
97 };
98
99 Timer(void);
100
102 Timer(const Timer& _other) = delete;
103
105 Timer& operator=( const Timer& ) = delete;
106
107 ~Timer(void);
108
110 bool is_valid() const { return state_!=Invalid; }
111
112 bool is_stopped() const { return state_==Stopped; }
113
115 void reset(void);
116
118 void start(void);
119
121 void stop(void);
122
124 void cont(void);
125
127 float resolution() const;
128
130 double seconds(void) const;
131
133 double hseconds(void) const { return seconds()*1e2; }
134
136 double mseconds(void) const { return seconds()*1e3; }
137
139 double useconds(void) const { return seconds()*1e6; }
140
144 std::string as_string(Format format = Automatic);
145
149 static std::string as_string(double seconds, Format format = Automatic);
150
151
152
153public:
154
156
157 bool operator < (const Timer& t2) const
158 {
159 assert( is_stopped() && t2.is_stopped() );
160 return (seconds() < t2.seconds());
161 }
162
163 bool operator > (const Timer& t2) const
164 {
165 assert( is_stopped() && t2.is_stopped() );
166 return (seconds() > t2.seconds());
167 }
168
169 bool operator == (const Timer& t2) const
170 {
171 assert( is_stopped() && t2.is_stopped() );
172 return (seconds() == t2.seconds());
173 }
174
175 bool operator <= (const Timer& t2) const
176 {
177 assert( is_stopped() && t2.is_stopped() );
178 return (seconds() <= t2.seconds());
179 }
180
181 bool operator >=(const Timer& t2) const
182 {
183 assert( is_stopped() && t2.is_stopped() );
184 return (seconds() >= t2.seconds());
185 }
187
188protected:
189
190 TimerImpl *impl_;
191
192 enum {
193 Invalid = -1,
194 Stopped = 0,
195 Running = 1
196 } state_;
197
198};
199
200
205inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
206{
207 return (_o << _t.seconds());
208}
209
210
211// ============================================================================
212} // END_NS_UTILS
213} // END_NS_OPENMESH
214// ============================================================================
215#endif
216// end of Timer.hh
217// ===========================================================================
218
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
auto operator<<(std::ostream &os, const VectorT< Scalar, DIM > &_vec) -> typename std::enable_if< sizeof(decltype(os<< _vec[0])) >=0
output a vector by printing its space-separated compontens
Timer class.
Definition: Timer.hh:83
double hseconds(void) const
Returns measured time in hundredth seconds, if the timer is in state 'Stopped'.
Definition: Timer.hh:133
Format
Formatting options for member Timer::as_string()
Definition: Timer.hh:87
void reset(void)
Reset the timer.
double mseconds(void) const
Returns measured time in milli seconds, if the timer is in state 'Stopped'.
Definition: Timer.hh:136
static std::string as_string(double seconds, Format format=Automatic)
Returns a given measured time as a string.
void cont(void)
Continue measurement.
void stop(void)
Stop measurement.
Timer & operator=(const Timer &)=delete
Make the timer non copyable.
double useconds(void) const
Returns measured time in micro seconds, if the timer is in state 'Stopped'.
Definition: Timer.hh:139
Timer(const Timer &_other)=delete
Make the timer non copyable.
float resolution() const
Give resolution of timer. Depends on the underlying measurement method.
double seconds(void) const
Returns measured time in seconds, if the timer is in state 'Stopped'.
std::string as_string(Format format=Automatic)
Returns the measured time as a string.
void start(void)
Start measurement.
bool is_valid() const
Returns true if self is in a valid state!
Definition: Timer.hh:110

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .