9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* File: mn_strategy.hpp
* Created Date: Thursday February 17th 2022
* Author: yangzilong (yangzilong@objecteye.com)
* Description:
* -----
* Last Modified: Thursday, 17th February 2022 11:23:44 am
* Modified By: yangzilong (yangzilong@objecteye.com>)
* -----
* Copyright 2022
*/
#pragma once
// m帧里面出现了n帧才会报警, 降低报警的话可以提高n的值
#include <vector>
#include "helpers/logger.hpp"
template<typename T>
class MNStrategy
{
public:
MNStrategy(const unsigned _m = 0, const unsigned _n = 0)
: target_m_(_m)
, target_n_(_n)
, current_m_(0)
, current_n_(0)
{}
void set_target_m(const unsigned _val) noexcept
{
target_m_ = _val;
}
void set_target_n(const unsigned _val) noexcept
{
target_n_ = _val;
if (target_n_ >= target_m_)
LOG_ERROR("mn strategy `target_n` gt `target_m` ({} vs {})", _val, target_m_);
}
void update_m() noexcept
{
++current_m_;
}
void update_n() noexcept
{
++current_n_;
}
void reset_m() noexcept
{
current_m_ = 0;
}
void reset_n() noexcept
{
current_n_ = 0;
}
void try_reset() noexcept
{
if (current_m_ >= target_m_ && current_n_ < target_n_)
reset();
}
void reset() noexcept
{
reset_m();
reset_n();
}
bool check() const noexcept
{
return current_n_ >= target_n_;
}
bool update_and_check(const T &source, const T &target, const bool do_reset = false) noexcept
{
if (source == target)
update_n();
update_m();
try_reset();
return check_and_erase(do_reset);
}
bool update_and_check(const bool do_reset = false) noexcept
{
update_n();
update_m();
try_reset();
return check_and_erase(do_reset);
}
private:
bool check_and_erase(const bool do_reset = false) noexcept
{
bool check_status = check();
if (check_status && do_reset)
reset();
return check_status;
}
unsigned target_m_, target_n_;
unsigned current_m_, current_n_;
};
|