kblib 0.2.3
General utilities library for modern C++
convert.h File Reference

Provides facilities to convert between various kinds of representations. More...

#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <exception>
#include <iomanip>
#include <sstream>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include "algorithm.h"
#include "iterators.h"
#include "traits.h"
#include <string_view>
#include <strstream>
#include "stringops.h"
#include <iostream>
Include dependency graph for convert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  kblib::constant< T, V >
 
struct  kblib::detail_units::prefix
 
struct  kblib::detail_units::is_si_ratio< R >
 
struct  kblib::detail_units::is_si_ratio< std::atto >
 
struct  kblib::detail_units::is_si_ratio< std::femto >
 
struct  kblib::detail_units::is_si_ratio< std::pico >
 
struct  kblib::detail_units::is_si_ratio< std::nano >
 
struct  kblib::detail_units::is_si_ratio< std::micro >
 
struct  kblib::detail_units::is_si_ratio< std::milli >
 
struct  kblib::detail_units::is_si_ratio< std::centi >
 
struct  kblib::detail_units::is_si_ratio< std::deci >
 
struct  kblib::detail_units::is_si_ratio< std::ratio< 1 > >
 
struct  kblib::detail_units::is_si_ratio< std::deca >
 
struct  kblib::detail_units::is_si_ratio< std::hecto >
 
struct  kblib::detail_units::is_si_ratio< std::kilo >
 
struct  kblib::detail_units::is_si_ratio< std::mega >
 
struct  kblib::detail_units::is_si_ratio< std::giga >
 
struct  kblib::detail_units::is_si_ratio< std::tera >
 
struct  kblib::detail_units::is_si_ratio< std::peta >
 
struct  kblib::detail_units::is_si_ratio< std::exa >
 
struct  kblib::detail_units::unit_conversion< M >
 
struct  kblib::detail_units::nearest_ratio< Num, Den >
 
struct  kblib::lexical_caster< To, From >
 
struct  kblib::lexical_caster< Same, Same >
 
struct  kblib::lexical_caster< std::string, std::string >
 
struct  kblib::lexical_caster< std::string, From >
 
struct  kblib::lexical_caster< To, std::string >
 
struct  kblib::lexical_caster< std::string_view, std::string_view >
 
struct  kblib::lexical_caster< std::string_view, std::string >
 
struct  kblib::lexical_caster< std::string_view, From >
 
struct  kblib::lexical_caster< To, std::string_view >
 

Namespaces

namespace  kblib
 The main namespace in which all entities from kblib are defined.
 
namespace  kblib::detail_convert
 
namespace  kblib::literals
 
namespace  detail_units
 
namespace  kblib::detail_units
 

Macros

#define pFromStr(type, val)   ::kblib::fromStr<type>((val), # type)
 

Typedefs

template<std::intmax_t Num, std::intmax_t Den>
using kblib::detail_units::nearest_ratio_t = typename nearest_ratio< Num, Den >::type
 

Functions

template<int base, typename Int >
auto kblib::to_string (Int num) -> std::string
 
template<typename Int >
auto kblib::to_string (Int num, int base) -> std::string
 
template<typename Result , unsigned variants, std::size_t N>
constexpr auto kblib::detail_convert::read_digits (const char *begin, const char *end, unsigned base, const char(&digits)[N]) -> Result
 
template<typename Result >
constexpr auto kblib::parse_integer (const char *begin, const char *end, int base=0) -> Result
 
template<typename Result , std::size_t N>
constexpr auto kblib::parse_integer (const char(&in)[N], int base=0) -> Result
 
template<typename Result >
constexpr auto kblib::parse_integer (const std::string &in, int base=0) -> Result
 
template<typename Result >
constexpr auto kblib::parse_integer (std::string_view in, int base=0) -> Result
 
template<char... Cs>
constexpr auto kblib::literals::operator""_c ()
 
template<char... Cs>
constexpr auto kblib::literals::operator""_cu ()
 
template<typename E , typename = typename std::enable_if<std::is_enum<E>::value>::type>
constexpr auto kblib::etoi (E e) -> auto
 
template<int maxBufLen = 4096, typename clock , typename duration >
auto kblib::time_to_str (std::chrono::time_point< clock, duration > &tp, const std::string &fmt="%F %T") -> std::string
 
constexpr auto kblib::detail_units::unit_of (std::chrono::nanoseconds) noexcept -> auto
 
constexpr auto kblib::detail_units::unit_of (std::chrono::microseconds) noexcept -> auto
 
