OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 #ifndef TIMER_HH
50 #define TIMER_HH
51 // ----------------------------------------------------------------------------
52 
58 // ----------------------------------------------------------------------------
59 
60 #include <OpenMesh/Core/System/config.hh>
61 //
62 #include <ostream>
63 #include <string>
64 #if defined(OM_CC_MIPS)
65 # include <assert.h>
66 #else
67 # include <cassert>
68 #endif
69 
70 
71 // ------------------------------------------------------------- namespace ----
72 
73 namespace OpenMesh {
74 namespace Utils {
75 
76 
77 // -------------------------------------------------------------- forwards ----
78 
79 
80 class TimerImpl;
81 
82 
83 // ----------------------------------------------------------------- class ----
84 
87 class OPENMESHDLLEXPORT Timer
88 {
89 public:
90 
92  enum Format {
93  Automatic,
94  Long,
95  Hours,
96  Minutes,
97  Seconds,
98  HSeconds,
99  MSeconds,
100  MicroSeconds,
101  NanoSeconds
102  };
103 
104  Timer(void);
105  ~Timer(void);
106 
108  bool is_valid() const { return state_!=Invalid; }
109 
110  bool is_stopped() const { return state_==Stopped; }
111 
113  void reset(void);
114 
116  void start(void);
117 
119  void stop(void);
120 
122  void cont(void);
123 
125  float resolution() const;
126 
128  double seconds(void) const;
129 
131  double hseconds(void) const { return seconds()*1e2; }
132 
134  double mseconds(void) const { return seconds()*1e3; }
135 
137  double useconds(void) const { return seconds()*1e6; }
138 
142  std::string as_string(Format format = Automatic);
143 
147  static std::string as_string(double seconds, Format format = Automatic);
148 
149 public:
150 
152  bool operator < (const Timer& t2) const
154  {
155  assert( is_stopped() && t2.is_stopped() );
156  return (seconds() < t2.seconds());
157  }
158 
159  bool operator > (const Timer& t2) const
160  {
161  assert( is_stopped() && t2.is_stopped() );
162  return (seconds() > t2.seconds());
163  }
164 
165  bool operator == (const Timer& t2) const
166  {
167  assert( is_stopped() && t2.is_stopped() );
168  return (seconds() == t2.seconds());
169  }
170 
171  bool operator <= (const Timer& t2) const
172  {
173  assert( is_stopped() && t2.is_stopped() );
174  return (seconds() <= t2.seconds());
175  }
176 
177  bool operator >=(const Timer& t2) const
178  {
179  assert( is_stopped() && t2.is_stopped() );
180  return (seconds() >= t2.seconds());
181  }
183 
184 protected:
185 
186  TimerImpl *impl_;
187 
188  enum {
189  Invalid = -1,
190  Stopped = 0,
191  Running = 1
192  } state_;
193 
194 };
195 
196 
201 inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
202 {
203  return (_o << _t.seconds());
204 }
205 
206 
207 // ============================================================================
208 } // END_NS_UTILS
209 } // END_NS_OPENMESH
210 // ============================================================================
211 #endif
212 // end of Timer.hh
213 // ===========================================================================
214 
Format
Formatting options for member Timer::as_string()
Definition: Timer.hh:92
Timer class.
Definition: Timer.hh:87
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
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
double useconds(void) const
Returns measured time in micro seconds, if the timer is in state 'Stopped'.
Definition: Timer.hh:137
bool is_valid() const
Returns true if self is in a valid state!
Definition: Timer.hh:108
double hseconds(void) const
Returns measured time in hundredth seconds, if the timer is in state 'Stopped'.
Definition: Timer.hh:131
double seconds(void) const
Returns measured time in seconds, if the timer is in state 'Stopped'.
double mseconds(void) const
Returns measured time in milli seconds, if the timer is in state 'Stopped'.
Definition: Timer.hh:134

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .