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
14template <typename T>
16{
17public:
18 using const_iterator = typename std::deque<T>::const_iterator;
19
20public:
23 {
24 }
25
29 int size() const {
30 return m_values.size();
31 }
32
36 T at(int pos) const {
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
84 return m_values.cbegin();
85 }
86
88 return m_values.cend();
89 }
90
91
92private:
93 int m_maxSize = 0;
94 std::deque<T> m_values;
95};
96
97#endif // KISHISTORYLIST_H
float value(const T *src, size_t ch)
const_iterator cend() const
int append(const T &value)
std::deque< T > m_values
int maxSize() const
typename std::deque< T >::const_iterator const_iterator
const_iterator cbegin() const
KisHistoryList(int size)
T at(int pos) const
int size() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129