11#include <boost/iterator/iterator_facade.hpp>
12#include <boost/iterator/iterator_adaptor.hpp>
21template <
typename Base>
34template <
typename Base>
45 explicit Node(X &&newValue)
61template <
typename BaseClass,
typename T,
typename Tag,
bool is_const>
63 public boost::iterator_facade <BaseClass,
66 std::add_lvalue_reference_t<
67 std::add_const_if_t<is_const, T>>>
85 typename std::iterator_traits<BaseIterator>::reference
dereference()
const {
90 bool equal(
const BaseClass &other)
const {
91 return m_node == other.m_node;
159template <
typename T,
bool is_const>
163 boost::bidirectional_traversal_tag,
167 BaseIterator <ChildIterator<T, is_const>,
169 boost::bidirectional_traversal_tag,
189 template <
typename X,
bool c>
191 template <
typename X,
bool c>
193 template <
typename X,
bool c>
195 template <
typename X,
bool c>
197 template <
typename X,
bool c>
200 template <
typename X,
bool c>
202 template <
typename X>
friend class Forest;
211 this->
m_node->prevSibling :
227template <
typename value_type,
bool is_const>
231 dbg.nospace() <<
"ChildIterator(" << it.
node() <<
"(" << it.
node()->value <<
")" <<
", parent:" << it.
m_parent <<
")";
233 dbg.nospace() <<
"ChildIterator(" <<
"nullptr" <<
", parent:" << it.
m_parent <<
", offset:" << it.
m_offsetToParent <<
")";
239template <
typename value_type,
bool is_const>
245template <
typename value_type,
bool is_const>
254template <
typename value_type,
bool is_const>
261template <
typename Iterator,
262 bool is_const = std::is_const_v<typename Iterator::NodeType>,
263 typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
270 return ResultIterator(it.node(), it.node() ? it.node()->parent :
nullptr, 0);
273template <
typename Iterator,
274 bool is_const = std::is_const_v<typename Iterator::NodeType>,
275 typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
281template <
typename Iterator,
282 bool is_const = std::is_const_v<typename Iterator::NodeType>,
283 typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
289 template <
typename value_type,
bool is_const>
299template <
typename value_type,
bool is_const>
309template <
typename Iterator,
310 bool is_const = std::is_const_v<typename Iterator::NodeType>,
311 typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
317template <
typename Iterator,
318 bool is_const = std::is_const_v<typename Iterator::NodeType>,
319 typename ResultIterator = ChildIterator<typename Iterator::value_type, is_const>>
326template <
typename value_type,
bool is_const>
333 NodeType *parentNode =
static_cast<NodeType*
>(it.
m_parent);
340template <
typename T,
bool is_const>
380template <
typename T,
bool is_const>
384 boost::forward_traversal_tag,
387 using BaseClass = BaseIterator <HierarchyIterator<T, is_const>,
389 boost::forward_traversal_tag,
416template <
typename Iterator,
417 bool is_const = std::is_const_v<typename Iterator::NodeType>,
418 typename ResultIterator = HierarchyIterator<typename Iterator::value_type, is_const>>
421 return ResultIterator(it.node());
424template <
typename Iterator,
425 bool is_const = std::is_const_v<typename Iterator::NodeType>,
426 typename ResultIterator = HierarchyIterator<typename Iterator::value_type, is_const>>
430 return ResultIterator(
nullptr);
484template <
typename T,
bool is_const>
486 public boost::iterator_adaptor<
487 CompositionIterator<T, is_const>,
488 ChildIterator<T, is_const>,
490 boost::forward_traversal_tag>
496 boost::forward_traversal_tag>;
503 using NodeType =
typename BaseIteratorType::NodeType;
506 return this->base().node();
532 this->base_reference() = it;
559template <
typename Iterator,
560 bool is_const = std::is_const_v<typename Iterator::NodeType>,
564 return ResultIterator(it.node(),
Enter);
567template <
typename Iterator,
568 bool is_const = std::is_const_v<typename Iterator::NodeType>,
569 typename ResultIterator = CompositionIterator<typename Iterator::value_type, is_const>>
573 std::next(ResultIterator(it.node(),
Leave)) :
574 ResultIterator(
nullptr,
Leave);
630template <
typename T, TraversalState visit_on,
bool is_const>
632 public boost::iterator_adaptor<
633 DepthFirstIterator<T, visit_on, is_const>,
634 CompositionIterator<T, is_const>,
636 boost::forward_traversal_tag>
642 boost::forward_traversal_tag>;
649 using NodeType =
typename BaseIteratorType::NodeType;
653 bool shouldSkipToBegin =
false)
656 if (shouldSkipToBegin) {
662 return this->base().node();
673 this->base_reference()++;
678 while (this->base().
node() && this->base().state() != state) {
679 this->base_reference()++;
685template <
typename Iterator,
686 bool is_const = std::is_const_v<typename Iterator::NodeType>,
687 typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Enter, is_const>>
690 return ResultIterator(it.node(),
Enter);
693template <
typename Iterator,
694 bool is_const = std::is_const_v<typename Iterator::NodeType>,
695 typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Enter, is_const>>
699 std::next(ResultIterator(it.node(),
Leave)) :
700 ResultIterator(
nullptr,
Leave);
703template <
typename Iterator,
704 bool is_const = std::is_const_v<typename Iterator::NodeType>,
705 typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Leave, is_const>>
708 return ResultIterator(it.node(),
Enter,
true);
711template <
typename Iterator,
712 bool is_const = std::is_const_v<typename Iterator::NodeType>,
713 typename ResultIterator = DepthFirstIterator<typename Iterator::value_type, Leave, is_const>>
717 std::next(ResultIterator(it.node(),
Leave)) :
718 ResultIterator(
nullptr,
Leave);
821 return !
m_root.firstChild;
942 template <
typename X>
963 if (lastNode != node) {
966 lastNode = it.node();
1031 Node<T> *prevNode = nextNode ?
1046 node->
parent = parentNode;
1073 for (;it !=
end; ++it) {
1080 template <
class ForestType,
1081 class IteratorType =
ChildIterator<
typename ForestType::value_type,
1082 std::is_const_v<ForestType>>>
1084 return IteratorType(forest.m_root.firstChild, &forest.m_root, 0);
1087 template <
class ForestType,
1088 class IteratorType =
ChildIterator<
typename ForestType::value_type,
1089 std::is_const_v<ForestType>>>
1091 return IteratorType(
nullptr, &forest.m_root, 0);
1094 template <
class ForestType,
1095 class IteratorType =
ChildIterator<
typename ForestType::value_type,
1096 std::is_const_v<ForestType>>>
1098 return IteratorType(
nullptr, &forest.m_root, -1);
1101 template <
class ForestType,
1104 std::is_const_v<ForestType>>>
1106 return IteratorType(forest.m_root.firstChild);
1109 template <
class ForestType,
1112 std::is_const_v<ForestType>>>
1115 return IteratorType(
nullptr);
1118 template <
class ForestType,
1120 std::is_const_v<ForestType>>>
1122 return IteratorType(forest.m_root.firstChild);
1125 template <
class ForestType,
1127 std::is_const_v<ForestType>>>
1130 return IteratorType(
nullptr);
1137template <
typename T>
1143template <
typename T>
1150template <
typename T>
1156template <
typename T>
1162template <
typename T>
1168template <
typename T>
1175template <
typename T>
1181template <
typename T>
1188template <
typename T>
1194template <
typename T>
1200template <
typename T>
1206template <
typename T>
1212template <
typename T>
1217 int currentDepth = 0;
1219 for (
auto it = beginIt; it != endIt; ++it) {
1223 return currentDepth;
1226template <
typename T>
1231template <
typename T>
1233 return std::distance(begin(forest), end(forest));
1238using std::make_reverse_iterator;
1242using std::find_if_not;
float value(const T *src, size_t ch)
std::iterator_traits< BaseIterator >::reference dereference() const
bool equal(const BaseClass &other) const
BaseIterator(NodeType *node)
friend class boost::iterator_core_access
std::add_const_if_t< is_const, Node< T > > NodeType
bool equal(const ChildIterator< T, is_const > &other) const
friend QDebug operator<<(QDebug dbg, const ChildIterator< X, c > &it)
friend ChildIterator< X, c > childBegin(const ChildIterator< X, c > &it)
friend ChildIterator< X, c > childEnd(const ChildIterator< X, c > &it)
friend ChildIterator< X, c > parent(const ChildIterator< X, c > &it)
friend ChildIterator< X, c > siblingBegin(const ChildIterator< X, c > &it)
ChildIterator(NodeType *node, RootNodeType *parent, int offsetToParent)
typename BaseClass::NodeType NodeType
std::add_const_if_t< is_const, RootNode< T > > RootNodeType
friend class boost::iterator_core_access
friend ChildIterator< X, c > siblingEnd(const ChildIterator< X, c > &it)
typename BaseIteratorType::RootNodeType RootNodeType
CompositionIterator(NodeType *node, traversal_state state=Enter)
typename CompositionIterator::base_type BaseIteratorType
typename BaseIteratorType::NodeType NodeType
friend class boost::iterator_core_access
bool tryJumpToPos(typename CompositionIterator::base_type it, TraversalState newState)
traversal_state state() const
boost::iterator_adaptor< CompositionIterator< T, is_const >, ChildIterator< T, is_const >, boost::use_default, boost::forward_traversal_tag > BaseClass
boost::iterator_adaptor< DepthFirstIterator< T, visit_on, is_const >, CompositionIterator< T, is_const >, boost::use_default, boost::forward_traversal_tag > BaseClass
typename BaseIteratorType::NodeType NodeType
typename BaseIteratorType::RootNodeType RootNodeType
typename DepthFirstIterator::base_type BaseIteratorType
friend class boost::iterator_core_access
DepthFirstIterator(NodeType *node, traversal_state state=traversal_state::Enter, bool shouldSkipToBegin=false)
void skipToState(TraversalState state)
const_composition_iterator constCompositionBegin() const
child_iterator childEnd()
const_iterator constBegin() const
const_child_iterator constChildBegin() const
static IteratorType parentEndImpl(ForestType &forest)
const_iterator begin() const
const_child_iterator constParentEnd() const
const_depth_first_tail_iterator constDepthFirstTailBegin() const
const_depth_first_tail_iterator depthFirstTailBegin() const
const_child_iterator parentEnd() const
const_iterator end() const
const_child_iterator childEnd() const
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 pla...
child_iterator parentEnd()
Forest< T > & operator=(const Forest< T > &rhs)
depth_first_tail_iterator depthFirstTailEnd()
child_iterator childBegin()
child_iterator move(child_iterator subtree, child_iterator newPos)
move a subtree to new position Moves subtree into a new position pointer by newPos....
const_composition_iterator compositionBegin() const
const_child_iterator constChildEnd() const
const_depth_first_tail_iterator constDepthFirstTailEnd() const
const_depth_first_tail_iterator depthFirstTailEnd() const
composition_iterator compositionBegin()
const_child_iterator childBegin() const
ChildIterator< T, false > child_iterator
static IteratorType beginImpl(ForestType &forest)
composition_iterator compositionEnd()
void linkNode(child_iterator pos, Node< T > *node)
static IteratorType childBeginImpl(ForestType &forest)
const_composition_iterator constCompositionEnd() const
const_iterator constEnd() const
void cloneChildren(const_child_iterator oldParent, child_iterator parent)
depth_first_tail_iterator depthFirstTailBegin()
static IteratorType childEndImpl(ForestType &forest)
Forest(const Forest< T > &rhs)
child_iterator erase(child_iterator pos, child_iterator end)
erases all elements from pos to end (excluding end)
static IteratorType compositionEndImpl(ForestType &forest)
void linkBefore(Node< T > *node, Node< T > *beforeMe)
const_composition_iterator compositionEnd() const
static IteratorType compositionBeginImpl(ForestType &forest)
static IteratorType endImpl(ForestType &forest)
void unlinkNode(Node< T > *node)
child_iterator erase(child_iterator pos)
Removes element at position pos. If pos is 'end', then result is undefined.
void linkAfter(Node< T > *node, Node< T > *afterMe)
std::add_const_if_t< is_const, RootNode< T > > RootNodeType
HierarchyIterator(NodeType *node)
friend class boost::iterator_core_access
typename BaseClass::NodeType NodeType
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
ResultIterator subtreeBegin(Iterator it)
bool isEnd(const ChildIterator< T, is_const > &it)
ResultIterator hierarchyBegin(Iterator it)
ChildIterator< value_type, is_const > childBegin(const ChildIterator< value_type, is_const > &it)
ResultIterator hierarchyEnd(Iterator it)
ChildIterator< value_type, is_const > siblingCurrent(ChildIterator< value_type, is_const > it)
ResultIterator compositionEnd(Iterator it)
QDebug operator<<(QDebug dbg, const ChildIterator< value_type, is_const > &it)
ResultIterator tailSubtreeBegin(Iterator it)
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
int size(const Forest< T > &forest)
ResultIterator compositionBegin(Iterator it)
ChildIterator< value_type, is_const > siblingEnd(const ChildIterator< value_type, is_const > &it)
ResultIterator tailSubtreeEnd(Iterator it)
ChildIterator< value_type, is_const > siblingBegin(const ChildIterator< value_type, is_const > &it)
ChildIterator< value_type, is_const > childEnd(const ChildIterator< value_type, is_const > &it)
int depth(typename Forest< T >::const_child_iterator beginIt, typename Forest< T >::const_child_iterator endIt)
ResultIterator subtreeEnd(Iterator it)
typename add_const_if< is_const, T >::type add_const_if_t
RootNodeImpl< Base > * parent