DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
xml_attribute_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_ATTRIBUTE_REF_H
13 #define DOCWIRE_XML_ATTRIBUTE_REF_H
14 
15 #include "safety_policy.h"
16 #include "xml_reader.h"
17 #include <functional>
18 #include <string_view>
19 #include <optional>
20 #include "convert_base.h"
21 
22 namespace docwire::xml
23 {
24 
31 template <safety_policy safety_level = default_safety_level>
33 {
34  public:
39  explicit attribute_ref(const reader<safety_level>& reader) : m_reader(reader) {}
41  std::string_view name() const { return m_reader.get().name(); }
43  std::string_view value() const { return m_reader.get().content(); }
44 
45  private:
46  std::reference_wrapper<const reader<safety_level>> m_reader;
47 };
48 
55 template<typename T, safety_policy safety_level>
56 requires convert::conversion_implementation_exists<T, std::string_view>
58 {
59  return convert::try_to<T>(attr.value());
60 }
61 
62 }
63 
64 #endif // DOCWIRE_XML_ATTRIBUTE_REF_H
A reference to an XML attribute.
std::string_view value() const
Returns the value of the attribute.
std::string_view name() const
Returns the name of the attribute.
attribute_ref(const reader< safety_level > &reader)
Constructs a reference from a reader positioned at an attribute.
XML processing utilities.
requires convert::conversion_implementation_exists< T, std::string_view > 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...
requires(!string_method_equipped< T >) struct stringifier< T >
Specialization for types that are streamable to std::ostream.
A tag type used for dispatching convert_impl overloads based on the destination type.
Definition: convert_base.h:32