DocWire SDK
DocWire SDK: Deterministic, auditable, and secure data processing in C++20. On-premise by default. No compromises on computational speed.
Toggle main menu visibility
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
21
namespace
docwire::xml
22
{
23
31
template
<safety_policy safety_level = default_safety_level>
32
class
node_ref
33
{
34
public
:
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
56
private
:
57
not_null<std::shared_ptr<iterator_state<safety_level>
>, safety_level> m_state;
58
};
59
66
template
<
typename
T, safety_policy safety_level>
67
requires
convert::conversion_implementation_exists<T, std::string_view>
68
std::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
docwire::not_null
A wrapper for pointer-like types that enforces a non-null invariant.
Definition
not_null.h:41
docwire::xml::node_ref
A reference to the current XML node in the reader.
Definition
xml_node_ref.h:33
docwire::xml::node_ref< safety_level >::state
const not_null< std::shared_ptr< iterator_state< safety_level > >, safety_level > & state() const
Definition
xml_node_ref.h:54
docwire::xml::node_ref::name
std::string_view name() const
Returns the local name of the node.
Definition
xml_node_ref.h:42
docwire::xml::node_ref::depth
non_negative< int, safety_level > depth() const
Returns the depth of the node in the XML tree.
Definition
xml_node_ref.h:50
docwire::xml::node_ref::type
node_type type() const
Returns the type of the node.
Definition
xml_node_ref.h:52
docwire::xml::node_ref::content
std::string_view content() const
Returns the content of the node (e.g., text content).
Definition
xml_node_ref.h:46
docwire::xml::node_ref::node_ref
node_ref(not_null< std::shared_ptr< iterator_state< safety_level > >, safety_level > state)
Constructs a reference from an iterator state.
Definition
xml_node_ref.h:39
docwire::xml::node_ref::full_name
std::string_view full_name() const
Returns the full name (including namespace prefix) of the node.
Definition
xml_node_ref.h:44
docwire::xml::node_ref::string_value
std::string_view string_value() const
Returns the string value of the node (concatenated text of children).
Definition
xml_node_ref.h:48
docwire::convert::conversion_implementation_exists
Definition
convert_base.h:35
docwire::convert::try_to
constexpr std::optional< To > try_to(const From &from) noexcept
Tries to convert a value of type From to type To.
Definition
convert_base.h:65
docwire::xml
XML processing utilities.
Definition
xml_attribute_ref.h:23
docwire::xml::convert_impl
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...
Definition
xml_attribute_ref.h:57
docwire::xml::node_type
node_type
Represents the type of an XML node.
Definition
xml_reader.h:31
docwire::convert::dest_type_tag
A tag type used for dispatching convert_impl overloads based on the destination type.
Definition
convert_base.h:32
docwire::xml::iterator_state
Shared state for XML iterators to coordinate traversal.
Definition
xml_iterator_state.h:26
xml_node_ref.h
Generated by
1.18.0