DocWire SDK
DocWire SDK: Deterministic, auditable, and secure data processing in C++20. On-premise by default. No compromises on computational speed.
Loading...
Searching...
No Matches
xml_node_ref.h
1/*********************************************************************************************************************************************/
2/* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3/* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4/* document analysis. Offline processing possible for security and confidentiality */
5/* */
6/* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7/* Project homepage: https://github.com/docwire/docwire */
8/* */
9/* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10/*********************************************************************************************************************************************/
11
12#ifndef DOCWIRE_XML_NODE_REF_H
13#define DOCWIRE_XML_NODE_REF_H
14
15#include <memory>
16#include "xml_iterator_state.h"
17#include "not_null.h"
18#include "ranged.h"
19#include "convert_base.h"
20
21namespace docwire::xml
22{
23
31template <safety_policy safety_level = default_safety_level>
33{
34public:
39 explicit node_ref(not_null<std::shared_ptr<iterator_state<safety_level>>, safety_level> state)
40 : m_state(std::move(state)) {}
41
42 std::string_view name() const { return m_state->xml_reader.name(); }
44 std::string_view full_name() const { return m_state->xml_reader.full_name(); }
46 std::string_view content() const { return m_state->xml_reader.content(); }
48 std::string_view string_value() const { return m_state->xml_reader.string_value(); }
50 non_negative<int, safety_level> depth() const { return m_state->xml_reader.depth(); }
52 node_type type() const { return m_state->xml_reader.type(); }
54 const not_null<std::shared_ptr<iterator_state<safety_level>>, safety_level>& state() const { return m_state; }
55
56private:
58};
59
66template<typename T, safety_policy safety_level>
68std::optional<T> convert_impl(const node_ref<safety_level>& node, convert::dest_type_tag<T>) noexcept
69{
70 return convert::try_to<T>(node.string_value());
71}
72
73}
74
75#endif
A wrapper for pointer-like types that enforces a non-null invariant.
Definition not_null.h:41
A reference to the current XML node in the reader.
const not_null< std::shared_ptr< iterator_state< safety_level > >, safety_level > & state() const
std::string_view name() const
Returns the local name of the node.
non_negative< int, safety_level > depth() const
Returns the depth of the node in the XML tree.
node_type type() const
Returns the type of the node.
std::string_view content() const
Returns the content of the node (e.g., text content).
node_ref(not_null< std::shared_ptr< iterator_state< safety_level > >, safety_level > state)
Constructs a reference from an iterator state.
std::string_view full_name() const
Returns the full name (including namespace prefix) of the node.
std::string_view string_value() const
Returns the string value of the node (concatenated text of children).
constexpr std::optional< To > try_to(const From &from) noexcept
Tries to convert a value of type From to type To.
XML processing utilities.
std::optional< T > convert_impl(const attribute_ref< safety_level > &attr, convert::dest_type_tag< T >) noexcept
Conversion implementation to convert an attribute_ref to another type T. This is done by attempting t...
node_type
Represents the type of an XML node.
Definition xml_reader.h:31
A tag type used for dispatching convert_impl overloads based on the destination type.
Shared state for XML iterators to coordinate traversal.