OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Timer.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42 #ifndef TIMER_HH
43 #define TIMER_HH
44 // ----------------------------------------------------------------------------
45
51 // ----------------------------------------------------------------------------
52
53 #include <OpenMesh/Core/System/config.hh>
54 //
55 #include <iostream>
56 #include <string>
57 #if defined(OM_CC_MIPS)
58 # include <assert.h>
59 #else
60 # include <cassert>
61 #endif
62
63
64 // ------------------------------------------------------------- namespace ----
65
66 namespace OpenMesh {
67 namespace Utils {
68
69
70 // -------------------------------------------------------------- forwards ----
71
72
73 class TimerImpl;
74
75
76 // ----------------------------------------------------------------- class ----
77
80 class OPENMESHDLLEXPORT Timer
81 {
82 public:
83
85 enum Format {
86 Automatic,
87 Long,
88 Hours,
89 Minutes,
90 Seconds,
91 HSeconds,
92 MSeconds,
93 MicroSeconds,
94 NanoSeconds
95 };
96
97 Timer(void);
98 ~Timer(void);
99
101 bool is_valid() const { return state_!=Invalid; }
102
103 bool is_stopped() const { return state_==Stopped; }
104
106 void reset(void);
107
109 void start(void);
110
112 void stop(void);
113
115 void cont(void);
116
118 float resolution() const;
119
121 double seconds(void) const;
122
124 double hseconds(void) const { return seconds()*1e2; }
125
127 double mseconds(void) const { return seconds()*1e3; }
128
130 double useconds(void) const { return seconds()*1e6; }
131
135 std::string as_string(Format format = Automatic);
136
140 static std::string as_string(double seconds, Format format = Automatic);
141
142 public:
143
145
146 bool operator < (const Timer& t2) const
147 {
148 assert( is_stopped() && t2.is_stopped() );
149 return (seconds() < t2.seconds());
150 }
151
152 bool operator > (const Timer& t2) const
153 {
154 assert( is_stopped() && t2.is_stopped() );
155 return (seconds() > t2.seconds());
156 }
157
158 bool operator == (const Timer& t2) const
159 {
160 assert( is_stopped() && t2.is_stopped() );
161 return (seconds() == t2.seconds());
162 }
163
164 bool operator <= (const Timer& t2) const
165 {
166 assert( is_stopped() && t2.is_stopped() );
167 return (seconds() <= t2.seconds());
168 }
169
170 bool operator >=(const Timer& t2) const
171 {
172 assert( is_stopped() && t2.is_stopped() );
173 return (seconds() >= t2.seconds());
174 }
176
177 protected:
178
179 TimerImpl *impl_;
180
181 enum {
182 Invalid = -1,
183 Stopped = 0,
184 Running = 1
185 } state_;
186
187 };
188
189
194 inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
195 {
196 return (_o << _t.seconds());
197 }
198
199
200 // ============================================================================
201 } // END_NS_UTILS
202 } // END_NS_OPENMESH
203 // ============================================================================
204 #endif
205 // end of Timer.hh
206 // ===========================================================================
207