Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef TIMER_HH
00043 #define TIMER_HH
00044
00045
00051
00052
00053 #include <OpenMesh/Core/System/config.hh>
00054
00055 #include <iostream>
00056 #include <string>
00057 #if defined(OM_CC_MIPS)
00058 # include <assert.h>
00059 #else
00060 # include <cassert>
00061 #endif
00062
00063
00064
00065
00066 namespace OpenMesh {
00067 namespace Utils {
00068
00069
00070
00071
00072
00073 class TimerImpl;
00074
00075
00076
00077
00080 class Timer
00081 {
00082 public:
00083
00085 enum Format {
00086 Automatic,
00087 Long,
00088 Hours,
00089 Minutes,
00090 Seconds,
00091 HSeconds,
00092 MSeconds,
00093 MicroSeconds,
00094 NanoSeconds
00095 };
00096
00097 Timer(void);
00098 ~Timer(void);
00099
00101 bool is_valid() const { return state_!=Invalid; }
00102
00103 bool is_stopped() const { return state_==Stopped; }
00104
00106 void reset(void);
00107
00109 void start(void);
00110
00112 void stop(void);
00113
00115 void cont(void);
00116
00118 float resolution() const;
00119
00121 double seconds(void) const;
00122
00124 double hseconds(void) const { return seconds()*1e2; }
00125
00127 double mseconds(void) const { return seconds()*1e3; }
00128
00130 double useconds(void) const { return seconds()*1e6; }
00131
00135 std::string as_string(Format format = Automatic);
00136
00140 static std::string as_string(double seconds, Format format = Automatic);
00141
00142 public:
00143
00145
00146 bool operator < (const Timer& t2) const
00147 {
00148 assert( is_stopped() && t2.is_stopped() );
00149 return (seconds() < t2.seconds());
00150 }
00151
00152 bool operator > (const Timer& t2) const
00153 {
00154 assert( is_stopped() && t2.is_stopped() );
00155 return (seconds() > t2.seconds());
00156 }
00157
00158 bool operator == (const Timer& t2) const
00159 {
00160 assert( is_stopped() && t2.is_stopped() );
00161 return (seconds() == t2.seconds());
00162 }
00163
00164 bool operator <= (const Timer& t2) const
00165 {
00166 assert( is_stopped() && t2.is_stopped() );
00167 return (seconds() <= t2.seconds());
00168 }
00169
00170 bool operator >=(const Timer& t2) const
00171 {
00172 assert( is_stopped() && t2.is_stopped() );
00173 return (seconds() >= t2.seconds());
00174 }
00176
00177 protected:
00178
00179 TimerImpl *impl_;
00180
00181 enum {
00182 Invalid = -1,
00183 Stopped = 0,
00184 Running = 1
00185 } state_;
00186
00187 };
00188
00189
00194 inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
00195 {
00196 return (_o << _t.seconds());
00197 }
00198
00199
00200
00201 }
00202 }
00203
00204 #endif
00205
00206
00207