KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gl_reset_budget.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GL_RESET_BUDGET_H
21#define GL_RESET_BUDGET_H
22
23#include <chrono>
24#include <cstddef>
25#include <deque>
26
27namespace KIGFX
28{
29
38{
39public:
40 using CLOCK = std::chrono::steady_clock;
41
42 GL_RESET_BUDGET( size_t aMaxResets, CLOCK::duration aWindow ) :
43 m_maxResets( aMaxResets ),
44 m_window( aWindow )
45 {
46 }
47
53 bool RecordReset( CLOCK::time_point aNow )
54 {
55 while( !m_resets.empty() && aNow - m_resets.front() >= m_window )
56 m_resets.pop_front();
57
58 m_resets.push_back( aNow );
59
60 return m_resets.size() <= m_maxResets;
61 }
62
63private:
65 CLOCK::duration m_window;
66 std::deque<CLOCK::time_point> m_resets;
67};
68
69} // namespace KIGFX
70
71#endif // GL_RESET_BUDGET_H
CLOCK::duration m_window
std::chrono::steady_clock CLOCK
GL_RESET_BUDGET(size_t aMaxResets, CLOCK::duration aWindow)
bool RecordReset(CLOCK::time_point aNow)
Record a reset.
std::deque< CLOCK::time_point > m_resets
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30