Sources/Timer.cp

/*
    File:       Timer.cp
 
    Contains:   TTimer is a simple timing class that could provide both 10 lap time values as well as
                final values.
                TTimer.cp contains the TTimer member functions.
 
    Written by: Kent Sandvik    
 
    Copyright:  Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                8/18/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
#ifndef _TIMER_
#include "Timer.h"
#endif
 
 
// _________________________________________________________________________________________________________ //
//  TTimer Class definitions.
 
//  CONSTRUCTORS AND DESTRUCTORS
#pragma segment Timer
TTimer::TTimer()
// Default constructor.
{
    this->Reset();
}
 
 
#pragma segment Timer
TTimer::~TTimer()
// Default destructor -- empty for the time being.
{
}
 
 
//  MAIN INTERFACES
#pragma segment Timer
void TTimer::Start()
// Start the timer.
{
    fStartTick = ::TickCount();
}
 
 
#pragma segment Timer
void TTimer::Stop()
// Stop the timer.
{
    fStopTick = ::TickCount();
}
 
#pragma segment Timer
void TTimer::Reset()
// Reset the internal count to zero.
{
    fStartTick = fStopTick = 0;
}
 
 
#pragma segment Timer
void TTimer::SetLap(short index)
// Set a lap time, where we have 10 lap registers.
{
    VASSERT(index < 11, ("Index is bigger than 10 = %d\n", index));
    if (index < 11)
        fLapIndex[index] = ::TickCount() - fStartTick;
}
 
 
#pragma segment Timer
long TTimer::GetLap(short index)
// Get the lap time, we have 10 lap registers.
{
    VASSERT(index < 11, ("Index is bigger than 10 = %d\n", index));
    if (index < 11)
        return fLapIndex[index];
    else
        return 0;
}
 
 
#pragma segment Timer
long TTimer::GetLap()
// Get a temporary lap time, independent of the registers.
{
    long temp = ::TickCount();
    return (temp - fStartTick);
}
 
 
#pragma segment Timer
long TTimer::GetTicks()
// Get tick count from when we started the timer.
{
    return (fStopTick - fStartTick);
}
 
 
#pragma segment Timer
float TTimer::GetSeconds()
// Get N seconds from the point of time when we started the timer.
{
    return ((float)(fStopTick - fStartTick) / 60L);
}
 
 
// _________________________________________________________________________________________________________ //
 
 
/*  Change History (most recent last):
  No        Init.   Date        Comment
  1         khs     12/14/92    New file
  2         khs     1/3/93      Cleanup
*/