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
docwire::convert Namespace Reference

Namespace for type conversion utilities. More...

Classes

struct  dest_type_tag
 A tag type used for dispatching convert_impl overloads based on the destination type. More...
 

Functions

template<typename To , typename From >
requires constexpr conversion_implementation_exists< To, From > std::optional< To > try_to (const From &from) noexcept
 Tries to convert a value of type From to type To. More...
 
template<typename To , typename From >
requires conversion_implementation_exists< To, From > To to (const From &from)
 Converts a value of type From to type To. More...
 
DOCWIRE_CORE_EXPORT std::optional< std::chrono::sys_seconds > convert_impl (with::date_format::iso8601 s, dest_type_tag< std::chrono::sys_seconds >) noexcept
 Converts an ISO 8601 date string to sys_seconds.
 
DOCWIRE_CORE_EXPORT std::optional< std::chrono::sys_seconds > convert_impl (with::date_format::openoffice_legacy s, dest_type_tag< std::chrono::sys_seconds >) noexcept
 Converts a legacy OpenOffice date string to sys_seconds.
 
DOCWIRE_CORE_EXPORT std::optional< std::chrono::sys_seconds > convert_impl (with::date_format::asn1 s, dest_type_tag< std::chrono::sys_seconds >) noexcept
 Converts an ASN.1 date string to sys_seconds.
 
DOCWIRE_CORE_EXPORT std::optional< std::string > convert_impl (std::chrono::sys_seconds tp, dest_type_tag< std::string >) noexcept
 Converts sys_seconds to a string representation.
 

Variables

template<typename To , typename From >
concept conversion_implementation_exists
 
template<typename T >
concept is_from_chars_compatible = (std::is_integral_v<T> && !std::is_same_v<T, bool>) || std::is_floating_point_v<T>
 Concept checking if a type is compatible with std::from_chars.
 

Detailed Description

Namespace for type conversion utilities.

Function Documentation

◆ to()

template<typename To , typename From >
requires conversion_implementation_exists<To, From> To docwire::convert::to ( const From &  from)

Converts a value of type From to type To.

Template Parameters
ToThe target type.
FromThe source type.
Parameters
fromThe value to convert.
Exceptions
docwire::errorwith docwire::errors::uninterpretable_data tag attached if the conversion fails.

Definition at line 79 of file convert_base.h.

◆ try_to()

template<typename To , typename From >
requires constexpr conversion_implementation_exists<To, From> std::optional<To> docwire::convert::try_to ( const From &  from)
constexprnoexcept

Tries to convert a value of type From to type To.

Template Parameters
ToThe target type.
FromThe source type.
Parameters
fromThe value to convert.
Returns
An optional containing the converted value if successful, or std::nullopt otherwise.

Definition at line 65 of file convert_base.h.

Variable Documentation

◆ conversion_implementation_exists

template<typename To , typename From >
concept docwire::convert::conversion_implementation_exists
Initial value:
= requires(const From& from) {
{ convert_impl(from, convert::dest_type_tag<To>{}) } noexcept -> std::same_as<std::optional<To>>;
}
DOCWIRE_CORE_EXPORT std::optional< std::chrono::sys_seconds > convert_impl(with::date_format::iso8601 s, dest_type_tag< std::chrono::sys_seconds >) noexcept
Converts an ISO 8601 date string to sys_seconds.
requires(std::is_arithmetic_v< T > &&!value_alternative< T >) struct serializer< T >
Specialization for arithmetic types (integers, floats).

Definition at line 35 of file convert_base.h.