|
General IRI utilities
|
Implementation of a time class and operations. More...
#include <ctime.h>
Public Member Functions | |
| CTime () | |
| Constructor. More... | |
| CTime (double relative) | |
| Constructor with parameters. More... | |
| ~CTime () | |
| Destructor. More... | |
Get time functions | |
| unsigned long | seconds (void) |
| Get Seconds. More... | |
| unsigned long | nanoseconds (void) |
| Get Nanoseconds. More... | |
| double | getTimeInSeconds (void) |
| Get time in seconds. More... | |
| double | getTimeInMilliseconds (void) |
| Get time in milliseconds. More... | |
| long | getTimeInMicroseconds (void) |
| Get time in microseconds. More... | |
| timespec | getTimeInTimespec (void) |
| Get time in a timespec strcuture. More... | |
| timeval | getTimeInTimeval (void) |
| Get time in a timeval strcuture. More... | |
| time_t | getTimeInTime_t (void) |
| Get time in time_t. More... | |
| CTime | getRef () |
| Get the reference internal time. More... | |
| void | useRef (bool use) |
| sets if use or not the reference internal time More... | |
| bool | isRefUsed () |
| Get if is used or not the reference internal time. More... | |
Set Time | |
| void | set (double milliseconds=-1.0) |
| Sets the internal time. More... | |
| void | setRef () |
| Sets the internal reference time. More... | |
| void | resetRef () |
| Resets the reference time to the epoch. More... | |
| CTime | diff (CTime &t1, CTime &t0) |
Static Public Member Functions | |
Conversion functions | |
| static double | timespecToMs (timespec t) |
| conversion from timespec to milliseconds More... | |
| static timespec | msToTimespec (double ms) |
| conversion from milliseconds to timespec More... | |
Operators | |
| CTime | operator- (CTime &t) |
| Calculates time difference. More... | |
| CTime | operator+ (CTime &t) |
| Calculates time addition. More... | |
| CTime | operator/ (int div) |
| Calculates division by integer. More... | |
| bool | operator== (CTime &t) |
| Comparison operator. More... | |
| bool | operator!= (CTime &t) |
| Comparison operator. More... | |
| bool | operator> (CTime &t) |
| Comparison > operator. More... | |
| bool | operator< (CTime &t) |
| Comparison < operator. More... | |
| bool | operator>= (CTime &t) |
| Comparison >= operator. More... | |
| bool | operator<= (CTime &t) |
| Comparison <= operator. More... | |
| std::string | getString (void) |
| Gives a formatted string of this time. More... | |
| void | setFormat (ctimeformat format) |
| Sets output string format. More... | |
| ctimeformat | getFormat () |
| Gets output string format. More... | |
| std::ostream & | operator<< (std::ostream &o, CTime &t) |
| outputs time into a ostream More... | |
This class is designed to easily handle time within a program. It provides to the user a friendly interface in miliseconds and allows him to get the current time or convert any given time in any of the system dependant structures.
Each CTime object has a time since the Epoch. This class can also work with user provided times which are not referenced to the previous zero time, but can be used as timeouts or to monitor time between events.
Also, given a time in any format it provides a set of static functions to convert from that format to any other format in order to simplify the time handling issues without having to create an object of this class.
Finally, some basic arithmetic operators are provided (addition, substraction, ..) as well as relational operators are provided to perform basic operations on objects of this class.
| CTime::CTime | ( | ) |
| CTime::CTime | ( | double | relative | ) |
This constructor creates a new object of this class initialized with the value specified by the user. This value is a relative time in miliseconds.
| relative | the desired relative time in miliseconds. This value must be always positive since it represents time. |
| CTime::~CTime | ( | ) |
| unsigned long CTime::seconds | ( | void | ) |
| unsigned long CTime::nanoseconds | ( | void | ) |
| double CTime::getTimeInSeconds | ( | void | ) |
| double CTime::getTimeInMilliseconds | ( | void | ) |
| long CTime::getTimeInMicroseconds | ( | void | ) |
| timespec CTime::getTimeInTimespec | ( | void | ) |
This function returns the internal time using a timespec Linux structure. This may prove usefulll when using some Linux system functions which require this kind of structure.
The format of the timespec structure is as follows:
| timeval CTime::getTimeInTimeval | ( | void | ) |
This function returns the internalCTime CTime::zero; time using a timeval Linux structure. This may prove usefulll when using some Linux system functions which require this kind of structure.
The format of the timeval structure is as follows:
Definition at line 92 of file ctime.cpp.
Referenced by CEventServer::wait_all(), and CEventServer::wait_first().

