| OpenMesh

Timer.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, 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
68 namespace OpenMesh {
69 namespace Utils {
70
71
72 // -------------------------------------------------------------- forwards ----
73
74
75 class TimerImpl;
76
77
78 // ----------------------------------------------------------------- class ----
79
82 class OPENMESHDLLEXPORT Timer
83 {
84 public:
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
101 Timer(const Timer& _other) = delete;
102
103 ~Timer(void);
104
106 bool is_valid() const { return state_!=Invalid; }
107
108 bool is_stopped() const { return state_==Stopped; }
109
111 void reset(void);
112
114 void start(void);
115
117 void stop(void);
118
120 void cont(void);
121
123 float resolution() const;
124
126 double seconds(void) const;
127
129 double hseconds(void) const { return seconds()*1e2; }
130
132 double mseconds(void) const { return seconds()*1e3; }
133
135 double useconds(void) const { return seconds()*1e6; }
136
140 std::string as_string(Format format = Automatic);
141
145 static std::string as_string(double seconds, Format format = Automatic);
146
147 public:
148
150 bool operator < (const Timer& t2) const
152 {
153 assert( is_stopped() && t2.is_stopped() );
154 return (seconds() < t2.seconds());
155 }
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 }
181
182 protected:
183
184 TimerImpl *impl_;
185
186 enum {
187 Invalid = -1,
188 Stopped = 0,
189 Running = 1
190 } state_;
191
192 };
193
194
199 inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
200 {
201 return (_o << _t.seconds());
202 }
203
204
205 // ============================================================================
206 } // END_NS_UTILS
207 } // END_NS_OPENMESH
208 // ============================================================================
209 #endif
210 // end of Timer.hh
211 // ===========================================================================
212
OpenMesh::Utils::Timer::Format
Format
Formatting options for member Timer::as_string()
Definition: Timer.hh:87
OpenMesh::Utils::Timer::hseconds
double hseconds(void) const
Returns measured time in hundredth seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:129
OpenMesh::Utils::Timer::useconds
double useconds(void) const
Returns measured time in micro seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:135
OpenMesh::operator<<
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
OpenMesh::Utils::Timer
Timer class.
Definition: Timer.hh:82
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::Utils::Timer::mseconds
double mseconds(void) const
Returns measured time in milli seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:132
OpenMesh::Utils::Timer::is_valid
bool is_valid() const
Returns true if self is in a valid state!
Definition: Timer.hh:106
OpenMesh::Utils::Timer::seconds
double seconds(void) const
Returns measured time in seconds, if the timer is in state &#39;Stopped&#39;.