5#include <IceUtil/Time.h>
14 const IceUtil::Time timestamp_invalid = IceUtil::Time::milliSeconds(-1);
20 _clock{clockType}, _startingTime{_clock.now()}, _time{
Duration::Seconds(0)}
41 _time = _clock.now() - _startingTime;
48 _startingTime = _clock.now();
55 return _time.isPositive();
69 throw std::logic_error{
"Timer was not stopped yet, cannot assess stopping time."};
72 return _startingTime + _time;
78 const auto duration =
stop();
90 m_time_mode{timeMode},
91 m_starting_time{
TimeUtil::GetTime(m_time_mode)},
92 m_time{::timestamp_invalid}
121 m_time = ::timestamp_invalid;
127 return m_time != ::timestamp_invalid;
133 return m_starting_time;
141 throw std::logic_error{
"Timer was not stopped yet, cannot assess stopping time."};
144 return m_starting_time + m_time;
StopWatch(armarx::TimeMode timeMode=armarx::TimeMode::SystemTime)
static IceUtil::Time measure(std::function< void(void)> subjectToMeasure, armarx::TimeMode timeMode=armarx::TimeMode::SystemTime)
IceUtil::Time startingTime() const
IceUtil::Time stoppingTime() const
provides utility functions for getting the current time
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
static IceUtil::Time GetTimeSince(IceUtil::Time referenceTime, TimeMode timeMode=TimeMode::VirtualTime)
Get the difference between the current time and a reference time.
Represents a point in time.
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Duration stop()
Stops the timer and returns the measured duration.
Duration stopAndReset()
Stops and resets the timer.
virtual ~StopWatch()
Destructs the StopWatch.
static Duration measure(std::function< void(void)> subjectToMeasure, ClockType clockType=ClockType::Virtual)
Measures the duration needed to execute the given lambda and returns it.
void reset()
Resets the timer.
bool isStopped() const
Returns whether the timer is stopped or is actively measuring time.
DateTime stoppingTime() const
Returns the date/time at stopping the timer.
DateTime startingTime() const
Returns the date/time at starting the timer.
StopWatch(ClockType clockType=ClockType::Virtual)
Constructs a StopWatch and starts it immediately.
TimeMode
Time mode to be used.
ClockType
Describes the type of clock.
This file offers overloads of toIce() and fromIce() functions for STL container types.