12 #ifndef DOCWIRE_XML_ATTRIBUTES_H
13 #define DOCWIRE_XML_ATTRIBUTES_H
15 #include "safety_policy.h"
16 #include "xml_node_ref.h"
17 #include "xml_attribute_ref.h"
20 #include "convert_base.h"
39 template <safety_policy safety_level = default_safety_level>
51 m_reader.get().move_to_element();
61 std::reference_wrapper<reader<safety_level>> m_reader;
72 template<safety_policy safety_level>
87 template<safety_policy safety_level>
90 auto attrs = attributes<safety_level>(node);
91 if (
auto it = std::ranges::find_if(attrs, [name](
const auto& attr) {
return attr.name() == name; }); it != attrs.end())
106 template<
typename T, safety_policy safety_level>
107 requires convert::conversion_implementation_exists<T, std::string_view>
111 return convert::try_to<T>(*sv);
118 template<safety_policy safety_level>
122 using iterator_concept = std::input_iterator_tag;
123 using difference_type = std::ptrdiff_t;
128 bool operator==(
const sentinel&)
const {
129 return !m_attribute.has_value();
141 if (m_attribute.has_value() && !m_reader.get().move_to_next_attribute()) {
147 void operator++(
int) {
155 if (m_reader.get().move_to_first_attribute()) {
156 m_attribute.emplace(m_reader.get());
159 std::reference_wrapper<reader<safety_level>> m_reader;
A generic wrapper for dereferenceable types (like pointers and optionals) that provides checked acces...
A reference to an XML attribute.
Iterator for traversing XML attributes.
A view over the attributes of an XML node.
~attributes_view() noexcept(noexcept(m_reader.get().move_to_element()))
Destructor. Moves the reader back to the element containing the attributes to ensure consistent state...
attributes_view(reader< safety_level > &reader)
Constructs a view from a reader.
A reference to the current XML node in the reader.
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.
attributes_view< safety_level > attributes(const node_ref< safety_level > &node)
A factory function to create an attributes_view with a specified safety policy.
checked< std::optional< std::string_view >, safety_level > attribute_value(const node_ref< safety_level > &node, std::string_view name)
A convenience helper to find an attribute by name.
requires(!string_method_equipped< T >) struct stringifier< T >
Specialization for types that are streamable to std::ostream.
A sentinel type used to define the end of a range or view.