12 #ifndef DOCWIRE_XML_DESCENDANTS_VIEW_H
13 #define DOCWIRE_XML_DESCENDANTS_VIEW_H
15 #include "xml_nodes.h"
16 #include "xml_iterator_state.h"
17 #include "log_scope.h"
18 #include "xml_node_ref.h"
33 template <safety_policy safety_level = default_safety_level>
40 return iterator{m_state, m_start_depth};
50 : m_state(std::move(state)), m_start_depth(depth)
61 template <safety_policy safety_level>
67 using iterator_concept = std::input_iterator_tag;
68 using difference_type = std::ptrdiff_t;
73 bool operator==(
const sentinel& s)
const {
return m_nodes_iter == s; }
74 reference operator*()
const {
return *m_nodes_iter; }
75 pointer operator->()
const {
return m_nodes_iter.operator->(); }
78 log::scope _{
"start_depth"_v = m_start_depth };
80 if (m_state->m_node_ahead_flag)
82 m_state->m_node_ahead_flag =
false;
89 invalidate_if_out_of_scope();
98 void invalidate_if_out_of_scope()
100 if (m_nodes_iter !=
sentinel{} && (*m_nodes_iter).depth() <= m_start_depth)
102 m_state->m_node_ahead_flag =
true;
103 m_nodes_iter.reset();
108 : m_state(std::move(state)), m_start_depth(start_depth),
112 invalidate_if_out_of_scope();
127 template <safety_policy safety_level>
140 template <safety_policy safety_level>
Represents a logging scope.
A wrapper for pointer-like types that enforces a non-null invariant.
Iterator for recursively traversing descendant nodes.
A view over all descendants of an XML node (recursive).
descendants_view(not_null< std::shared_ptr< iterator_state< safety_level >>, safety_level > state, int depth)
Constructs a view from an iterator state and start depth.
A reference to the current XML node in the reader.
non_negative< int, safety_level > depth() const
Returns the depth of the node in the XML tree.
const not_null< std::shared_ptr< iterator_state< safety_level > >, safety_level > & state() const
Returns the shared iterator state associated with this node reference.
XML processing utilities.
descendants_view< safety_level > descendants(const node_ref< safety_level > &node)
Returns a view of all descendants of the given node.
not_null< std::remove_cvref_t< Ptr > > assume_not_null(Ptr &&ptr)
Wraps a pointer-like object in a not_null, bypassing the runtime check.
A sentinel type used to define the end of a range or view.
Shared state for XML iterators to coordinate traversal.