Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1// License: Apache 2.0. See LICENSE file in root directory.
2// Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3
4// Helper classes to keep track of time
5#pragma once
6
7#include "stopwatch.h"
8
9namespace utilities
10{
11 namespace time
12 {
13 // A timer counting backwards in time (vs forwards in the `stopwatch` class)
14 // It supply basic timer API, start, has_expired..
15 class timer
16 {
17 public:
18
19 timer(clock::duration timeout) : _delta(timeout), sw()
20 {
21 }
22
23 // Start timer
24 void start() const
25 {
26 sw.reset();
27 }
28
29 // Check if timer time expired
30 bool has_expired() const
31 {
32 return sw.get_start() + _delta <= clock::now();
33 }
34
35 // Force time expiration
37 {
38 sw.reset(clock::now() - (_delta + std::chrono::nanoseconds(100)));
39 }
40 protected:
41 clock::duration _delta;
43 };
44 }
45}
Definition: stopwatch.h:15
clock::time_point get_start() const
Definition: stopwatch.h:42
void reset(clock::time_point start_time=clock::now()) const
Definition: stopwatch.h:24
Definition: timer.h:16
void start() const
Definition: timer.h:24
void set_expired()
Definition: timer.h:36
bool has_expired() const
Definition: timer.h:30
clock::duration _delta
Definition: timer.h:41
stopwatch sw
Definition: timer.h:42
timer(clock::duration timeout)
Definition: timer.h:19
Definition: stabilized-value.h:12