| time_t CTime::getTimeInTime_t | ( | void | ) |
| CTime CTime::getRef | ( | ) |
This function returns the internal time as a CTime object
| bool CTime::isRefUsed | ( | ) |
| void CTime::set | ( | double | milliseconds = -1.0 | ) |
This function sets the internal time of the object once it is already created. If no parameter is passed (or a negative value is provided), the current computer time is used. Otherwise, the time provided by the user in milliseconds is used to initialize the internal time.
| milliseconds | the desired time in milliseconds to initialize the object. If this parameter is not provided or it has a negative value, the current computer time will be used. |
Definition at line 110 of file ctime.cpp.
Referenced by CLog::log(), CLog::log_vector(), CEventServer::wait_all(), and CEventServer::wait_first().

| void CTime::setRef | ( | ) |
| void CTime::resetRef | ( | ) |
This operator computes the difference between two time objects. The resulting time object may have a negative value because it represents a difference.
| t | a second time object used to perform the desired arithmetic operation. |
This operator computes the addition of two time objects. Depending on the values of the time objects to add, it is possible the resulting value overflows the internal attributes. In this case an exception is thrown.
| t | a second time object used to perform the desired arithmetic operation. |
| CTime CTime::operator/ | ( | int | div | ) |
This operator computes the division of the time object by an integer value. It can be usefull when computing averages of time objects. The value of the resulting time object is rounded to the nanoseconds.
| div | an integer value used to dived the internal time value. This value can be negative, in which case the resulting time object will also have a negative value. |
return a new object initialized with the time of the object itself divided by the provided integer.
| bool CTime::operator== | ( | CTime & | t | ) |
This operator is used to compare two time objects. If the two values are the same it returns true, and false otherwise.
| t | a second time object used to perform the comparation. |
| bool CTime::operator!= | ( | CTime & | t | ) |
This operator is used to compare two time objects. If the two values are the same it returns true, and false otherwise.
| t | a second time object used to perform the comparation. |
| bool CTime::operator> | ( | CTime & | t | ) |
| bool CTime::operator< | ( | CTime & | t | ) |
| bool CTime::operator>= | ( | CTime & | t | ) |
| bool CTime::operator<= | ( | CTime & | t | ) |
| std::string CTime::getString | ( | void | ) |
This function is similar to the << operator, but it returns a formatted string instead of outputting it into an ostream object. In this case, the output format is also determined by the current value of the print_format attribute.
Available formats are:
Seconds Nanoseconds ( ctf_secnano )
Date,Time ( ctf_datetime )
Milliseconds ( ctf_ms )
Definition at line 293 of file ctime.cpp.
Referenced by CLog::log(), and CLog::log_vector().

| void CTime::setFormat | ( | ctimeformat | format | ) |
This function sets the desired ouptu format for the getString() function and the << operator.
| format | an identifier of the desired format. It must belong to the ctimeformat enummeration type. Currently, the only supported formats are: |
For more information see the documentation on the ctimeformat enummeration type.
Definition at line 351 of file ctime.cpp.
Referenced by CLog::set_time_format().

| ctimeformat CTime::getFormat | ( | ) |
This function return the current output format being used in the getString() function and the << operator.
Definition at line 356 of file ctime.cpp.
Referenced by CLog::get_time_format().

|
static |
This function converts a time in a timespec structure into a double value with the same time in miliseconds. This function is static, so it can be used even if there exist no object of this class.
| t | a valid timespec structure already initialized. |
|
static |
This function converts a time in milliseconds into a timespec structure (seconds and nanoseconds). This function is static, so it can be used even if there exist no object of this class.
| ms | the time in milliseconds. |
|
friend |
This function is used to output formatted time information into a ostream object, such as the standard output or a file. This function uses the current value of the print_format attribute to provided teh desired output format.
Use the setFormat() and getFormat() functions to change and check the current output format respectively. See the documentation on the ctimeformat enummeration for information on the supported formats.
| o | the ostream object to ouput the formatted information. This can be the standard output or a file. |
| t | a time object whose time information is to be formatted and output into the ostream obejct. |
1.8.6