smtk::time Class Reference

wall clock time class More...

List of all members.

Public Member Functions

long double diff (long double *t=0)
 get time difference
double diff_double (double *t=0)
 get time difference
long double get (struct timeval *tv)
 get time
long double get (long double *dif=0)
 get time
double get_double (double *dif=0)
 get time
long double get_offset (void) const
 get the offset
timereset (double offset, bool is_since_now=true)
timereset (long double offset=0, bool is_since_now=true)
 time (time &t)
 copy constructor
 time (float offset, bool is_since_now=true)
 time (double offset, bool is_since_now=true)
 time (long double offset=0, bool is_since_now=true)


Detailed Description

wall clock time class

Examples: time_get.cpp, time_diff.cpp, time_get_diff.cpp, copy_time.cpp.

This class is a small gettimeofday(2) wrapper. It provides methods to get absolute and relative time in floating point numbers. If you interested in getting time to the full resolution of that provided by gettimeofday(2) you should use the long double values. Full resolution is good when computing small time differences when the values of each time is large, but if you just need small changes in time you can use floats.

Though the UNIX struct timeval (or like on MS Windows) has the same number of bits as a double (at the time of writing this), but because of the exponent there is less room to store the information. There is not enough precision to represent all the digits from a struct timeval in a double, so the next size up, a long double is the floating-point number needed to store all this time information for a struct timeval.


Constructor & Destructor Documentation

time::time ( long double  offset = 0,
bool  is_since_now = true 
)

By default (with no arguments set) this will make a time object that will have time equal to zero at the time this constructor is called.

Parameters:
offset Sets the time that is added to the time values returned in get().
is_since_now If true, the time returned from get() is the time in seconds since this object was constructed plus offset, or else if this is false the time returned from get() will be the UNIX time in seconds plus the offset. UNIX time is measured from the date January 1, 1970. See http://en.wikipedia.org/wiki/Unix_timestamp

time::time ( double  offset,
bool  is_since_now = true 
)

By default (with no arguments set) this will make a time object that will have time equal to zero at the time this constructor is called.

Parameters:
offset Sets the time that is added to the time values returned in get().
is_since_now If true, the time returned from get() is the time in seconds since this object was constructed plus offset, or else if this is false the time returned from get() will be the UNIX time in seconds plus the offset. UNIX time is measured from the date January 1, 1970. See http://en.wikipedia.org/wiki/Unix_timestamp

time::time ( float  offset,
bool  is_since_now = true 
)

By default (with no arguments set) this will make a time object that will have time equal to zero at the time this constructor is called.

Parameters:
offset Sets the time that is added to the time values returned in get().
is_since_now If true, the time returned from get() is the time in seconds since this object was constructed plus offset, or else if this is false the time returned from get() will be the UNIX time in seconds plus the offset. UNIX time is measured from the date January 1, 1970. See http://en.wikipedia.org/wiki/Unix_timestamp

time::time ( time t  ) 

copy constructor

Creates a smtk::time object that is syncronised with another object.

Parameters:
t a reference to a time object with which the created object will be syncronised with.


Member Function Documentation

long double smtk::time::diff ( long double *  t = 0  )  [inline]

get time difference

Parameters:
t is a pointer user provided data to put the time in seconds, as would be computed by a call to get(). This is provided to decrease the number of calls to get the system time with gettimeofday(2).
Returns:
the time as a long double in seconds since the last call to diff() or since this object was constructed or since the last call to reset() or the last call to any of the get_* methods that the user got the difference time, which ever is shortest.

double smtk::time::diff_double ( double *  t = 0  )  [inline]

get time difference

Parameters:
t is a pointer user provided data to put the time in seconds, as would be computed by a call to get_double(). This is provided to decrease the number of calls to get the system time with gettimeofday(2).
Returns:
the time as a double in seconds since the last call to diff() or since this object was constructed or since the last call to reset(), which ever is shortest.

long double smtk::time::get ( struct timeval *  tv  )  [inline]

get time

Parameters:
tv is a pointer to a struct timeval that will be written to with the time that is also returned as a long double.
Returns:
the time as a long double in seconds.

long double smtk::time::get ( long double *  dif = 0  )  [inline]

get time

Parameters:
dif is a pointer user provided data to put the difference in time since the last call to diff() or since this object was constructed or since the last call to reset() or the last call to any of the get_* methods that the user got the difference time, which ever is shortest. If diff=0 the difference will not be computed. This is provided to decrease the number of calls to get the system time with gettimeofday(2).
Returns:
the time as a long double in seconds.

double smtk::time::get_double ( double *  dif = 0  )  [inline]

get time

Parameters:
dif is a pointer user provided data to put the difference in time since the last call to diff() or since this object was constructed or since the last call to reset() or the last call to any of the get_* methods that the user got the difference time, which ever is shortest. If diff=0 the difference will not be computed. This is provided to decrease the number of calls to get the system time with gettimeofday(2).
Returns:
the time as a double in seconds.

long double smtk::time::get_offset ( void   )  const [inline]

get the offset

Returns:
the offset time as a long double in seconds. This offset is the time is added to the current UNIX time. You can make a time object that gets the same values of time as another object by using this returned value like the following example
#include <stdio.h>
#include <smtk.h>

int main(void)
{
  smtk::time time1;

  // Object time2 will be in sync with object time1.
  smtk::time time2(time1.get_offset(), false);

  int i;
  for(i=0;i<30;i++)
    {
      long double t1 = time1.get();
      long double t2 = time2.get();
      printf("%6.6Le\n%6.6Le\n",t1,t2);
    }

  fprintf(stderr, "\n"
          "The calls to time1.get() and time2.get() can't\n"
          "happen at the same time, but if they could they\n"
          "would return exactly the same times.\n\n"
          "Try running: `./copy_time | quickplot'\n\n");

  return 0;
}

time & time::reset ( double  offset,
bool  is_since_now = true 
)

By default (with no arguments set) this will make the time object have time equal to zero at the time this method is called.

Parameters:
offset Sets the time that is added to the time values returned in get().
is_since_now If true, the time returned from get() is the time in seconds since this call plus offset, or else if this is false the time returned from get() will be the UNIX time in seconds plus the offset. UNIX time is measured from the date January 1, 1970. See http://en.wikipedia.org/wiki/Unix_timestamp
Returns:
a reference to the time object

time & time::reset ( long double  offset = 0,
bool  is_since_now = true 
)

By default (with no arguments set) this will make the time object have time equal to zero at the time this method is called.

Parameters:
offset Sets the time that is added to the time values returned in get().
is_since_now If true, the time returned from get() is the time in seconds since this call plus offset, or else if this is false the time returned from get() will be the UNIX time in seconds plus the offset. UNIX time is measured from the date January 1, 1970. See http://en.wikipedia.org/wiki/Unix_timestamp
Returns:
a reference to the time object


The documentation for this class was generated from the following files:
Generated on Sat Aug 11 22:25:58 2007 for Simulation Toolkit (SmTk) by  doxygen 1.5.2