Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 15056, A neat timer function object

by Robert Mitchell Email: robertmitchell@yahoo.com


Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For C++Builder, Version 2.0  to 5.0 11 downloads
Copyright: Open Source or other


Size: 0 bytes
Updated on Fri, 14 Jul 2000 00:00:00 GMT
Originally uploaded on Fri, 14 Jul 2000 00:00:00 GMT
Description
Tim

A timer implemented as a function object


I view function objects in their purest form as functions with data members which is exactly how this function object is
implemented.
Each Tim object contains a start, stop and elapsed time.
Using this approach, a sequence of timed events can be calculated and stored in an array of Tims.
There is also the option of pausing for a specified number of seconds.



#include
#include
#include
class Tim{

public:
void operator () (bool); // start and stop
void operator () (int); // pause

time_t Elapsed();// {return elapsed;};
void Reset();// {start=0; stop=0; elapsed=0;};

private:
time_t start,
stop,
elapsed;

};

void
Tim::operator () (bool com)
{
if(com)
start=time(0);

if(!com) {
stop=time(0);
elapsed= stop -start;
}
};

void
Tim::operator () (int pause)
{
start =time(0);
while(time(0) ;
};

inline time_t
Tim::Elapsed()
{
return elapsed;
};

inline void
Tim::Reset()
{
start=0; stop=0; elapsed=0;
};

// for a driver and further code see www.geocities.com/robertmitchell_99

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03