iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
iox2::legacy::convert Class Reference

Collection of static methods for conversion from and to string. More...

#include <convert.hpp>

Public Types

enum class  NumberType : uint8_t { INTEGER , UNSIGNED_INTEGER , FLOAT }
 

Public Member Functions

template<>
bb::Optional< std::string > from_string (const char *v) noexcept
 A specialization function of convert::from_string for std::string.
 

Static Public Member Functions

template<typename Source >
static std::enable_if<!std::is_convertible< Source, std::string >::value, std::string >::type toString (const Source &t) noexcept
 Converts every type which is either a pod (plain old data) type or is convertable to a string (this means that the operator std::string() is defined)
 
template<typename Source >
static std::enable_if< std::is_convertible< Source, std::string >::value, std::string >::type toString (const Source &t) noexcept
 Converts every type which is either a pod (plain old data) type or is convertable to a string (this means that the operator std::string() is defined)
 
template<typename TargetType >
static bb::Optional< TargetType > from_string (const char *v) noexcept
 convert the input based on the 'TargetType', allowing only numeric types as valid destination types
 

Static Public Attributes

static constexpr int32_t STRTOULL_BASE { 10 }
 
static constexpr int32_t STRTOUL_BASE { 10 }
 
static constexpr int32_t STRTOLL_BASE { 10 }
 
static constexpr int32_t STRTOL_BASE { 10 }
 
static constexpr uint32_t FLOAT_SIGNALING_NAN_MASK { static_cast<uint32_t>(1) << static_cast<uint32_t>(22) }
 
static constexpr uint64_t DOUBLE_SIGNALING_NAN_MASK { static_cast<uint64_t>(1) << static_cast<uint64_t>(51) }
 

Detailed Description

Collection of static methods for conversion from and to string.

int i;
unsigned int a;
if ( iox2::legacy::convert::from_string("123", i) ) {} // will succeed
if ( iox2::legacy::convert::from_string("-123", a) ) {} // will fail since -123 is not unsigned
static bb::Optional< TargetType > from_string(const char *v) noexcept
convert the input based on the 'TargetType', allowing only numeric types as valid destination types
static std::enable_if<!std::is_convertible< Source, std::string >::value, std::string >::type toString(const Source &t) noexcept
Converts every type which is either a pod (plain old data) type or is convertable to a string (this m...
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
Todo:
iox-#260 Refactor 'convert' so that one can use 'into' to directly to convert numbers to strings: 'ClassExpectingAString(iox2::bb::into<iox2::bb::StaticString<100>>(42)'

Definition at line 47 of file convert.hpp.

Member Enumeration Documentation

◆ NumberType

Enumerator
INTEGER 
UNSIGNED_INTEGER 
FLOAT 

Definition at line 49 of file convert.hpp.

Member Function Documentation

◆ from_string() [1/2]

template<typename TargetType >
static bb::Optional< TargetType > iox2::legacy::convert::from_string ( const char v)
staticnoexcept

convert the input based on the 'TargetType', allowing only numeric types as valid destination types

Note
for the 'TargetType' equal to 'std::string,' please include 'iox/std_string_support.hpp'
Template Parameters
TargetTypethe desired target type for converting text
Parameters
vthe input string in c type
Returns
an iox2::bb::Optional<TargetType> where, if the return value is iox2::bb::NULLOPT, it indicates a failed conversion process

◆ from_string() [2/2]

template<>
bb::Optional< std::string > iox2::legacy::convert::from_string ( const char v)
inlinenoexcept

A specialization function of convert::from_string for std::string.

Parameters
vthe input string in c type
Returns
an iox2::bb::Optional<Destination> where, if the return value is iox2::bb::NULLOPT, it indicates a failed conversion process

Definition at line 31 of file std_string_support.hpp.

References iox2::legacy::always_false_v.

◆ toString() [1/2]

template<typename Source >
static std::enable_if<!std::is_convertible< Source, std::string >::value, std::string >::type iox2::legacy::convert::toString ( const Source t)
staticnoexcept

Converts every type which is either a pod (plain old data) type or is convertable to a string (this means that the operator std::string() is defined)

Parameters
Sourcetype of the value which should be converted to a string
[in]tvalue which should be converted to a string
Returns
string representation of t

◆ toString() [2/2]

template<typename Source >
static std::enable_if< std::is_convertible< Source, std::string >::value, std::string >::type iox2::legacy::convert::toString ( const Source t)
staticnoexcept

Converts every type which is either a pod (plain old data) type or is convertable to a string (this means that the operator std::string() is defined)

Parameters
Sourcetype of the value which should be converted to a string
[in]tvalue which should be converted to a string
Returns
string representation of t

Member Data Documentation

◆ DOUBLE_SIGNALING_NAN_MASK

constexpr uint64_t iox2::legacy::convert::DOUBLE_SIGNALING_NAN_MASK { static_cast<uint64_t>(1) << static_cast<uint64_t>(51) }
staticconstexpr

Definition at line 61 of file convert.hpp.

◆ FLOAT_SIGNALING_NAN_MASK

constexpr uint32_t iox2::legacy::convert::FLOAT_SIGNALING_NAN_MASK { static_cast<uint32_t>(1) << static_cast<uint32_t>(22) }
staticconstexpr

Definition at line 60 of file convert.hpp.

◆ STRTOL_BASE

constexpr int32_t iox2::legacy::convert::STRTOL_BASE { 10 }
staticconstexpr

Definition at line 58 of file convert.hpp.

◆ STRTOLL_BASE

constexpr int32_t iox2::legacy::convert::STRTOLL_BASE { 10 }
staticconstexpr

Definition at line 57 of file convert.hpp.

◆ STRTOUL_BASE

constexpr int32_t iox2::legacy::convert::STRTOUL_BASE { 10 }
staticconstexpr

Definition at line 56 of file convert.hpp.

◆ STRTOULL_BASE

constexpr int32_t iox2::legacy::convert::STRTOULL_BASE { 10 }
staticconstexpr

Definition at line 55 of file convert.hpp.


The documentation for this class was generated from the following files: