Vanetza
 
Loading...
Searching...
No Matches
cbf_counter.cpp
1#include <vanetza/geonet/cbf_counter.hpp>
2#include <cassert>
3
4namespace vanetza
5{
6namespace geonet
7{
8
9void CbfCounterImmortal::add(const id_type& id)
10{
11 ++m_counters[id];
12}
13
14void CbfCounterImmortal::increment(const id_type& id)
15{
16 ++m_counters[id];
17}
18
19auto CbfCounterImmortal::counter(const id_type& id) const -> counter_type
20{
21 counter_type count = 0;
22 auto found = m_counters.find(id);
23 if (found != m_counters.end()) {
24 count = found->second;
25 }
26 return count;
27}
28
29void CbfCounterContending::add(const id_type& id)
30{
31 m_counters[id] = 1;
32}
33
34void CbfCounterContending::remove(const id_type& id)
35{
36 m_counters.erase(id);
37}
38
39CbfCounterFading::CbfCounterFading(Runtime& rt, Clock::duration lifetime) :
40 m_counters(rt)
41{
42 m_counters.set_lifetime(lifetime);
43}
44
45void CbfCounterFading::add(const id_type& id)
46{
47 ++m_counters.refresh(id);
48 m_counters.drop_expired();
49}
50
51void CbfCounterFading::increment(const id_type& id)
52{
53 ++m_counters.get_value(id);
54}
55
56auto CbfCounterFading::counter(const id_type& id) const -> counter_type
57{
58 auto* count = m_counters.get_value_ptr(id);
59 return count ? *count : 0;
60}
61
62} // namespace geonet
63} // namespace vanetza
void add(const id_type &) override
Definition: cbf_counter.cpp:29
void remove(const id_type &) override
Definition: cbf_counter.cpp:34
void increment(const id_type &) override
Definition: cbf_counter.cpp:51
void add(const id_type &) override
Definition: cbf_counter.cpp:45
counter_type counter(const id_type &) const override
Definition: cbf_counter.cpp:56
counter_type counter(const id_type &) const override
Definition: cbf_counter.cpp:19
void add(const id_type &) override
Definition: cbf_counter.cpp:9
void increment(const id_type &) override
Definition: cbf_counter.cpp:14
mapped_type & refresh(const key_type &key)
mapped_type & get_value(const key_type &key)