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
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...

Concepts

concept  conversion_implementation_exists
concept  is_from_chars_compatible
 Concept checking if a type is compatible with std::from_chars.

Functions

template<typename To, typename From>
requires conversion_implementation_exists<To, From>
constexpr std::optional< To > try_to (const From &from) noexcept
 Tries to convert a value of type From to type To.
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.
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.
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.
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.
std::optional< std::string > convert_impl (std::chrono::sys_seconds tp, dest_type_tag< std::string >) noexcept
 Converts sys_seconds to a string representation.
template<is_from_chars_compatible To, std::convertible_to< std::string_view > From>
requires (noexcept(std::string_view(std::declval<const From&>())) && detail::std_from_chars_available<To>)
std::optional< To > convert_impl (const From &s, dest_type_tag< To >) noexcept
 Converts a string-like value to a numeric type using std::from_chars.
template<std::floating_point To, std::convertible_to< std::string_view > From>
requires (noexcept(std::string_view(std::declval<const From&>())) && !detail::std_from_chars_available<To>)
std::optional< To > convert_impl (const From &s, dest_type_tag< To >) noexcept
 Fallback conversion for floating point types when std::from_chars is not available.

Detailed Description

Namespace for type conversion utilities.

Function Documentation

◆ convert_impl() [1/6]

template<std::floating_point To, std::convertible_to< std::string_view > From>
requires (noexcept(std::string_view(std::declval<const From&>())) && !detail::std_from_chars_available<To>)
std::optional< To > docwire::convert::convert_impl ( const From & s,
dest_type_tag< To >  )
noexcept

Fallback conversion for floating point types when std::from_chars is not available.

Definition at line 128 of file convert_numeric.h.

◆ convert_impl() [2/6]

template<is_from_chars_compatible To, std::convertible_to< std::string_view > From>
requires (noexcept(std::string_view(std::declval<const From&>())) && detail::std_from_chars_available<To>)
std::optional< To > docwire::convert::convert_impl ( const From & s,
dest_type_tag< To >  )
noexcept

Converts a string-like value to a numeric type using std::from_chars.

Template Parameters
ToThe target numeric type.
FromThe source string type (must be convertible to string_view).

Definition at line 107 of file convert_numeric.h.

◆ convert_impl() [3/6]

std::optional< std::string > docwire::convert::convert_impl ( std::chrono::sys_seconds tp,
dest_type_tag< std::string >  )
inlinenoexcept

Converts sys_seconds to a string representation.

Definition at line 129 of file convert_chrono.h.

◆ convert_impl() [4/6]

std::optional< std::chrono::sys_seconds > docwire::convert::convert_impl ( with::date_format::asn1 s,
dest_type_tag< std::chrono::sys_seconds >  )
inlinenoexcept

Converts an ASN.1 date string to sys_seconds.

Definition at line 119 of file convert_chrono.h.

◆ convert_impl() [5/6]

std::optional< std::chrono::sys_seconds > docwire::convert::convert_impl ( with::date_format::iso8601 s,
dest_type_tag< std::chrono::sys_seconds >  )
inlinenoexcept

Converts an ISO 8601 date string to sys_seconds.

Definition at line 103 of file convert_chrono.h.

◆ convert_impl() [6/6]

std::optional< std::chrono::sys_seconds > docwire::convert::convert_impl ( with::date_format::openoffice_legacy s,
dest_type_tag< std::chrono::sys_seconds >  )
inlinenoexcept

Converts a legacy OpenOffice date string to sys_seconds.

Definition at line 111 of file convert_chrono.h.

◆ 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.
Examples
xml_parsing_example.cpp.

Definition at line 79 of file convert_base.h.

◆ try_to()

template<typename To, typename From>
requires 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.