A simple clock class. More...
#include <Clock.hpp>
Public Types | |
enum | Error { UNKNOWN_ERROR, UNKNOWN_STATE } |
Public Member Functions | |
Clock () | |
Constructs a Clock object. | |
double | elapsed_time () const |
Returns the elapsed time in seconds. | |
void | pause () |
Pauses the time measurement. | |
void | reset () |
Resets the time measurement. | |
void | resume () |
Resumes the time measurement. | |
void | wait_milliseconds (double time) const |
Waits for a defined period of time. | |
void | wait_seconds (double time) const |
Waits for a defined period of time. | |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &output, Clock &clock) |
Writes the elapsed time of a Clock object to the given stream. |
A simple clock class.
This class provides means for time measurement and some functionality for waiting for a defined period of time. The time measurement can be paused and resumed.
Please be aware of the fact, that the wait_seconds() and wait_milliseconds() functions do not idle, i.e., they might be computationally expensive!
Here is an example which shows the Clock class in action:
#include <iostream> #include <TRTK/Clock.hpp> using namespace TRTK; using std::cout; int main() { Clock clock; clock.wait_seconds(1); cout << clock; clock.wait_seconds(2.123); cout << clock; clock.reset(); clock.wait_milliseconds(60); cout << clock; clock.reset(); cout << clock; Clock().wait_seconds(0.5); cout << clock; clock.pause(); Clock().wait_seconds(0.5); cout << clock; clock.resume(); Clock().wait_seconds(0.5); cout << clock; return 0; }
This is, what the output might look like:
Elapsed time: 1 seconds. Elapsed time: 3.124 seconds. Elapsed time: 0.06 seconds. Elapsed time: 0 seconds. Elapsed time: 0.501 seconds. Elapsed time: 0.501 seconds. Elapsed time: 1.001 seconds.
Definition at line 102 of file Clock.hpp.
double TRTK::Clock::elapsed_time | ( | ) | const |
Returns the elapsed time in seconds.
The elapsed time is the time interval between the point in time of the creation (and resetting, respectively) of this object and the point in time of calling this function.
ErrorObj | In case of an unexpected error, an error object is thrown and its error code is set to UNKNOWN_STATE . |
void TRTK::Clock::pause | ( | ) |
void TRTK::Clock::reset | ( | ) |
Resets the time measurement.
void TRTK::Clock::resume | ( | ) |
void TRTK::Clock::wait_milliseconds | ( | double | time ) | const |
Waits for a defined period of time.
[in] | time | time in milliseconds |
This function waits for time
milliseconds. This is done by continuously checking if the period of time has already elapsed. Thus, be aware, that this function might be computationally expensive!
void TRTK::Clock::wait_seconds | ( | double | time ) | const |
Waits for a defined period of time.
[in] | time | time in seconds |
This function waits for time
seconds. This is done by continuously checking if the period of time has already elapsed. Thus, be aware, that this function might be computationally expensive!
std::ostream & operator<< | ( | std::ostream & | output, |
Clock & | clock | ||
) | [related] |
Documentation generated by Doxygen