common/clocktimer.h

///////////////////////////////////////////////////////////////////////////////
// Filename: clocktimer.h
///////////////////////////////////////////////////////////////////////////////
// Purpose: class definition for "clocktimer", a timer which measures
//          real time
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date     Time     Name      Description   
// -------- -------- --------  ------------------------------------------------
// 96/02/06 01:01:29 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////

#ifndef __CLOCKTIMER_H__
#define __CLOCKTIMER_H__


// Feature test switches ///////////////////////////// Feature test switches //
    /* NONE */


// System headers /////////////////////////////////////////// System headers //

#include <sys/time.h>
#include <iostream.h>




// Local headers ///////////////////////////////////////////// Local headers //

#include "../common.h"



// Macros /////////////////////////////////////////////////////////// Macros //
    /* NONE */



// File scope objects /////////////////////////////////// File scope objects //
    /* NONE */



// External variables, functions, and classes ///////////// External objects //
    /* NONE */



// Signal catching functions ///////////////////// Signal catching functions //
    /* NONE */



// Structures, unions, and class definitions /////////////////// Definitions //


/*
 * The class "clocktimer" is useful for measuring real clock time.
 * It uses the UNIX function gettimeofday() to get the needed information.
 */

class clocktimer
{

public:
    // constructor, initialize everything
    clocktimer(void):gottime(false),started(false){}

    // destructor, nothing to do
    ~clocktimer(void){}

    // return the number of measured seconds or -1 for an error
    long secs(void);

    // return the number of measured microseconds or -1 for an error
    long usecs(void);

    // start measurement
    bool start(void);

    // end measurement
    bool end(void);

private:
    bool gottime;       // do we have a measured time we can return?
    bool started;       // is the timer started?
    timeval tstart;     // the start time
    timeval tresult;    // the result time
};