SensESP
3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
expiring_value.h
Go to the documentation of this file.
1
#ifndef SENSESP_SYSTEM_EXPIRING_VALUE_H_
2
#define SENSESP_SYSTEM_EXPIRING_VALUE_H_
3
4
namespace
sensesp
{
5
15
template
<
typename
T>
16
class
ExpiringValue
{
17
public
:
18
ExpiringValue
()
19
: value_{},
20
expiration_duration_{1000},
21
last_update_{0},
22
expired_value_{T{}} {}
23
24
ExpiringValue
(T value,
unsigned
long
expiration_duration, T expired_value)
25
: value_{value},
26
expiration_duration_{expiration_duration},
27
expired_value_{expired_value},
28
last_update_{millis()} {}
29
30
void
update
(T value) {
31
value_ = value;
32
last_update_ = millis();
33
}
34
35
T
get
()
const
{
36
if
(!
is_expired
()) {
37
return
value_;
38
}
else
{
39
return
expired_value_;
40
}
41
}
42
43
bool
is_expired
()
const
{
44
return
millis() - last_update_ > expiration_duration_;
45
}
46
47
private
:
48
T value_;
49
T expired_value_;
50
unsigned
long
expiration_duration_;
51
unsigned
long
last_update_;
52
};
53
54
}
// namespace sensesp
55
56
#endif
// SENSESP_SRC_SENSESP_SYSTEM_EXPIRING_VALUE_H_
sensesp::ExpiringValue
Value container that keeps track of its expiration time.
Definition
expiring_value.h:16
sensesp::ExpiringValue::ExpiringValue
ExpiringValue()
Definition
expiring_value.h:18
sensesp::ExpiringValue::update
void update(T value)
Definition
expiring_value.h:30
sensesp::ExpiringValue::ExpiringValue
ExpiringValue(T value, unsigned long expiration_duration, T expired_value)
Definition
expiring_value.h:24
sensesp::ExpiringValue::get
T get() const
Definition
expiring_value.h:35
sensesp::ExpiringValue::is_expired
bool is_expired() const
Definition
expiring_value.h:43
sensesp
Definition
sensesp.cpp:7
src
sensesp
system
expiring_value.h
Generated by
1.12.0