Krita Source Code Documentation
Loading...
Searching...
No Matches
KisForestDetail::Forest< T > Class Template Reference

#include <KisForest.h>

Public Types

using child_iterator = ChildIterator<T, false>
 
using composition_iterator = CompositionIterator<T, false>
 
using const_child_iterator = ChildIterator<T, true>
 
using const_composition_iterator = CompositionIterator<T, true>
 
using const_depth_first_tail_iterator = DepthFirstIterator<T, Leave, true>
 
using const_hierarchy_iterator = HierarchyIterator<T, true>
 
using const_iterator = DepthFirstIterator<T, Enter, true>
 
using depth_first_tail_iterator = DepthFirstIterator<T, Leave, false>
 
using hierarchy_iterator = HierarchyIterator<T, false>
 
using iterator = DepthFirstIterator<T, Enter, false>
 
using value_type = T
 

Public Member Functions

iterator begin ()
 
const_iterator begin () const
 
child_iterator childBegin ()
 
const_child_iterator childBegin () const
 
child_iterator childEnd ()
 
const_child_iterator childEnd () const
 
composition_iterator compositionBegin ()
 
const_composition_iterator compositionBegin () const
 
composition_iterator compositionEnd ()
 
const_composition_iterator compositionEnd () const
 
const_iterator constBegin () const
 
const_child_iterator constChildBegin () const
 
const_child_iterator constChildEnd () const
 
const_composition_iterator constCompositionBegin () const
 
const_composition_iterator constCompositionEnd () const
 
const_depth_first_tail_iterator constDepthFirstTailBegin () const
 
const_depth_first_tail_iterator constDepthFirstTailEnd () const
 
const_iterator constEnd () const
 
const_child_iterator constParentEnd () const
 
depth_first_tail_iterator depthFirstTailBegin ()
 
const_depth_first_tail_iterator depthFirstTailBegin () const
 
depth_first_tail_iterator depthFirstTailEnd ()
 
const_depth_first_tail_iterator depthFirstTailEnd () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
child_iterator erase (child_iterator pos)
 Removes element at position pos. If pos is 'end', then result is undefined.
 
child_iterator erase (child_iterator pos, child_iterator end)
 erases all elements from pos to end (excluding end)
 
 Forest ()
 
 Forest (const Forest< T > &rhs)
 
template<typename X >
child_iterator insert (child_iterator pos, X &&value)
 Inserts element value into position pos. value becomes the child of the same parent as pos and is placed right before pos.
 
child_iterator move (child_iterator subtree, child_iterator newPos)
 move a subtree to new position Moves subtree into a new position pointer by newPos. newPos must not be inside the subtree, otherwise cycling links may appear.
 
Forest< T > & operator= (const Forest< T > &rhs)
 
child_iterator parentEnd ()
 
const_child_iterator parentEnd () const
 
void swap (Forest &other)
 
 ~Forest ()
 

Private Member Functions

void cloneChildren (const_child_iterator oldParent, child_iterator parent)
 
void linkAfter (Node< T > *node, Node< T > *afterMe)
 
void linkBefore (Node< T > *node, Node< T > *beforeMe)
 
void linkNode (child_iterator pos, Node< T > *node)
 
void unlinkNode (Node< T > *node)
 

Static Private Member Functions

template<class ForestType , class IteratorType = DepthFirstIterator<typename ForestType::value_type, Enter, std::is_const_v<ForestType>>>
static IteratorType beginImpl (ForestType &forest)
 
template<class ForestType , class IteratorType = ChildIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType childBeginImpl (ForestType &forest)
 
template<class ForestType , class IteratorType = ChildIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType childEndImpl (ForestType &forest)
 
template<class ForestType , class IteratorType = CompositionIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType compositionBeginImpl (ForestType &forest)
 
template<class ForestType , class IteratorType = CompositionIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType compositionEndImpl (ForestType &forest)
 
