timer.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_TIMER_H
00033 #define RCSC_TIMER_H
00034 
00035 #include <iostream>
00036 
00037 namespace rcsc {
00038 
00043 class TimeStamp {
00044 private:
00045     long M_sec; 
00046     long M_usec; 
00047 
00048 public:
00052     TimeStamp()
00053         : M_sec( 0 )
00054         , M_usec( 0 )
00055       { }
00056 
00060     void setCurrent();
00061 
00066     long sec() const
00067       {
00068           return M_sec;
00069       }
00070 
00075     long usec() const
00076       {
00077           return M_usec;
00078       }
00079 
00085     long getMSecDiffFrom( const TimeStamp & new_time ) const;
00086 
00092     double getRealMSecDiffFrom( const TimeStamp & new_time ) const;
00093 
00101     static
00102     void calc_time_diff( const TimeStamp & old_time,
00103                          const TimeStamp & new_time,
00104                          long & sec_diff,
00105                          long & usec_diff );
00106 };
00107 
00109 
00114 class MSecTimer {
00115 private:
00117     TimeStamp M_start_time;
00118 
00119 public:
00123     MSecTimer()
00124       {
00125           M_start_time.setCurrent();
00126       }
00127 
00131     void restart()
00132       {
00133           M_start_time.setCurrent();
00134       }
00135 
00140     long elapsed() const;
00141 
00146     double elapsedReal() const;
00147 
00153     std::ostream & print( std::ostream & os ) const;
00154 };
00155 
00156 }
00157 
00158 /*-------------------------------------------------------------------*/
00165 inline
00166 std::ostream &
00167 operator<<( std::ostream & os,
00168             const rcsc::MSecTimer & t )
00169 {
00170     return t.print( os );
00171 }
00172 
00173 #endif

librcscに対してThu May 1 15:41:22 2008に生成されました。  doxygen 1.5.0