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  * $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 
106  Timer(const Timer& _other) = delete;
107 
108  ~Timer(void);
109 
111  bool is_valid() const { return state_!=Invalid; }
112 
113  bool is_stopped() const { return state_==Stopped; }
114 
116  void reset(void);
117 
119  void start(void);
120 
122  void stop(void);
123 
125  void cont(void);
126 
128  float resolution() const;
129 
131  double seconds(void) const;
132 
134  double hseconds(void) const { return seconds()*1e2; }
135 
137  double mseconds(void) const { return seconds()*1e3; }
138 
140  double useconds(void) const { return seconds()*1e6; }
141 
145  std::string as_string(Format format = Automatic);
146 
150  static std::string as_string(double seconds, Format format = Automatic);
151 
152 public:
153 
155  bool operator < (const Timer& t2) const
157  {
158  assert( is_stopped() && t2.is_stopped() );
159  return (seconds() < t2.seconds());
160  }
161 
162  bool operator > (const Timer& t2) const
163  {
164  assert( is_stopped() && t2.is_stopped() );
165  return (seconds() > t2.seconds());
166  }
167 
168  bool operator == (const Timer& t2) const
169  {
170  assert( is_stopped() && t2.is_stopped() );
171  return (seconds() == t2.seconds());
172  }
173 
174  bool operator <= (const Timer& t2) const
175  {
176  assert( is_stopped() && t2.is_stopped() );
177  return (seconds() <= t2.seconds());
178  }
179 
180  bool operator >=(const Timer& t2) const
181  {
182  assert( is_stopped() && t2.is_stopped() );
183  return (seconds() >= t2.seconds());
184  }
186 
187 protected:
188 
189  TimerImpl *impl_;
190 
191  enum {
192  Invalid = -1,
193  Stopped = 0,
194  Running = 1
195  } state_;
196 
197 };
198 
199 
204 inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
205 {
206  return (_o << _t.seconds());
207 }
208 
209 
210 // ============================================================================
211 } // END_NS_UTILS
212 } // END_NS_OPENMESH
213 // ============================================================================
214 #endif
215 // end of Timer.hh
216 // ===========================================================================
217 
double hseconds(void) const
Returns measured time in hundredth seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:134
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 &#39;Stopped&#39;.
Definition: Timer.hh:140
Format
Formatting options for member Timer::as_string()
Definition: Timer.hh:92
double seconds(void) const
Returns measured time in seconds, if the timer is in state &#39;Stopped&#39;.
bool is_valid() const
Returns true if self is in a valid state!
Definition: Timer.hh:111
double mseconds(void) const
Returns measured time in milli seconds, if the timer is in state &#39;Stopped&#39;.
Definition: Timer.hh:137
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:87

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