Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Timer.hh

Go to the documentation of this file.
00001 // ============================================================================
00002 // $Id: Timer.hh,v 1.1.1.1 2004/09/06 12:37:51 botsch Exp $
00003 // ----------------------------------------------------------------------------
00004 #ifndef TIMER_HH
00005 #define TIMER_HH
00006 // ----------------------------------------------------------------------------
00007 
00013 // ----------------------------------------------------------------------------
00014 
00015 #include <OpenMesh/Core/System/config.hh>
00016 //
00017 #include <iostream>
00018 #include <string>
00019 #if defined(OM_CC_MIPS)
00020 #  include <assert.h>
00021 #else
00022 #  include <cassert>
00023 #endif
00024 
00025 
00026 // ------------------------------------------------------------- namespace ----
00027 
00028 namespace OpenMesh {
00029 namespace Utils {
00030 
00031 
00032 // -------------------------------------------------------------- forwards ----
00033 
00034 
00035 class TimerImpl;
00036 
00037 
00038 // ----------------------------------------------------------------- class ----
00039 
00042 class Timer
00043 {
00044 public:
00045 
00047   enum Format {
00048     Automatic,
00049     Long,
00050     Hours,
00051     Minutes,
00052     Seconds,
00053     HSeconds,
00054     MSeconds,
00055     MicroSeconds,
00056     NanoSeconds
00057   };
00058 
00059   Timer(void);
00060   ~Timer(void);
00061 
00063   bool is_valid() const { return state_!=Invalid; }
00064 
00065   bool is_stopped() const { return state_==Stopped; }
00066 
00068   void reset(void);
00069 
00071   void start(void);
00072 
00074   void stop(void);
00075 
00077   void cont(void);
00078 
00080   float resolution() const;
00081     
00083   double seconds(void) const;
00084 
00086   double hseconds(void) const { return seconds()*1e2; }
00087 
00089   double mseconds(void) const { return seconds()*1e3; }
00090 
00092   double useconds(void) const { return seconds()*1e6; }
00093   
00097   std::string as_string(Format format = Automatic);
00098   
00102   static std::string as_string(double seconds, Format format = Automatic);
00103 
00104 public:
00105 
00107 
00108   bool operator < (const Timer& t2) const 
00109   { 
00110     assert( is_stopped() && t2.is_stopped() ); 
00111     return (seconds() < t2.seconds()); 
00112   }
00113 
00114   bool operator > (const Timer& t2) const
00115   { 
00116     assert( is_stopped() && t2.is_stopped() ); 
00117     return (seconds() > t2.seconds()); 
00118   }
00119 
00120   bool operator == (const Timer& t2) const
00121   { 
00122     assert( is_stopped() && t2.is_stopped() ); 
00123     return (seconds() == t2.seconds()); 
00124   }
00125 
00126   bool operator <= (const Timer& t2) const
00127   {
00128     assert( is_stopped() && t2.is_stopped() ); 
00129     return (seconds() <= t2.seconds()); 
00130   }
00131 
00132   bool operator >=(const Timer& t2) const
00133   { 
00134     assert( is_stopped() && t2.is_stopped() ); 
00135     return (seconds() >= t2.seconds()); 
00136   }
00138 
00139 protected:
00140 
00141   TimerImpl *impl_;
00142 
00143   enum {
00144     Invalid = -1,
00145     Stopped =  0,
00146     Running =  1
00147   } state_;
00148 
00149 };
00150 
00151 
00156 inline std::ostream& operator << (std::ostream& _o, const Timer& _t)
00157 {
00158    return (_o << _t.seconds());
00159 }
00160 
00161 
00162 // ============================================================================
00163 } // END_NS_UTILS
00164 } // END_NS_OPENMESH
00165 // ============================================================================
00166 #endif
00167 // end of Timer.hh
00168 // ===========================================================================
00169 

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