Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
Loading...
Searching...
No Matches
periodic-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 "timer.h"
8
9namespace utilities
10{
11 namespace time
12 {
13 // A timer class that wakes up every <delta> seconds/minutes/etc. on its bool operator:
14 // Usage example:
15 // periodic_timer timer( chrono::seconds( 5 ));
16 // while(1) {
17 // if( timer ) { /* do something every 5 seconds */ }
18 // }
20 {
21 public:
22
23 periodic_timer(clock::duration delta)
24 : _delta(delta)
25 {
26 }
27
28 // Allow use of bool operator for checking time expiration and re trigger when time expired
29 operator bool() const
30 {
31 if (_delta.has_expired())
32 {
33 _delta.start();
34 return true;
35 }
36 return false;
37 }
38
39 // Force time expiration
41 {
43 }
44 protected:
46 };
47 }
48}
Definition: periodic-timer.h:20
periodic_timer(clock::duration delta)
Definition: periodic-timer.h:23
timer _delta
Definition: periodic-timer.h:45
void set_expired()
Definition: periodic-timer.h:40
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
Definition: stabilized-value.h:12