Krita Source Code Documentation
Loading...
Searching...
No Matches
KisForestDetail Namespace Reference

Classes

class  BaseIterator
 
struct  BaseNode
 
class  ChildIterator
 
class  CompositionIterator
 
class  DepthFirstIterator
 
class  Forest
 
class  HierarchyIterator
 
struct  Node
 
struct  RootNodeImpl
 

Typedefs

template<typename T >
using RootNode = RootNodeImpl<Node<T>>
 

Enumerations

enum  TraversalState { Enter , Leave }
 

Functions

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > childBegin (const ChildIterator< value_type, is_const > &it)
 
template<typename T >
Forest< T >::const_child_iterator childBegin (const Forest< T > &forest)
 
template<typename T >
Forest< T >::child_iterator childBegin (Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator childBegin (Iterator it)
 
template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > childEnd (const ChildIterator< value_type, is_const > &it)
 
template<typename T >
Forest< T >::const_child_iterator childEnd (const Forest< T > &forest)
 
template<typename T >
Forest< T >::child_iterator childEnd (Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator childEnd (Iterator it)
 
template<typename T >
Forest< T >::const_composition_iterator compositionBegin (const Forest< T > &forest)
 
template<typename T >
Forest< T >::composition_iterator compositionBegin (Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = CompositionIterator<typename Iterator::value_type, is_const>>
ResultIterator compositionBegin (Iterator it)
 
template<typename T >
Forest< T >::const_composition_iterator compositionEnd (const Forest< T > &forest)
 
template<typename T >
Forest< T >::composition_iterator compositionEnd (Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = CompositionIterator<typename Iterator::value_type, is_const>>
ResultIterator compositionEnd (Iterator it)
 
template<typename T >
int depth (const Forest< T > &forest)
 
template<typename T >
int depth (typename Forest< T >::const_child_iterator beginIt, typename Forest< T >::const_child_iterator endIt)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = HierarchyIterator<typename Iterator::value_type, is_const>>
ResultIterator hierarchyBegin (Iterator it)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = HierarchyIterator<typename Iterator::value_type, is_const>>
ResultIterator hierarchyEnd (Iterator it)
 
template<typename T , bool is_const>
bool isEnd (const ChildIterator< T, is_const > &it)
 
template<typename value_type , bool is_const>
QDebug operator<< (QDebug dbg, const ChildIterator< value_type, is_const > &it)
 
template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > parent (const ChildIterator< value_type, is_const > &it)
 
template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > siblingBegin (const ChildIterator< value_type, is_const > &it)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator siblingBegin (Iterator it)
 
template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > siblingCurrent (ChildIterator< value_type, is_const > it)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator siblingCurrent (Iterator it)
 
template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > siblingEnd (const ChildIterator< value_type, is_const > &it)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator siblingEnd (Iterator it)
 
template<typename T >
int size (const Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Enter, is_const>>
ResultIterator subtreeBegin (Iterator it)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Enter, is_const>>
ResultIterator subtreeEnd (Iterator it)
 
template<typename T >
Forest< T >::const_depth_first_tail_iterator tailSubtreeBegin (const Forest< T > &forest)
 
template<typename T >
Forest< T >::depth_first_tail_iterator tailSubtreeBegin (Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Leave, is_const>>
ResultIterator tailSubtreeBegin (Iterator it)
 
template<typename T >
Forest< T >::const_depth_first_tail_iterator tailSubtreeEnd (const Forest< T > &forest)
 
template<typename T >
Forest< T >::depth_first_tail_iterator tailSubtreeEnd (Forest< T > &forest)
 
template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Leave, is_const>>
ResultIterator tailSubtreeEnd (Iterator it)
 

Typedef Documentation

◆ RootNode

template<typename T >
using KisForestDetail::RootNode = RootNodeImpl<Node<T>>

Definition at line 54 of file KisForest.h.

Enumeration Type Documentation

◆ TraversalState

Composition iterator is used to traverse entire child-subtree of the node recursively in depth-first order. Every node it entered twice: first time, when subtree is entered; second time, when subtree is left. To check the current state of the iterator (Enter or Leave) use it.state() call.

Iterator models ForwardIterator concept.

// Forest:
//
// 0 1
// 2
// 3 5 6
// 7
// 4
// 8 9
// 10
KisForest<int>::iterator it3 = findValue(forest, 3);
// iterate through all the children of '3' recursively
for (auto it = compositionBegin(it3); it != compositionEnd(it3); ++it) {
qDebug() << *it << it.state();
}
// prints: (3, Enter)
// (5, Enter)
// (6, Enter)
// (6, Leave)
// (7, Enter)
// (7, Leave)
// (5, Leave)
// (3, Leave)
ResultIterator compositionEnd(Iterator it)
Definition KisForest.h:570
ResultIterator compositionBegin(Iterator it)
Definition KisForest.h:562

WARNING: converting end() iterator to other iterator types currently leads to undefined behavior.

Enumerator
Enter 
Leave 

Definition at line 479 of file KisForest.h.

479 {
480 Enter,
481 Leave
482};

Function Documentation

◆ childBegin() [1/4]

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > KisForestDetail::childBegin ( const ChildIterator< value_type, is_const > & it)

Definition at line 290 of file KisForest.h.

291{
292 if (it.node()) {
293 return ChildIterator<value_type, is_const>(it.node()->firstChild, it.node(), 0);
294 } else {
295 return ChildIterator<value_type, is_const>(nullptr, it.m_parent, it.m_offsetToParent + 1);
296 }
297}
NodeType * node() const
Definition KisForest.h:78

References KisForestDetail::ChildIterator< T, is_const >::m_offsetToParent, KisForestDetail::ChildIterator< T, is_const >::m_parent, and KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node().

◆ childBegin() [2/4]

template<typename T >
Forest< T >::const_child_iterator KisForestDetail::childBegin ( const Forest< T > & forest)

Definition at line 1144 of file KisForest.h.

1145{
1146 return forest.childBegin();
1147}
child_iterator childBegin()
Definition KisForest.h:876

References KisForestDetail::Forest< T >::childBegin().

◆ childBegin() [3/4]

template<typename T >
Forest< T >::child_iterator KisForestDetail::childBegin ( Forest< T > & forest)

Definition at line 1138 of file KisForest.h.

1139{
1140 return forest.childBegin();
1141}

References KisForestDetail::Forest< T >::childBegin().

◆ childBegin() [4/4]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::childBegin ( Iterator it)

Definition at line 312 of file KisForest.h.

313{
314 return childBegin(siblingCurrent(it));
315}
ChildIterator< value_type, is_const > childBegin(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:290
ChildIterator< value_type, is_const > siblingCurrent(ChildIterator< value_type, is_const > it)
Definition KisForest.h:240

References childBegin(), and siblingCurrent().

◆ childEnd() [1/4]

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > KisForestDetail::childEnd ( const ChildIterator< value_type, is_const > & it)

Definition at line 300 of file KisForest.h.

301{
302 if (it.node()) {
303 return ChildIterator<value_type, is_const>(nullptr, it.node(), 0);
304 } else {
305 return ChildIterator<value_type, is_const>(nullptr, it.m_parent, it.m_offsetToParent + 1);
306 }
307}

References KisForestDetail::ChildIterator< T, is_const >::m_offsetToParent, KisForestDetail::ChildIterator< T, is_const >::m_parent, and KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node().

◆ childEnd() [2/4]

template<typename T >
Forest< T >::const_child_iterator KisForestDetail::childEnd ( const Forest< T > & forest)

Definition at line 1157 of file KisForest.h.

1158{
1159 return forest.childEnd();
1160}
child_iterator childEnd()
Definition KisForest.h:880

References KisForestDetail::Forest< T >::childEnd().

◆ childEnd() [3/4]

template<typename T >
Forest< T >::child_iterator KisForestDetail::childEnd ( Forest< T > & forest)

Definition at line 1151 of file KisForest.h.

1152{
1153 return forest.childEnd();
1154}

References KisForestDetail::Forest< T >::childEnd().

◆ childEnd() [4/4]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::childEnd ( Iterator it)

Definition at line 320 of file KisForest.h.

321{
322 return childEnd(siblingCurrent(it));
323}
ChildIterator< value_type, is_const > childEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:300

References childEnd(), and siblingCurrent().

◆ compositionBegin() [1/3]

template<typename T >
Forest< T >::const_composition_iterator KisForestDetail::compositionBegin ( const Forest< T > & forest)

Definition at line 1169 of file KisForest.h.

1170{
1171 return forest.compositionBegin();
1172}
composition_iterator compositionBegin()
Definition KisForest.h:912

References KisForestDetail::Forest< T >::compositionBegin().

◆ compositionBegin() [2/3]

template<typename T >
Forest< T >::composition_iterator KisForestDetail::compositionBegin ( Forest< T > & forest)

Definition at line 1163 of file KisForest.h.

1164{
1165 return forest.compositionBegin();
1166}

References KisForestDetail::Forest< T >::compositionBegin().

◆ compositionBegin() [3/3]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = CompositionIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::compositionBegin ( Iterator it)

Definition at line 562 of file KisForest.h.

563{
564 return ResultIterator(it.node(), Enter);
565}

References Enter.

◆ compositionEnd() [1/3]

template<typename T >
Forest< T >::const_composition_iterator KisForestDetail::compositionEnd ( const Forest< T > & forest)

Definition at line 1182 of file KisForest.h.

1183{
1184 return forest.compositionEnd();
1185}
composition_iterator compositionEnd()
Definition KisForest.h:916

References KisForestDetail::Forest< T >::compositionEnd().

◆ compositionEnd() [2/3]

template<typename T >
Forest< T >::composition_iterator KisForestDetail::compositionEnd ( Forest< T > & forest)

Definition at line 1176 of file KisForest.h.

1177{
1178 return forest.compositionEnd();
1179}

References KisForestDetail::Forest< T >::compositionEnd().

◆ compositionEnd() [3/3]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = CompositionIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::compositionEnd ( Iterator it)

Definition at line 570 of file KisForest.h.

571{
572 return it.node() ?
573 std::next(ResultIterator(it.node(), Leave)) :
574 ResultIterator(nullptr, Leave);
575}

References Leave.

◆ depth() [1/2]

template<typename T >
int KisForestDetail::depth ( const Forest< T > & forest)

Definition at line 1227 of file KisForest.h.

1227 {
1228 return depth<T>(childBegin(forest), childEnd(forest));
1229}

References childBegin(), and childEnd().

◆ depth() [2/2]

template<typename T >
int KisForestDetail::depth ( typename Forest< T >::const_child_iterator beginIt,
typename Forest< T >::const_child_iterator endIt )

Definition at line 1213 of file KisForest.h.

1215{
1216
1217 int currentDepth = 0;
1218
1219 for (auto it = beginIt; it != endIt; ++it) {
1220 currentDepth = std::max(currentDepth, 1 + depth<T>(childBegin(it), childEnd(it)));
1221 }
1222
1223 return currentDepth;
1224}

References childBegin(), and childEnd().

◆ hierarchyBegin()

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = HierarchyIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::hierarchyBegin ( Iterator it)

Definition at line 419 of file KisForest.h.

420{
421 return ResultIterator(it.node());
422}

◆ hierarchyEnd()

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = HierarchyIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::hierarchyEnd ( Iterator it)

Definition at line 427 of file KisForest.h.

428{
429 Q_UNUSED(it);
430 return ResultIterator(nullptr);
431}

◆ isEnd()

template<typename T , bool is_const>
bool KisForestDetail::isEnd ( const ChildIterator< T, is_const > & it)
inline

Definition at line 341 of file KisForest.h.

341 {
342 return !it.node();
343}

References KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node().

◆ operator<<()

template<typename value_type , bool is_const>
QDebug KisForestDetail::operator<< ( QDebug dbg,
const ChildIterator< value_type, is_const > & it )

Definition at line 228 of file KisForest.h.

229{
230 if (it.node()) {
231 dbg.nospace() << "ChildIterator(" << it.node() << "(" << it.node()->value << ")" << ", parent:" << it.m_parent << ")";
232 } else {
233 dbg.nospace() << "ChildIterator(" << "nullptr" << ", parent:" << it.m_parent << ", offset:" << it.m_offsetToParent << ")";
234 }
235 return dbg;
236}

References KisForestDetail::ChildIterator< T, is_const >::m_offsetToParent, KisForestDetail::ChildIterator< T, is_const >::m_parent, and KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node().

◆ parent()

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > KisForestDetail::parent ( const ChildIterator< value_type, is_const > & it)

Definition at line 327 of file KisForest.h.

328{
329 if (it.m_parent->isRoot()) {
330 return ChildIterator<value_type, is_const>(nullptr, it.m_parent, qMax(-1, it.m_offsetToParent - 1));
331 } else if (it.m_offsetToParent == 0) {
332 using NodeType = typename ChildIterator<value_type, is_const>::NodeType;
333 NodeType *parentNode = static_cast<NodeType*>(it.m_parent);
334 return ChildIterator<value_type, is_const>(parentNode, parentNode->parent, 0);
335 } else {
336 return ChildIterator<value_type, is_const>(nullptr, it.m_parent, it.m_offsetToParent - 1);
337 }
338}

References KisForestDetail::ChildIterator< T, is_const >::m_offsetToParent, and KisForestDetail::ChildIterator< T, is_const >::m_parent.

◆ siblingBegin() [1/2]

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > KisForestDetail::siblingBegin ( const ChildIterator< value_type, is_const > & it)

Definition at line 246 of file KisForest.h.

247{
248 using RootNodeType = typename ChildIterator<value_type, is_const>::RootNodeType;
249 if (!it.node() && it.m_offsetToParent != 0) return it;
250 RootNodeType *parent = it.m_parent;
251 return ChildIterator<value_type, is_const>(parent ? parent->firstChild : nullptr, parent, 0);
252}
std::add_const_if_t< is_const, RootNode< T > > RootNodeType
Definition KisForest.h:173
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References KisForestDetail::ChildIterator< T, is_const >::m_offsetToParent, KisForestDetail::ChildIterator< T, is_const >::m_parent, KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node(), and parent().

◆ siblingBegin() [2/2]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::siblingBegin ( Iterator it)

Definition at line 276 of file KisForest.h.

277{
278 return siblingBegin(siblingCurrent(it));
279}
ChildIterator< value_type, is_const > siblingBegin(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:246

References siblingBegin(), and siblingCurrent().

◆ siblingCurrent() [1/2]

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > KisForestDetail::siblingCurrent ( ChildIterator< value_type, is_const > it)

Definition at line 240 of file KisForest.h.

241{
242 return it;
243}

◆ siblingCurrent() [2/2]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::siblingCurrent ( Iterator it)

Definition at line 264 of file KisForest.h.

265{
266 // TODO: conversion of an end-iterator into a child iterator is still not implemented
267 // and considered as UB. We need to implement all special-cases for that.
269
270 return ResultIterator(it.node(), it.node() ? it.node()->parent : nullptr, 0);
271}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP.

◆ siblingEnd() [1/2]

template<typename value_type , bool is_const>
ChildIterator< value_type, is_const > KisForestDetail::siblingEnd ( const ChildIterator< value_type, is_const > & it)

◆ siblingEnd() [2/2]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
ResultIterator KisForestDetail::siblingEnd ( Iterator it)

Definition at line 284 of file KisForest.h.

285{
286 return siblingEnd(siblingCurrent(it));
287}
ChildIterator< value_type, is_const > siblingEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:255

References siblingCurrent(), and siblingEnd().

◆ size()

template<typename T >
int KisForestDetail::size ( const Forest< T > & forest)

Definition at line 1232 of file KisForest.h.

1232 {
1233 return std::distance(begin(forest), end(forest));
1234}

◆ subtreeBegin()

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Enter, is_const>>
ResultIterator KisForestDetail::subtreeBegin ( Iterator it)

Definition at line 688 of file KisForest.h.

689{
690 return ResultIterator(it.node(), Enter);
691}

References Enter.

◆ subtreeEnd()

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Enter, is_const>>
ResultIterator KisForestDetail::subtreeEnd ( Iterator it)

Definition at line 696 of file KisForest.h.

697{
698 return it.node() ?
699 std::next(ResultIterator(it.node(), Leave)) :
700 ResultIterator(nullptr, Leave);
701}

References Leave.

◆ tailSubtreeBegin() [1/3]

template<typename T >
Forest< T >::const_depth_first_tail_iterator KisForestDetail::tailSubtreeBegin ( const Forest< T > & forest)

Definition at line 1195 of file KisForest.h.

1196{
1197 return forest.depthFirstTailBegin();
1198}
depth_first_tail_iterator depthFirstTailBegin()
Definition KisForest.h:852

References KisForestDetail::Forest< T >::depthFirstTailBegin().

◆ tailSubtreeBegin() [2/3]

template<typename T >
Forest< T >::depth_first_tail_iterator KisForestDetail::tailSubtreeBegin ( Forest< T > & forest)

Definition at line 1189 of file KisForest.h.

1190{
1191 return forest.depthFirstTailBegin();
1192}

References KisForestDetail::Forest< T >::depthFirstTailBegin().

◆ tailSubtreeBegin() [3/3]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Leave, is_const>>
ResultIterator KisForestDetail::tailSubtreeBegin ( Iterator it)

Definition at line 706 of file KisForest.h.

707{
708 return ResultIterator(it.node(), Enter, true);
709}

References Enter.

◆ tailSubtreeEnd() [1/3]

template<typename T >
Forest< T >::const_depth_first_tail_iterator KisForestDetail::tailSubtreeEnd ( const Forest< T > & forest)

Definition at line 1207 of file KisForest.h.

1208{
1209 return forest.depthFirstTailEnd();
1210}
depth_first_tail_iterator depthFirstTailEnd()
Definition KisForest.h:856

References KisForestDetail::Forest< T >::depthFirstTailEnd().

◆ tailSubtreeEnd() [2/3]

template<typename T >
Forest< T >::depth_first_tail_iterator KisForestDetail::tailSubtreeEnd ( Forest< T > & forest)

Definition at line 1201 of file KisForest.h.

1202{
1203 return forest.depthFirstTailEnd();
1204}

References KisForestDetail::Forest< T >::depthFirstTailEnd().

◆ tailSubtreeEnd() [3/3]

template<typename Iterator , bool is_const = std::is_const_v<typename Iterator::NodeType>, typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Leave, is_const>>
ResultIterator KisForestDetail::tailSubtreeEnd ( Iterator it)

Definition at line 714 of file KisForest.h.

715{
716 return it.node() ?
717 std::next(ResultIterator(it.node(), Leave)) :
718 ResultIterator(nullptr, Leave);
719}

References Leave.