template<class ForestType , class IteratorType = DepthFirstIterator<typename ForestType::value_type, Enter, std::is_const_v<ForestType>>>
static IteratorType endImpl (ForestType &forest)
 
template<class ForestType , class IteratorType = ChildIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType parentEndImpl (ForestType &forest)
 

Private Attributes

RootNode< T > m_root
 

Detailed Description

template<typename T>
class KisForestDetail::Forest< T >

Forest implements a container for composing tree-like structures from arbitrary objects.

All add/remove operations are implemented via child_iterator. You can convert any iterator type into a child iterator via siblingCurrent() function.

Definition at line 776 of file KisForest.h.

Member Typedef Documentation

◆ child_iterator

template<typename T >
using KisForestDetail::Forest< T >::child_iterator = ChildIterator<T, false>

Definition at line 805 of file KisForest.h.

◆ composition_iterator

template<typename T >
using KisForestDetail::Forest< T >::composition_iterator = CompositionIterator<T, false>

Definition at line 808 of file KisForest.h.

◆ const_child_iterator

template<typename T >
using KisForestDetail::Forest< T >::const_child_iterator = ChildIterator<T, true>

Definition at line 806 of file KisForest.h.

◆ const_composition_iterator

template<typename T >
using KisForestDetail::Forest< T >::const_composition_iterator = CompositionIterator<T, true>

Definition at line 809 of file KisForest.h.

◆ const_depth_first_tail_iterator

template<typename T >
using KisForestDetail::Forest< T >::const_depth_first_tail_iterator = DepthFirstIterator<T, Leave, true>

Definition at line 818 of file KisForest.h.

◆ const_hierarchy_iterator

template<typename T >
using KisForestDetail::Forest< T >::const_hierarchy_iterator = HierarchyIterator<T, true>

Definition at line 812 of file KisForest.h.

◆ const_iterator

template<typename T >
using KisForestDetail::Forest< T >::const_iterator = DepthFirstIterator<T, Enter, true>

Definition at line 815 of file KisForest.h.

◆ depth_first_tail_iterator

template<typename T >
using KisForestDetail::Forest< T >::depth_first_tail_iterator = DepthFirstIterator<T, Leave, false>

Definition at line 817 of file KisForest.h.

◆ hierarchy_iterator

template<typename T >
using KisForestDetail::Forest< T >::hierarchy_iterator = HierarchyIterator<T, false>

Definition at line 811 of file KisForest.h.

◆ iterator

template<typename T >
using KisForestDetail::Forest< T >::iterator = DepthFirstIterator<T, Enter, false>

Definition at line 814 of file KisForest.h.

◆ value_type

template<typename T >
using KisForestDetail::Forest< T >::value_type = T

Definition at line 803 of file KisForest.h.

Constructor & Destructor Documentation

◆ Forest() [1/2]

template<typename T >
KisForestDetail::Forest< T >::Forest ( )
inline

Definition at line 779 of file KisForest.h.

780 {
781 }

◆ ~Forest()

template<typename T >
KisForestDetail::Forest< T >::~Forest ( )
inline

Definition at line 783 of file KisForest.h.

783 {
785 }
child_iterator erase(child_iterator pos)
Removes element at position pos. If pos is 'end', then result is undefined.
Definition KisForest.h:956

References KisForestDetail::Forest< T >::childBegin(), KisForestDetail::Forest< T >::childEnd(), and KisForestDetail::Forest< T >::erase().

◆ Forest() [2/2]

template<typename T >
KisForestDetail::Forest< T >::Forest ( const Forest< T > & rhs)
inline

Definition at line 787 of file KisForest.h.

787 {
788 for (auto it = rhs.childBegin(); it != rhs.childEnd(); ++it) {
789 auto cloneIt = this->insert(this->childEnd(), *it);
790 cloneChildren(it, cloneIt);
791 }
792 }
void cloneChildren(const_child_iterator oldParent, child_iterator parent)
Definition KisForest.h:1070

