ADTF
Loading...
Searching...
No Matches
string_conversion.h File Reference
#include <string>
#include <string_view>
#include <sstream>
#include <locale>
#include <array>
#include <limits>
Include dependency graph for string_conversion.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  adtf
 Namespace for all functionality provided by ADTF and its SDKs.
 
namespace  adtf::base
 Namespace for the ADTF Base SDK.
 

Enumerations

enum class  float_format { general = 0 , scientific = 1 , fixed = 2 , hex = 3 }
 

Functions

template<typename T>
std::string adtf::base::string_conversion::detail::float_to_string (T value, float_format format)
 
template<typename T>
adtf::base::string_conversion::detail::string_to_float (std::string_view value)
 
std::pair< int, size_t > adtf::base::string_conversion::detail::get_base (std::string_view value)
 
template<typename T>
std::string adtf::base::string_conversion::to_string (T value, float_format=float_format::fixed)
 
template<>
std::string adtf::base::string_conversion::to_string (float value, float_format format)
 
template<>
std::string adtf::base::string_conversion::to_string (double value, float_format format)
 
template<typename T>
adtf::base::string_conversion::to_number (std::string_view value, int base=0)
 
template<>
float adtf::base::string_conversion::to_number (std::string_view value, int)
 
template<>
double adtf::base::string_conversion::to_number (std::string_view value, int)
 

Detailed Description

Copyright © Audi Electronics Venture GmbH. All rights reserved

Function Documentation

◆ to_number()

template<typename T>
T adtf::base::string_conversion::to_number ( std::string_view value,
int base = 0 )
inline

Convert a string representation of an integer to a numeric value of type T.

Supports an optional leading sign ('+' or '-') as well as the base prefixes "0x"/"0X" (hexadecimal), "0b"/"0B" (binary) and a leading '0' (octal). A negative value is only accepted when T is a signed type; the most negative value (e.g. "-0x80" for int8_t) is representable.

Template Parameters
TThe numeric type the string gets converted to.
Parameters
[in]valueString to convert.
[in]baseNumeric base to use. When 0 (the default), the base is auto-detected from the prefix (see above), otherwise value is parsed using the given base.
Warning
When an explicit base (non-zero) is passed together with a prefixed value (e.g. "0x" or "0b"), the behavior is undefined: the prefix is not stripped and the result depends on the underlying conversion backend.
Returns
Numeric value parsed from value.
Exceptions
std::out_of_rangeIf the parsed value does not fit into the numeric limits of T.
std::runtime_errorIf value is not a valid number, contains trailing characters, or carries a negative sign while T is an unsigned type.