KDStateMachineEditor API Documentation
2.1
Loading...
Searching...
No Matches
src
core
util
ringbuffer.h
Go to the documentation of this file.
1
/*
2
This file is part of the KDAB State Machine Editor Library.
3
4
SPDX-FileCopyrightText: 2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5
Author: Kevin Funk <kevin.funk@kdab.com>
6
7
SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8
9
Licensees holding valid commercial KDAB State Machine Editor Library
10
licenses may use this file in accordance with the KDAB State Machine Editor
11
Library License Agreement provided with the Software.
12
13
Contact info@kdab.com if any conditions of this licensing are not clear to you.
14
*/
15
16
// krazy:excludeall=inline as this is a template
17
#ifndef KDSME_UTIL_RINGBUFFER_H
18
#define KDSME_UTIL_RINGBUFFER_H
19
20
#include <QQueue>
21
#include <QList>
22
23
namespace
KDSME
{
24
37
template
<
class
T>
38
class
RingBuffer
39
{
40
public
:
44
explicit
RingBuffer
(
int
capacity = 10)
45
: m_capacity(capacity)
46
{
47
}
48
55
void
setCapacity
(
int
capacity)
56
{
57
Q_ASSERT(capacity > 0);
58
m_capacity = capacity;
59
cleanup();
60
}
61
65
void
enqueue
(T t)
66
{
67
m_entries.enqueue(t);
68
cleanup();
69
}
70
74
void
clear
()
75
{
76
m_entries.clear();
77
}
78
79
inline
const
T &
at
(
int
i)
const
80
{
81
return
m_entries.at(i);
82
}
83
inline
int
size
()
const
84
{
85
return
m_entries.size();
86
}
91
inline
T
head
()
const
92
{
93
return
m_entries.head();
94
}
99
inline
T
last
()
const
100
{
101
return
m_entries.last();
102
}
103
inline
QList<T>
entries
()
const
104
{
105
return
m_entries;
106
}
107
108
private
:
109
void
cleanup()
110
{
111
while
(m_entries.size() > m_capacity) {
112
m_entries.dequeue();
113
}
114
}
115
116
QQueue<T> m_entries;
117
int
m_capacity;
118
};
119
120
}
121
122
#endif
KDSME::RingBuffer
Definition
ringbuffer.h:39
KDSME::RingBuffer::RingBuffer
RingBuffer(int capacity=10)
Definition
ringbuffer.h:44
KDSME::RingBuffer::setCapacity
void setCapacity(int capacity)
Definition
ringbuffer.h:55
KDSME::RingBuffer::clear
void clear()
Definition
ringbuffer.h:74
KDSME::RingBuffer::at
const T & at(int i) const
Definition
ringbuffer.h:79
KDSME::RingBuffer::size
int size() const
Definition
ringbuffer.h:83
KDSME::RingBuffer::head
T head() const
Definition
ringbuffer.h:91
KDSME::RingBuffer::last
T last() const
Definition
ringbuffer.h:99
KDSME::RingBuffer::enqueue
void enqueue(T t)
Definition
ringbuffer.h:65
KDSME::RingBuffer::entries
QList< T > entries() const
Definition
ringbuffer.h:103
KDSME
Definition
mainwindow.h:21
© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDStateMachineEditor
Create Qt State Machine metacode using a graphical user interface
https://github.com/KDAB/KDStateMachineEditor
Generated on Tue Jul 15 2025 15:21:47 for KDStateMachineEditor API Documentation by doxygen 1.9.8