References KisForestDetail::Forest< T >::childBegin(), KisForestDetail::Forest< T >::childEnd(), KisForestDetail::Forest< T >::cloneChildren(), and KisForestDetail::Forest< T >::insert().

Member Function Documentation

◆ begin() [1/2]

template<typename T >
iterator KisForestDetail::Forest< T >::begin ( )
inline

Definition at line 828 of file KisForest.h.

828 {
829 return beginImpl(*this);
830 }
static IteratorType beginImpl(ForestType &forest)
Definition KisForest.h:1105

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

◆ begin() [2/2]

template<typename T >
const_iterator KisForestDetail::Forest< T >::begin ( ) const
inline

Definition at line 836 of file KisForest.h.

836 {
837 return beginImpl(*this);
838 }

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

◆ beginImpl()

template<typename T >
template<class ForestType , class IteratorType = DepthFirstIterator<typename ForestType::value_type, Enter, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::beginImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1105 of file KisForest.h.

1105 {
1106 return IteratorType(forest.m_root.firstChild);
1107 }

◆ childBegin() [1/2]

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

Definition at line 876 of file KisForest.h.

876 {
877 return childBeginImpl(*this);
878 }
static IteratorType childBeginImpl(ForestType &forest)
Definition KisForest.h:1083

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

◆ childBegin() [2/2]

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

Definition at line 888 of file KisForest.h.

888 {
889 return childBeginImpl(*this);
890 }

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

◆ childBeginImpl()

template<typename T >
template<class ForestType , class IteratorType = ChildIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::childBeginImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1083 of file KisForest.h.

1083 {
1084 return IteratorType(forest.m_root.firstChild, &forest.m_root, 0);
1085 }

◆ childEnd() [1/2]

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

Definition at line 880 of file KisForest.h.

880 {
881 return childEndImpl(*this);
882 }
static IteratorType childEndImpl(ForestType &forest)
Definition KisForest.h:1090

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

◆ childEnd() [2/2]

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

Definition at line 892 of file KisForest.h.

892 {
893 return childEndImpl(*this);
894 }

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

◆ childEndImpl()

template<typename T >
template<class ForestType , class IteratorType = ChildIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::childEndImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1090 of file KisForest.h.

1090 {
1091 return IteratorType(nullptr, &forest.m_root, 0);
1092 }

◆ cloneChildren()

template<typename T >
void KisForestDetail::Forest< T >::cloneChildren ( const_child_iterator oldParent,
child_iterator parent )
inlineprivate

Definition at line 1070 of file KisForest.h.

