53 lines
965 B
C++
53 lines
965 B
C++
#ifndef ZTD_TIME_HPP
|
|
#define ZTD_TIME_HPP
|
|
|
|
#include <sys/time.h>
|
|
|
|
/*! @file time.hpp
|
|
* @brief Time measuring and managing
|
|
*/
|
|
|
|
namespace ztd
|
|
{
|
|
//! Measure time intervals
|
|
/*! Class for quick and easy time measurement
|
|
*/
|
|
class timer
|
|
{
|
|
public:
|
|
timer();
|
|
|
|
//! Get measured time
|
|
/*!
|
|
If the timer was stopped, returns the time between start and stop\n
|
|
If the timer is still running, returns time between start and now
|
|
@return
|
|
In seconds, µs granularity
|
|
*/
|
|
double time() const;
|
|
|
|
//! Start the timer
|
|
/*!
|
|
If the timer was already running, resets the timer to this point
|
|
*/
|
|
void start();
|
|
//! Stop the timer
|
|
/*!
|
|
Store time difference
|
|
@return
|
|
@b true if timer was running, @b false otherwise
|
|
*/
|
|
bool stop();
|
|
|
|
//! Reset the timer
|
|
void reset();
|
|
|
|
private:
|
|
bool m_stopped;
|
|
double m_sec;
|
|
struct timeval m_start, m_end;
|
|
};
|
|
}
|
|
|
|
|
|
#endif //ZTD_TIME_HPP
|