NDEVR
API Documentation
RateLimiter.h
1#pragma once
2#include <NDEVR/TimeSpan.h>
3#include <NDEVR/Time.h>
4namespace NDEVR
5{
10 {
11 public:
17 : m_update_period(Time(0), seconds)
18 {}
19
23 void setCurrent(Time time)
24 {
25 m_update_period.setStartTime(time);
26 }
27
33 bool shouldFire(Time time, bool update_for_next_period = true)
34 {
35 if (time > m_update_period.endTime())
36 {
37 if (update_for_next_period)
38 m_update_period.setStartTime(time);
39 return true;
40 }
41 return false;
42 }
43 protected:
45 };
46}
RateLimiter(fltp08 seconds)
Constructs a RateLimiter with the specified minimum interval between firings.
Definition RateLimiter.h:16
bool shouldFire(Time time, bool update_for_next_period=true)
Checks whether enough time has elapsed to allow the action to fire.
Definition RateLimiter.h:33
TimeSpan m_update_period
The time span defining the minimum interval between firings.
Definition RateLimiter.h:44
void setCurrent(Time time)
Sets the current reference time, resetting the rate limiter period.
Definition RateLimiter.h:23
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
The primary namespace for the NDEVR SDK.
double fltp08
Defines an alias representing an 8 byte floating-point number.