1070 {
1071 auto it = KisForestDetail::childBegin(oldParent);
1072 auto end = KisForestDetail::childEnd(oldParent);
1073 for (;it != end; ++it) {
1074 auto itClone = this->insert(KisForestDetail::childEnd(parent), *it);
1075 cloneChildren(it, itClone);
1076 }
1077 }
ChildIterator< value_type, is_const > childBegin(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:290
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327
ChildIterator< value_type, is_const > childEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:300

References KisForestDetail::childBegin(), KisForestDetail::childEnd(), KisForestDetail::Forest< T >::cloneChildren(), KisForestDetail::Forest< T >::end(), and KisForestDetail::Forest< T >::insert().

◆ compositionBegin() [1/2]

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

Definition at line 912 of file KisForest.h.

912 {
913 return compositionBeginImpl(*this);
914 }
static IteratorType compositionBeginImpl(ForestType &forest)
Definition KisForest.h:1121

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

◆ compositionBegin() [2/2]

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

Definition at line 920 of file KisForest.h.

920 {
921 return compositionBeginImpl(*this);
922 }

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

◆ compositionBeginImpl()

template<typename T >
template<class ForestType , class IteratorType = CompositionIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::compositionBeginImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1121 of file KisForest.h.

1121 {
1122 return IteratorType(forest.m_root.firstChild);
1123 }

◆ compositionEnd() [1/2]

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

Definition at line 916 of file KisForest.h.

916 {
917 return compositionEndImpl(*this);
918 }
static IteratorType compositionEndImpl(ForestType &forest)
Definition KisForest.h:1128

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

◆ compositionEnd() [2/2]

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

Definition at line 924 of file KisForest.h.

924 {
925 return compositionEndImpl(*this);
926 }

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

◆ compositionEndImpl()

template<typename T >
template<class ForestType , class IteratorType = CompositionIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::compositionEndImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1128 of file KisForest.h.

1128 {
1129 Q_UNUSED(forest);
1130 return IteratorType(nullptr);
1131 }

◆ constBegin()

template<typename T >
const_iterator KisForestDetail::Forest< T >::constBegin ( ) const
inline

Definition at line 844 of file KisForest.h.

844 {
845 return beginImpl(*this);
846 }

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

◆ constChildBegin()

template<typename T >
const_child_iterator KisForestDetail::Forest< T >::constChildBegin ( ) const
inline

Definition at line 900 of file KisForest.h.

900 {
901 return childBeginImpl(*this);
902 }

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

◆ constChildEnd()

template<typename T >
const_child_iterator KisForestDetail::Forest< T >::constChildEnd ( ) const
inline

Definition at line 904 of file KisForest.h.

904 {
905 return childEndImpl(*this);
906 }

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

◆ constCompositionBegin()

template<typename T >
const_composition_iterator KisForestDetail::Forest< T >::constCompositionBegin ( ) const
inline

Definition at line 928 of file KisForest.h.

928 {
929 return compositionBeginImpl(*this);
930 }

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

◆ constCompositionEnd()

template<typename T >
const_composition_iterator KisForestDetail::Forest< T >::constCompositionEnd ( ) const
inline

Definition at line 932 of file KisForest.h.

932 {
933 return compositionEndImpl(*this);
934 }

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

◆ constDepthFirstTailBegin()

template<typename T >
const_depth_first_tail_iterator KisForestDetail::Forest< T >::constDepthFirstTailBegin ( ) const
inline

Definition at line 868 of file KisForest.h.

868 {
870 }
const_iterator constBegin() const
Definition KisForest.h:844
ResultIterator tailSubtreeBegin(Iterator it)
Definition KisForest.h:706

References KisForestDetail::Forest< T >::constBegin(), and KisForestDetail::tailSubtreeBegin().

◆ constDepthFirstTailEnd()

template<typename T >
const_depth_first_tail_iterator KisForestDetail::Forest< T >::constDepthFirstTailEnd ( ) const
inline

Definition at line 872 of file KisForest.h.

872 {
873 return tailSubtreeEnd(constEnd());
874 }
const_iterator constEnd() const
Definition KisForest.h:848
ResultIterator tailSubtreeEnd(Iterator it)
Definition KisForest.h:714

References KisForestDetail::Forest< T >::constEnd(), and KisForestDetail::tailSubtreeEnd().

◆ constEnd()

template<typename T >
const_iterator KisForestDetail::Forest< T >::constEnd ( ) const
inline

Definition at line 848 of file KisForest.h.

848 {
849 return endImpl(*this);
850 }
static IteratorType endImpl(ForestType &forest)
Definition KisForest.h:1113

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

◆ constParentEnd()

template<typename T >
const_child_iterator KisForestDetail::Forest< T >::constParentEnd ( ) const
inline

Definition at line 908 of file KisForest.h.

908 {
909 return parentEndImpl(*this);
910 }
static IteratorType parentEndImpl(ForestType &forest)
Definition KisForest.h:1097

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

◆ depthFirstTailBegin() [1/2]

template<typename T >
depth_first_tail_iterator KisForestDetail::Forest< T >::depthFirstTailBegin ( )
inline

Definition at line 852 of file KisForest.h.

852 {
853 return tailSubtreeBegin(begin());
854 }

References KisForestDetail::Forest< T >::begin(), and KisForestDetail::tailSubtreeBegin().

◆ depthFirstTailBegin() [2/2]

template<typename T >
const_depth_first_tail_iterator KisForestDetail::Forest< T >::depthFirstTailBegin ( ) const
inline

Definition at line 860 of file KisForest.h.

860 {
862 }

References KisForestDetail::Forest< T >::constBegin(), and KisForestDetail::tailSubtreeBegin().

◆ depthFirstTailEnd() [1/2]

template<typename T >
depth_first_tail_iterator KisForestDetail::Forest< T >::depthFirstTailEnd ( )
inline

Definition at line 856 of file KisForest.h.

856 {
857 return tailSubtreeEnd(end());
858 }

References KisForestDetail::Forest< T >::end(), and KisForestDetail::tailSubtreeEnd().

◆ depthFirstTailEnd() [2/2]

template<typename T >
const_depth_first_tail_iterator KisForestDetail::Forest< T >::depthFirstTailEnd ( ) const
inline

Definition at line 864 of file KisForest.h.

864 {
865 return tailSubtreeEnd(constEnd());
866 }

References KisForestDetail::Forest< T >::constEnd(), and KisForestDetail::tailSubtreeEnd().

◆ empty()

template<typename T >
bool KisForestDetail::Forest< T >::empty ( ) const
inline

Definition at line 820 of file KisForest.h.

820 {
821 return !m_root.firstChild;
822 }

References KisForestDetail::Forest< T >::m_root.

◆ end() [1/2]

template<typename T >
iterator KisForestDetail::Forest< T >::end ( )
inline

Definition at line 832 of file KisForest.h.

832 {
833 return endImpl(*this);
834 }

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

◆ end() [2/2]

template<typename T >
const_iterator KisForestDetail::Forest< T >::end ( ) const
inline

Definition at line 840 of file KisForest.h.

840 {
841 return endImpl(*this);
842 }

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

◆ endImpl()

template<typename T >
template<class ForestType , class IteratorType = DepthFirstIterator<typename ForestType::value_type, Enter, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::endImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1113 of file KisForest.h.

1113 {
1114 Q_UNUSED(forest);
1115 return IteratorType(nullptr);
1116 }

◆ erase() [1/2]

template<typename T >
child_iterator KisForestDetail::Forest< T >::erase ( child_iterator pos)
inline

Removes element at position pos. If pos is 'end', then result is undefined.

Returns
the element following pos

Definition at line 956 of file KisForest.h.

956 {
957 child_iterator nextNode = std::next(pos);
958 Node<T> *node = pos.node();
959
960 Node<T> *lastNode = node;
961 for (auto it = tailSubtreeBegin(pos); it != tailSubtreeEnd(pos); ++it) {
962
963 if (lastNode != node) {
964 delete lastNode;
965 }
966 lastNode = it.node();
967 }
968
969 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(lastNode == node, pos);
970
971 unlinkNode(node);
972 delete node;
973
974 return nextNode;
975 }
ChildIterator< T, false > child_iterator
Definition KisForest.h:805
void unlinkNode(Node< T > *node)
Definition KisForest.h:1049
Definition Node.h:24
KisNodeSP node() const
Definition Node.cpp:827
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node(), KisForestDetail::tailSubtreeBegin(), KisForestDetail::tailSubtreeEnd(), and KisForestDetail::Forest< T >::unlinkNode().

◆ erase() [2/2]

template<typename T >
child_iterator KisForestDetail::Forest< T >::erase ( child_iterator pos,
child_iterator end )
inline

erases all elements from pos to end (excluding end)

Returns
end

Definition at line 981 of file KisForest.h.

981 {
982 while (pos != end) {
983 pos = erase(pos);
984 }
985 return pos;
986 }

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

◆ insert()

template<typename T >
template<typename X >
child_iterator KisForestDetail::Forest< T >::insert ( child_iterator pos,
X && value )
inline

Inserts element value into position pos. value becomes the child of the same parent as pos and is placed right before pos.

Returns
iterator pointing to the inserted element

Definition at line 943 of file KisForest.h.

943 {
944 Node<T> *node = new Node<T>(std::forward<X>(value));
945
946 linkNode(pos, node);
947
948 return child_iterator(node, node->parent, 0);
949 }
float value(const T *src, size_t ch)
void linkNode(child_iterator pos, Node< T > *node)
Definition KisForest.h:1027

References KisForestDetail::Forest< T >::linkNode(), KisForestDetail::RootNodeImpl< Base >::parent, and value().

◆ linkAfter()

template<typename T >
void KisForestDetail::Forest< T >::linkAfter ( Node< T > * node,
Node< T > * afterMe )
inlineprivate

Definition at line 1020 of file KisForest.h.

1020 {
1021 if (afterMe) {
1022 node->prevSibling = afterMe;
1023 afterMe->nextSibling = node;
1024 }
1025 }

References KisForestDetail::BaseNode< Base >::nextSibling, and KisForestDetail::BaseNode< Base >::prevSibling.

◆ linkBefore()

template<typename T >
void KisForestDetail::Forest< T >::linkBefore ( Node< T > * node,
Node< T > * beforeMe )
inlineprivate

Definition at line 1013 of file KisForest.h.

1013 {
1014 if (beforeMe) {
1015 node->nextSibling = beforeMe;
1016 beforeMe->prevSibling = node;
1017 }
1018 }

References KisForestDetail::BaseNode< Base >::nextSibling, and KisForestDetail::BaseNode< Base >::prevSibling.

◆ linkNode()

template<typename T >
void KisForestDetail::Forest< T >::linkNode ( child_iterator pos,
Node< T > * node )
inlineprivate

Definition at line 1027 of file KisForest.h.

1027 {
1028 Node<T> *nextNode = pos.node();
1029 RootNode<T> *parentNode = pos.m_parent;
1030
1031 Node<T> *prevNode = nextNode ?
1032 nextNode->prevSibling :
1033 parentNode ? parentNode->lastChild : m_root.lastChild;
1034
1035 linkAfter(node, prevNode);
1036 linkBefore(node, nextNode);
1037
1039 if (!nextNode) {
1040 parentNode->lastChild = node;
1041 }
1042
1043 if (nextNode == parentNode->firstChild) {
1044 parentNode->firstChild = node;
1045 }
1046 node->parent = parentNode;
1047 }
void linkBefore(Node< T > *node, Node< T > *beforeMe)
Definition KisForest.h:1013
void linkAfter(Node< T > *node, Node< T > *afterMe)
Definition KisForest.h:1020
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KisForestDetail::RootNodeImpl< Base >::firstChild, KIS_SAFE_ASSERT_RECOVER_RETURN, KisForestDetail::RootNodeImpl< Base >::lastChild, KisForestDetail::Forest< T >::linkAfter(), KisForestDetail::Forest< T >::linkBefore(), KisForestDetail::ChildIterator< T, is_const >::m_parent, KisForestDetail::Forest< T >::m_root, KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node(), KisForestDetail::RootNodeImpl< Base >::parent, and KisForestDetail::BaseNode< Base >::prevSibling.

◆ move()

template<typename T >
child_iterator KisForestDetail::Forest< T >::move ( child_iterator subtree,
child_iterator newPos )
inline

move a subtree to new position Moves subtree into a new position pointer by newPos. newPos must not be inside the subtree, otherwise cycling links may appear.

Returns
iterator to a new position of subtree

Definition at line 994 of file KisForest.h.

994 {
995 // sanity check for cycling move
996 for (auto it = hierarchyBegin(newPos); it != hierarchyEnd(newPos); ++it) {
997 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(it.node() != subtree.node(), subtree);
998 }
999
1000 Node<T> *node = subtree.node();
1001 unlinkNode(node);
1002
1003 node->prevSibling = nullptr;
1004 node->nextSibling = nullptr;
1005 node->parent = nullptr;
1006
1007 linkNode(newPos, node);
1008 return child_iterator(node, node->parent, 0);
1009 }
ResultIterator hierarchyBegin(Iterator it)
Definition KisForest.h:419
ResultIterator hierarchyEnd(Iterator it)
Definition KisForest.h:427

References KisForestDetail::hierarchyBegin(), KisForestDetail::hierarchyEnd(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KisForestDetail::Forest< T >::linkNode(), KisForestDetail::BaseNode< Base >::nextSibling, KisForestDetail::BaseIterator< BaseClass, T, Tag, is_const >::node(), KisForestDetail::RootNodeImpl< Base >::parent, KisForestDetail::BaseNode< Base >::prevSibling, and KisForestDetail::Forest< T >::unlinkNode().

◆ operator=()

template<typename T >
Forest< T > & KisForestDetail::Forest< T >::operator= ( const Forest< T > & rhs)
inline

Definition at line 794 of file KisForest.h.

794 {
796 for (auto it = rhs.childBegin(); it != rhs.childEnd(); ++it) {
797 auto cloneIt = this->insert(this->childEnd(), *it);
798 cloneChildren(it, cloneIt);
799 }
800 return *this;
801 }

References KisForestDetail::Forest< T >::childBegin(), KisForestDetail::Forest< T >::childEnd(), KisForestDetail::Forest< T >::cloneChildren(), KisForestDetail::Forest< T >::erase(), and KisForestDetail::Forest< T >::insert().

◆ parentEnd() [1/2]

template<typename T >
child_iterator KisForestDetail::Forest< T >::parentEnd ( )
inline

Definition at line 884 of file KisForest.h.

884 {
885 return parentEndImpl(*this);
886 }

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

◆ parentEnd() [2/2]

template<typename T >
const_child_iterator KisForestDetail::Forest< T >::parentEnd ( ) const
inline

Definition at line 896 of file KisForest.h.

896 {
897 return parentEndImpl(*this);
898 }

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

◆ parentEndImpl()

template<typename T >
template<class ForestType , class IteratorType = ChildIterator<typename ForestType::value_type, std::is_const_v<ForestType>>>
static IteratorType KisForestDetail::Forest< T >::parentEndImpl ( ForestType & forest)
inlinestaticprivate

Definition at line 1097 of file KisForest.h.

1097 {
1098 return IteratorType(nullptr, &forest.m_root, -1);
1099 }

◆ swap()

template<typename T >
void KisForestDetail::Forest< T >::swap ( Forest< T > & other)
inline

Definition at line 824 of file KisForest.h.

824 {
825 std::swap(m_root, other.m_root);
826 }

References KisForestDetail::Forest< T >::m_root.

◆ unlinkNode()

template<typename T >
void KisForestDetail::Forest< T >::unlinkNode ( Node< T > * node)
inlineprivate

Definition at line 1049 of file KisForest.h.

1049 {
1050 RootNode<T> *parentNode = node->parent;
1051
1052 if (node->nextSibling) {
1053 node->nextSibling->prevSibling = node->prevSibling;
1054 }
1055
1056 if (node->prevSibling) {
1057 node->prevSibling->nextSibling = node->nextSibling;
1058 }
1059
1061 if (parentNode->firstChild == node) {
1062 parentNode->firstChild = node->nextSibling;
1063 }
1064
1065 if (parentNode->lastChild == node) {
1066 parentNode->lastChild = node->prevSibling;
1067 }
1068 }

References KisForestDetail::RootNodeImpl< Base >::firstChild, KIS_SAFE_ASSERT_RECOVER_RETURN, KisForestDetail::RootNodeImpl< Base >::lastChild, KisForestDetail::BaseNode< Base >::nextSibling, KisForestDetail::RootNodeImpl< Base >::parent, and KisForestDetail::BaseNode< Base >::prevSibling.

Member Data Documentation

◆ m_root

template<typename T >
RootNode<T> KisForestDetail::Forest< T >::m_root
private

Definition at line 1134 of file KisForest.h.


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