Krita Source Code Documentation
Loading...
Searching...
No Matches
KisHistoryList.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2024 Dmitry Kazakov <dimula73@gmail.com>
3
*
4
* SPDX-License-Identifier: GPL-2.0-or-later
5
*/
6
7
#ifndef KISHISTORYLIST_H
8
#define KISHISTORYLIST_H
9
10
#include "
kis_debug.h
"
11
#include "
kis_assert.h
"
12
#include <deque>
13
14
template
<
typename
T>
15
class
KisHistoryList
16
{
17
public
:
18
using
const_iterator
=
typename
std::deque<T>::const_iterator;
19
20
public
:
21
KisHistoryList
(
int
size
)
22
:
m_maxSize
(
size
)
23
{
24
}
25
29
int
size
()
const
{
30
return
m_values
.size();
31
}
32
36
T
at
(
int
pos)
const
{
37
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE
(pos <
size
(), T());
38
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE
(pos >= 0, T());
39
40
return
m_values
.at(pos);
41
}
42
53
int
append
(
const
T&
value
) {
54
auto
it = std::find(
m_values
.begin(),
m_values
.end(),
value
);
55
56
if
(it !=
m_values
.end()) {
57
std::rotate(
m_values
.begin(), it, std::next(it));
58
}
else
{
59
m_values
.push_front(
value
);
60
if
(
int
(
m_values
.size()) >
m_maxSize
) {
61
m_values
.pop_back();
62
}
63
}
64
65
// return the index of just added color (always 0)
66
return
0;
67
}
68
72
void
clear
() {
73
m_values
.clear();
74
}
75
79
int
maxSize
()
const
{
80
return
m_maxSize
;
81
}
82
83
const_iterator
cbegin
()
const
{
84
return
m_values
.cbegin();
85
}
86
87
const_iterator
cend
()
const
{
88
return
m_values
.cend();
89
}
90
91
92
private
:
93
int
m_maxSize
= 0;
94
std::deque<T>
m_values
;
95
};
96
97
#endif
// KISHISTORYLIST_H
value
float value(const T *src, size_t ch)
Definition
JPEGXLImport.cpp:93
KisHistoryList
Definition
KisHistoryList.h:16
KisHistoryList::cend
const_iterator cend() const
Definition
KisHistoryList.h:87
KisHistoryList::append
int append(const T &value)
Definition
KisHistoryList.h:53
KisHistoryList::m_values
std::deque< T > m_values
Definition
KisHistoryList.h:94
KisHistoryList::maxSize
int maxSize() const
Definition
KisHistoryList.h:79
KisHistoryList::const_iterator
typename std::deque< T >::const_iterator const_iterator
Definition
KisHistoryList.h:18
KisHistoryList::clear
void clear()
Definition
KisHistoryList.h:72
KisHistoryList::cbegin
const_iterator cbegin() const
Definition
KisHistoryList.h:83
KisHistoryList::KisHistoryList
KisHistoryList(int size)
Definition
KisHistoryList.h:21
KisHistoryList::at
T at(int pos) const
Definition
KisHistoryList.h:36
KisHistoryList::m_maxSize
int m_maxSize
Definition
KisHistoryList.h:93
KisHistoryList::size
int size() const
Definition
KisHistoryList.h:29
kis_assert.h
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition
kis_assert.h:129
kis_debug.h
libs
global
KisHistoryList.h
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52