constexpr auto kblib::detail_units::unit_of (std::chrono::milliseconds) noexcept -> auto
 
constexpr auto kblib::detail_units::unit_of (std::chrono::seconds) noexcept -> auto
 
constexpr auto kblib::detail_units::unit_of (std::chrono::minutes) noexcept -> auto
 
constexpr auto kblib::detail_units::unit_of (std::chrono::hours) noexcept -> auto
 
constexpr auto kblib::detail_units::name_of (std::atto) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::femto) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::pico) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::nano) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::micro) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::milli) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::centi) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::deci) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::ratio< 1, 1 >) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::deca) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::hecto) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::kilo) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::mega) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::giga) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::tera) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::peta) -> prefix
 
constexpr auto kblib::detail_units::name_of (std::exa) -> prefix
 
constexpr auto kblib::detail_units::largest_power_1000 (std::intmax_t in) -> int
 
constexpr auto kblib::detail_units::largest_power_1000_p (double in) -> int
 
constexpr auto kblib::detail_units::largest_power_1000 (double in) -> int
 
constexpr auto kblib::detail_units::pow1000 (int p) -> double
 
template<std::intmax_t Num, std::intmax_t Den>
auto kblib::detail_units::ratio_to_SI () noexcept -> unit_conversion< std::intmax_t >
 
template<typename Rep , typename Ratio , enable_if_t< detail_units::is_si_ratio< typename Ratio::type >::value > * = 0>
auto kblib::duration_to_str (std::chrono::duration< Rep, Ratio > &d) -> std::string
 
template<typename Rep >
auto kblib::duration_to_str (std::chrono::duration< Rep, std::ratio< 60 > > d) -> std::string
 
template<typename Rep >
auto kblib::duration_to_str (std::chrono::duration< Rep, std::ratio< 3600 > > d) -> std::string
 
template<typename string >
auto kblib::url_encode (const string &value) -> std::string
 
template<typename string >
auto kblib::html_encode (const string &data) -> std::string
 
auto kblib::escapify (char c) -> std::string
 
template<typename string >
auto kblib::escapify (const string &value) -> std::string
 
template<typename string >
auto kblib::calculate_translated_index (string &&value, const char *p) -> std::ptrdiff_t
 
auto kblib::calculate_translated_index (const char *value, const char *p) -> std::ptrdiff_t
 
template<typename character , enable_if_t< is_character_v< character > > * = nullptr>
auto kblib::quoted (character c) -> std::string
 
template<typename string , enable_if_t< not is_character_v< string > > * = nullptr>
auto kblib::quoted (string &&in) -> std::string
 
template<typename T >
auto kblib::fromStr (const std::string &val, const char *type=typeid(T).name()) -> T
 
template<>
auto kblib::fromStr (const std::string &val, const char *) -> std::string
 
template<>
auto kblib::fromStr (const std::string &val, const char *type) -> bool
 
template<typename T >
auto kblib::fromStr (std::string &&val, const char *type=typeid(T).name()) -> T
 
template<>
auto kblib::fromStr (std::string &&val, const char *) -> std::string
 
template<>
auto kblib::fromStr (std::string &&val, const char *type) -> bool
 
template<>
auto kblib::fromStr (const std::string &val, const char *) -> std::string_view
 
template<>
auto kblib::fromStr (std::string &&, const char *) -> std::string_view=delete
 
template<typename T >
auto kblib::fromStr (std::string_view val, const char *type=typeid(T).name()) -> T
 
template<>
auto kblib::fromStr (std::string_view val, const char *) -> std::string_view
 
template<>
auto kblib::fromStr (std::string_view val, const char *) -> std::string
 
template<>
auto kblib::fromStr (std::string_view val, const char *type) -> bool
 
template<typename To , std::size_t N>
auto kblib::fromStr (const char(&val)[N], const char *type=typeid(To).name()) -> To
 
template<typename To , typename _ >
auto kblib::fromStr (const char *val, const char *type=typeid(To).name(), _=0) -> To
 
template<typename T >
auto kblib::toStr (T val) -> std::string
 
auto kblib::toStr (std::string val) -> std::string
 
template<typename To , typename From >
auto kblib::lexical_cast (const From &val, const char *type=typeid(To).name()) -> To
 

Detailed Description

Provides facilities to convert between various kinds of representations.

Author
killerbee
Date
2019-2021

Definition in file convert.h.

Macro Definition Documentation

◆ pFromStr

#define pFromStr (   type,
  val 
)    ::kblib::fromStr<type>((val), # type)

Definition at line 33 of file convert.h.