/Users/jack/Code/basso_dev/inc/Stopwatch.h

Go to the documentation of this file.
00001 
00010 #ifndef _STOPWATCH_BASSO_H_
00011 #define _STOPWATCH_BASSO_H_
00012 
00013 // std includes
00014 #include <ctime>
00015 #include <iomanip>
00016 
00017 // MTL includes
00018 
00019 // Basso includes
00020 #include "Basso.h"
00021 
00022 namespace basso {
00023 
00031 class Stopwatch {
00032 
00033 public:
00034         
00035         // PUBLIC DEFS
00036 #define TPS static_cast<Numeric>(CLOCKS_PER_SEC)
00037         
00038         // CONSTRUCTORS 
00039         Stopwatch() { /*mode=0; clock_ticks=0; lap_ticks=0; start_ticks=0;*/ }
00040         
00041         virtual ~Stopwatch() { }
00042         
00043         // ACCESSORS
00044         
00045         // MEMBER FUNCTIONS
00046         
00048         Numeric Start();
00049         
00051 //      Numeric Stop();
00052         
00054 //      Numeric Reset();
00055         
00057         Numeric Read() const;
00058 
00059 private:
00060         clock_t start_ticks;
00061 //      clock_t clock_ticks;
00062 //      clock_t lap_ticks;
00063         //int mode;  // mode = 0 off, mode = 1 running, mode = 2 lap
00064         
00065 
00066 };
00067 /*
00068 Numeric Stopwatch::Reset() 
00069 { 
00070         start_ticks=clock()-clock_ticks; 
00071         mode=1; 
00072         return Read(); 
00073 }
00074 */
00075 
00076 Numeric Stopwatch::Start() 
00077 { 
00078         start_ticks=clock(); 
00079         return Read(); 
00080 }
00081 
00082 /*
00083 Numeric Stopwatch::Stop()  
00084 { 
00085         if ( mode==2 )
00086                 mode=1;
00087         else
00088                 mode=0;
00089                  
00090         clock_ticks=clock();
00091         return Read(); 
00092 }
00093 */
00094 /*
00095 Numeric Stopwatch::Lap() 
00096 { 
00097         lap_ticks=clock();
00098         mode=2;
00099         return Read();
00100 }
00101 */
00102 Numeric Stopwatch::Read() const 
00103 {
00104         return (clock()-start_ticks)/TPS;
00105 }
00106 
00107 /*
00108 Numeric Stopwatch::ReadLap() const 
00109 {
00110         if ( mode!=2 )
00111                 return 0.0;
00112         return (clock()-lap_ticks)/TPS;
00113 }
00114 */
00115 //**************************************************
00117 std::ostream &operator << ( std::ostream &out, const Stopwatch &timer )
00118 {
00119         out << setw( 10 ) << setiosflags(ios::fixed) << setprecision( 3 ) << timer.Read() << " ";
00120         return out;
00121 }
00122 
00123 //** A simple function to pause for dt seconds */
00124 void pause( Numeric dt )
00125 {
00126         Stopwatch clock;
00127         clock.Start();
00128         while ( clock.Read() < dt )
00129                 int j=999;
00130 }
00131 
00132 } // end namespace
00133 
00134 #endif
00135 
00136 

Generated on Sat Jan 19 09:03:57 2008 for Basso by  doxygen 1.5.2