OpenABF 2.1.0
Loading...
Searching...
No Matches
Functions
OpenABF::io_utils Namespace Reference

Mesh IO utility functions. More...

Functions

static auto icase_compare (const std::string_view a, const std::string_view b) -> bool
 Compare two string_views, ignoring case.
 
static auto trim_left (std::string_view s) -> std::string_view
 Left trim.
 
static auto trim_right (std::string_view s) -> std::string_view
 Right trim.
 
static auto trim (std::string_view s) -> std::string_view
 Trim from both ends.
 
template<typename... Ds>
static auto split (std::string_view s, const Ds &... ds) -> std::vector< std::string_view >
 Split a string by a delimiter.
 
template<typename T >
auto to_string_view (const T &a, char *buf, const std::size_t &bufSize)
 Convenience wrapper around std::to_chars for converting numerics to std::string_view.
 
template<typename T , typename... Args>
auto to_numeric (const std::string_view str, Args... args) -> T
 Convert a string to a numeric type.
 
template<>
auto to_numeric< float > (const std::string_view str) -> float
 Convert a string to a numeric type.
 
template<>
auto to_numeric< double > (const std::string_view str) -> double
 Convert a string to a numeric type.
 
template<>
auto to_numeric< long double > (const std::string_view str) -> long double
 Convert a string to a numeric type.
 

Detailed Description

Mesh IO utility functions.

Function Documentation

◆ split()

template<typename... Ds>
static auto OpenABF::io_utils::split ( std::string_view  s,
const Ds &...  ds 
) -> std::vector<std::string_view>
staticprivate

Split a string by a delimiter.

When provided conflicting delimiters, the largest delimiter will take precedence:

split("a->b->c", "-", "->"); // returns {"a", "b", "c"}
static auto split(std::string_view s, const Ds &... ds) -> std::vector< std::string_view >
Split a string by a delimiter.
Definition OpenABF.hpp:4474

◆ to_numeric()

template<typename T , typename... Args>
auto OpenABF::io_utils::to_numeric ( const std::string_view  str,
Args...  args 
) -> T
private

Convert a string to a numeric type.

A drop-in replacement for the std:sto family of functions which uses std::from_chars for conversion. Like std::sto, throws exceptions when conversion fails or if the converted value is out of range of the result type.

Exceptions
std::invalid_argumentIf string cannot be converted to the result type.
std::result_out_of_rangeIf converted value is out of range for the result type.
Template Parameters
TRequested numeric type
ArgsParameter pack type
Parameters
strValue to convert
argsExtra parameters passed directly to std::to_chars
Returns
Converted value

◆ to_numeric< double >()

template<>
auto OpenABF::io_utils::to_numeric< double > ( const std::string_view  str) -> double
inlineprivate

Convert a string to a numeric type.

Template specialization as fallback when the compiler does not support std::from_chars for floating point types. Converts the input to a std::string and passes to the appropriate std::sto function.

◆ to_numeric< float >()

template<>
auto OpenABF::io_utils::to_numeric< float > ( const std::string_view  str) -> float
inlineprivate

Convert a string to a numeric type.

Template specialization as fallback when the compiler does not support std::from_chars for floating point types. Converts the input to a std::string and passes to the appropriate std::sto function.

◆ to_numeric< long double >()

template<>
auto OpenABF::io_utils::to_numeric< long double > ( const std::string_view  str) -> long double
inlineprivate

Convert a string to a numeric type.

Template specialization as fallback when the compiler does not support std::from_chars for floating point types. Converts the input to a std::string and passes to the appropriate std::sto function.

◆ to_string_view()

template<typename T >
auto OpenABF::io_utils::to_string_view ( const T &  a,
char buf,
const std::size_t &  bufSize 
)
private

Convenience wrapper around std::to_chars for converting numerics to std::string_view.

Useful during file writing operations when you're reusing a buffer, but don't want to duplicate the error checking code of using std::to_chars.