Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSortedHistoryList< T > Class Template Reference

#include <KisSortedHistoryList.h>

Public Types

using compare_less = std::function<bool(const T&, const T&)>
 
using const_iterator = typename std::vector<T>::const_iterator
 

Public Member Functions

int append (const T &value)
 
at (int pos) const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
 KisSortedHistoryList (int size)
 
int maxSize () const
 
void setCompareLess (compare_less func)
 
int size () const
 

Private Member Functions

bool resortList ()
 

Private Attributes

compare_less m_compareLess
 
KisHistoryList< T > m_list
 
std::vector< T > m_sortedList
 

Detailed Description

template<typename T>
class KisSortedHistoryList< T >

Definition at line 14 of file KisSortedHistoryList.h.

Member Typedef Documentation

◆ compare_less

template<typename T >
using KisSortedHistoryList< T >::compare_less = std::function<bool(const T&, const T&)>

Definition at line 18 of file KisSortedHistoryList.h.

◆ const_iterator

template<typename T >
using KisSortedHistoryList< T >::const_iterator = typename std::vector<T>::const_iterator

Definition at line 17 of file KisSortedHistoryList.h.

Constructor & Destructor Documentation

◆ KisSortedHistoryList()

template<typename T >
KisSortedHistoryList< T >::KisSortedHistoryList ( int size)
inline

Definition at line 21 of file KisSortedHistoryList.h.

22 : m_list(size)
23 {
24 }
KisHistoryList< T > m_list

Member Function Documentation

◆ append()

template<typename T >
int KisSortedHistoryList< T >::append ( const T & value)
inline

Add an element to the history list

Returns
the position of the inserted element in the sorted list

Definition at line 48 of file KisSortedHistoryList.h.

48 {
49 int newElementIndex = m_list.append(value);;
50 if (resortList()) {
51 auto it = std::find(m_sortedList.begin(), m_sortedList.end(), value);
53 it = m_sortedList.begin();
54 }
55 newElementIndex = std::distance(m_sortedList.begin(), it);
56 }
57
58 return newElementIndex;
59 }
float value(const T *src, size_t ch)
std::vector< T > m_sortedList
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References KIS_SAFE_ASSERT_RECOVER, KisSortedHistoryList< T >::m_list, KisSortedHistoryList< T >::m_sortedList, KisSortedHistoryList< T >::resortList(), and value().

◆ at()

template<typename T >
T KisSortedHistoryList< T >::at ( int pos) const
inline
Returns
@pos's element of the sorted history list

Definition at line 36 of file KisSortedHistoryList.h.

36 {
39
40 return m_sortedList.at(pos);
41 }
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KisSortedHistoryList< T >::m_sortedList, and KisSortedHistoryList< T >::size().

◆ cbegin()

template<typename T >
const_iterator KisSortedHistoryList< T >::cbegin ( ) const
inline

Definition at line 86 of file KisSortedHistoryList.h.

86 {
87 return m_sortedList.cbegin();
88 }

References KisSortedHistoryList< T >::m_sortedList.

◆ cend()

template<typename T >
const_iterator KisSortedHistoryList< T >::cend ( ) const
inline

Definition at line 90 of file KisSortedHistoryList.h.

90 {
91 return m_sortedList.cend();
92 }

References KisSortedHistoryList< T >::m_sortedList.

◆ clear()

template<typename T >
void KisSortedHistoryList< T >::clear ( )
inline

Clear all historical elements from the list

Definition at line 64 of file KisSortedHistoryList.h.

64 {
65 m_list.clear();
66 m_sortedList.clear();
67 }

References KisSortedHistoryList< T >::m_list, and KisSortedHistoryList< T >::m_sortedList.

◆ maxSize()

template<typename T >
int KisSortedHistoryList< T >::maxSize ( ) const
inline
Returns
the maximum possible number of elements in the list

Definition at line 72 of file KisSortedHistoryList.h.

72 {
73 return m_list.maxSize();
74 }

References KisSortedHistoryList< T >::m_list.

◆ resortList()

template<typename T >
bool KisSortedHistoryList< T >::resortList ( )
inlineprivate

Definition at line 95 of file KisSortedHistoryList.h.

95 {
96 m_sortedList.clear();
97 m_sortedList.reserve(m_list.size());
98 std::copy(m_list.cbegin(), m_list.cend(), std::back_inserter(m_sortedList));
99
100 if (m_compareLess) {
101 std::sort(m_sortedList.begin(), m_sortedList.end(), m_compareLess);
102 }
103
104 return bool(m_compareLess);
105 }

References KisSortedHistoryList< T >::m_compareLess, KisSortedHistoryList< T >::m_list, and KisSortedHistoryList< T >::m_sortedList.

◆ setCompareLess()

template<typename T >
void KisSortedHistoryList< T >::setCompareLess ( compare_less func)
inline

Set the comparison function for sorting the elements.

Set to empty function compare_less{} to disable sorting completely

Definition at line 81 of file KisSortedHistoryList.h.

81 {
82 m_compareLess = func;
83 resortList();
84 }

References KisSortedHistoryList< T >::m_compareLess, and KisSortedHistoryList< T >::resortList().

◆ size()

template<typename T >
int KisSortedHistoryList< T >::size ( ) const
inline
Returns
the number of elements in the list

Definition at line 29 of file KisSortedHistoryList.h.

29 {
30 return m_list.size();
31 }

References KisSortedHistoryList< T >::m_list.

Member Data Documentation

◆ m_compareLess

template<typename T >
compare_less KisSortedHistoryList< T >::m_compareLess
private

Definition at line 110 of file KisSortedHistoryList.h.

◆ m_list

template<typename T >
KisHistoryList<T> KisSortedHistoryList< T >::m_list
private

Definition at line 108 of file KisSortedHistoryList.h.

◆ m_sortedList

template<typename T >
std::vector<T> KisSortedHistoryList< T >::m_sortedList
private

Definition at line 109 of file KisSortedHistoryList.h.


The documentation for this class was generated from the following file: