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 | |
| time & | reset (double offset, bool is_since_now=true) |
| time & | reset (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) | |
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.
| 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.
| 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.
| 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.
| 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.
| t | a reference to a time object with which the created object will be syncronised with. |
| long double smtk::time::diff | ( | long double * | t = 0 |
) | [inline] |
| double smtk::time::diff_double | ( | double * | t = 0 |
) | [inline] |
get time difference
| 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). |
| long double smtk::time::get | ( | struct timeval * | tv | ) | [inline] |
| long double smtk::time::get | ( | long double * | dif = 0 |
) | [inline] |
get time
| 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). |
| double smtk::time::get_double | ( | double * | dif = 0 |
) | [inline] |
get time
| 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). |
| long double smtk::time::get_offset | ( | void | ) | const [inline] |
get the offset
#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.
| 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 |
| 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.
| 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 |
1.5.2