Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

timer.cpp

Go to the documentation of this file.
00001 // $Id$
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   Timer class.  Provides interval and duration      *
00006 //                   timing, both of which can be reset.               *
00007 //                                                                     *
00008 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00009 //                                                                     *
00010 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00011 //                                                                     *
00012 //    This program is free software; you can redistribute it and/or    *
00013 //    modify it under the terms of the GNU General Public License      *
00014 //    as published by the Free Software Foundation; either version 2   *
00015 //    of the License, or any later version.                            *
00016 //                                                                     *
00017 //    This program is distributed in the hope that it will be useful,  *
00018 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00019 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00020 //    GNU General Public License for more details.                     *
00021 //                                                                     *
00022 //    You should have received a copy of the GNU General Public        *
00023 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00024 //    program; if not, write to:                                       *
00025 //       The Free Software Foundation Inc.,                            *
00026 //       59 Temple Place - Suite 330,                                  *
00027 //       Boston, MA  02111-1307,                                       *
00028 //       USA.                                                          *
00029 //                                                                     *
00030 //**********************************************************************
00031 //                                                                     *
00032 //    Notes:                                                           *
00033 //                                                                     *
00034 //**********************************************************************
00035 
00036 #include <mytrace.h>
00037 
00038 #include "timer.h"
00039 
00040 
00041 using namespace Monitor::Utility;
00042 
00043 
00044 
00045 Timer::Timer()
00046 {
00047     _USEMYTRACE_("Timer::Timer()")
00048 
00049 
00050     restart();
00051 }
00052 
00053 
00054 
00055 Timer::~Timer()
00056 {
00057     _USEMYTRACE_("Timer::~Timer()")
00058 }
00059 
00060 
00061 
00062 unsigned
00063 Timer::interval()
00064 {
00065     _USEMYTRACE_("Timer::interval()")
00066 
00067 
00068     long    durationTime = long(clock() - intervalTime);
00069 
00070     durationTime *= 1000;
00071     durationTime /= CLK_TCK;
00072 
00073     return unsigned(durationTime);
00074 }
00075 
00076 
00077 
00078 unsigned
00079 Timer::restartInterval()
00080 {
00081     _USEMYTRACE_("Timer::restartInterval()")
00082 
00083 
00084     unsigned    restartInterval = interval();
00085 
00086     intervalTime = clock();
00087 
00088     return restartInterval;
00089 }
00090 
00091 
00092 
00093 unsigned
00094 Timer::duration()
00095 {
00096     _USEMYTRACE_("Timer::duration()")
00097 
00098 
00099     long    durationTime = long(clock() - startTime);
00100 
00101     durationTime *= 1000;
00102     durationTime /= CLK_TCK;
00103 
00104     return unsigned(durationTime);
00105 }
00106 
00107 
00108 
00109 unsigned
00110 Timer::restart()
00111 {
00112     _USEMYTRACE_("Timer::restart()")
00113 
00114 
00115     unsigned    restartDuration = duration();
00116 
00117     startTime = intervalTime = clock();
00118 
00119     return restartDuration;
00120 }

Generated on Wed Oct 29 20:51:59 2003 for Utility BC Common by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002