#include <Time.h>
Public Member Functions | |
Time () | |
Initializes this class with a time of 0. | |
Time (const Time &t) | |
Time (int seconds, int microseconds) | |
Initializes this class with the time specified. | |
int | getSec () const |
Returns seconds. | |
int | getuSec () const |
Returns microseconds. | |
int | getTotaluSec () const |
Returns the total time in microseconds. | |
int | getTotalmSec () const |
Returns the total time in milliseconds. | |
void | setSec (int seconds) |
Sets seconds. | |
void | setuSec (int microseconds) |
Sets microseconds. | |
Time | diff (const Time &rhs) const |
Returns the absolute value of the difference between these two times. | |
std::string | toString () const |
Returns a string representation of this time in seconds, for example this might return 5.002052 if there was 5 seconds and 2052 microseconds. | |
Time & | operator= (const Time &rhs) |
bool | operator== (const Time &rhs) const |
Equality operator that works as expected. | |
bool | operator!= (const Time &rhs) const |
Inequality operator that works as expected. | |
bool | operator< (const Time &rhs) const |
Less-than operator that works as expected. | |
bool | operator<= (const Time &rhs) const |
Less-or-equal-than operator that works as expected. | |
bool | operator> (const Time &rhs) const |
Greater-than operator that works as expected. | |
bool | operator>= (const Time &rhs) const |
Greater-or-equal-than operator that works as expected. | |
Time | operator+ (int rhs) const |
Time addition, adding microseconds of time. | |
Time & | operator+= (int rhs) |
Time addition, adding microseconds of time to this object. | |
Time & | operator+= (const Time &rhs) |
Time addition that works as expected to add two times. | |
Time | operator+ (const Time &rhs) const |
Time addition that works as expected. | |
Time | operator- (const Time &rhs) const |
Time subtraction that works as expected. | |
Time & | operator *= (int rhs) |
Scalar multiplication operator. | |
Time | operator * (int rhs) const |
Scalar multiplication operator. | |
Time & | operator/= (int rhs) |
Scalar division operator. | |
Time | operator/ (int rhs) const |
Scalar division operator. | |
Protected Member Functions | |
void | normalize () |
make sure that microsec stays under a second, adding to sec if needed. | |
void | convert () |
Temporarily converts the time values into a different format -- don't know what to call it. |
The time is always proper ("normalized"), meaning that 999,999 is the highest value for microseconds. Setting a value higher than this will increase seconds.
To get the current time, check out the methods Timer::getCurrentTime and Timer::getAbsoluteTime.
GNE::Time::Time | ( | int | seconds, | |
int | microseconds | |||
) |
Initializes this class with the time specified.
The given time need not be normalized as this will be done automatically. For example it is acceptable to pass in 0 seconds and 2,000,000 microseconds and it will be normalized to 2 seconds.
void GNE::Time::convert | ( | ) | [protected] |
Temporarily converts the time values into a different format -- don't know what to call it.
Just look at the formula. It's needed for things like division of negative numbers. The method normalize MUST be called before the method completes.
int GNE::Time::getTotalmSec | ( | ) | const |
Returns the total time in milliseconds.
Useful in the same situations as getTotaluSec, but can represent larger time differences. A 32-bit integer millisecond value can represent a time of about +/- 24.855 days.
int GNE::Time::getTotaluSec | ( | ) | const |
Returns the total time in microseconds.
This function can be useful for displaying the time represented by this object in a custom format (such as xxxxx ms or xxxxx us, rather than xxx.xxx seconds). Since an int is returned, +/- 2147.483648 seconds is the maximum amount of time that can be represented in a 32-bit integer in microseconds.
Because of this time limitation, only small time differences can be represented. If a larger time difference is expected, getTotalmSec may be a better choice.
Time subtraction that works as expected.
You might get negative values out of this. Sometimes Time::diff will be what you want, instead.
void GNE::Time::setuSec | ( | int | microseconds | ) |
Sets microseconds.
microseconds | the new value for microseconds. If this value is greater that 999,999, it will be normalized and the value of seconds will increase. |