lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::TimerGuard< T > Class Template Reference

The TimeGuard wraps a timer object and pauses it when the guard object is destructed. More...

#include <Timer.h>

Public Member Functions

 TimerGuard (T *timer, bool start_timer=true)
 Construct a new TimeGuard object.
 
 ~TimerGuard ()
 When the timer guard object is destructed, it pauses the embedded timer object.
 
void pause ()
 Pause the guarded timer object if the timer is not a nullptr.
 
void resume ()
 Resume the guarded timer object if the timer is not a nullptr.
 

Private Attributes

T *const timer_
 The timer to be guarded.
 

Detailed Description

template<IsAnyOf< Timer, UserTimer > T>
class lucid::TimerGuard< T >

The TimeGuard wraps a timer object and pauses it when the guard object is destructed.

Useful for measuring the exact time spent in a block of code.

// Example usage
class MyClass {
private:
public:
void function_to_measure() {
TimerGuard guard(&timer_, true);
// Code to measure
}
// Return the total time elapsed, even across multiple calls
double time_elapsed() { return timer_.seconds(); }
};
std::chrono::duration< double >::rep seconds() const
Get read-only access to the number elapsed seconds of the timer.
Definition Timer.cpp:64
T *const timer_
The timer to be guarded.
Definition Timer.h:159
TimerGuard(T *timer, bool start_timer=true)
Construct a new TimeGuard object.
Definition Timer.cpp:95
Timer class using the steady clock (wall time).
Definition Timer.h:91

Constructor & Destructor Documentation

◆ TimerGuard()

template<IsAnyOf< Timer, UserTimer > T>
lucid::TimerGuard< T >::TimerGuard ( T * timer,
bool start_timer = true )
explicit

Construct a new TimeGuard object.

If timer is a nullptr, the guard will not do anything. If start_timer is true, the timer starts as soon as the guard is constructed. Otherwise, the method resume has to be called manually to start the timer.

Parameters
timera pointer to the timer object to be guarded. Must remain valid for the lifetime of the guard
start_timerwhether the timer should be started as soon as the guard is created

◆ ~TimerGuard()

template<IsAnyOf< Timer, UserTimer > T>
lucid::TimerGuard< T >::~TimerGuard ( )

When the timer guard object is destructed, it pauses the embedded timer object.

If the timer is a nullptr, this does nothing.


The documentation for this class was generated from the following files: