iceoryx_doc  1.0.1
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
iox::cxx::convert Class Reference

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

#include <convert.hpp>

Public Types

enum class  NumberType { INTEGER , UNSIGNED_INTEGER , FLOAT }
 

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)
 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) More...
 
template<typename Source >
static std::enable_if< std::is_convertible< Source, std::string >::value, std::string >::type toString (const Source &t)
 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) More...
 
template<typename Destination >
static bool fromString (const char *v, Destination &dest)
 Sets dest from a given string. If the conversion fails false is returned and the value of dest is undefined. More...
 
static bool stringIsNumber (const char *v, const NumberType type)
 checks if a given string v is a number More...
 
template<>
bool fromString (const char *v, char &dest)
 
template<>
bool fromString (const char *v, string< 100 > &dest)
 
template<>
bool fromString (const char *v, float &dest)
 
template<>
bool fromString (const char *v, double &dest)
 
template<>
bool fromString (const char *v, long double &dest)
 
template<>
bool fromString (const char *v, uint64_t &dest)
 
template<>
bool fromString (const char *v, uint32_t &dest)
 
template<>
bool fromString (const char *v, uint16_t &dest)
 
template<>
bool fromString (const char *v, uint8_t &dest)
 
template<>
bool fromString (const char *v, int64_t &dest)
 
template<>
bool fromString (const char *v, int32_t &dest)
 
template<>
bool fromString (const char *v, int16_t &dest)
 
template<>
bool fromString (const char *v, int8_t &dest)
 
template<>
bool fromString (const char *v, bool &dest)
 

Static Public Attributes

static constexpr int32_t STRTOULL_BASE = 10
 

Detailed Description

Collection of static methods for conversion from and to string.

std::string number = cxx::convert::toString(123);
std::string someClass = cxx::convert::toString(someToStringConvertableObject);
int i;
unsigned int a;
if ( cxx::convert::fromString("123", i) ) {} // will succeed
if ( cxx::convert::fromString("-123", a) ) {} // will fail since -123 is not unsigned
static bool fromString(const char *v, Destination &dest)
Sets dest from a given string. If the conversion fails false is returned and the value of dest is und...
static std::enable_if<!std::is_convertible< Source, std::string >::value, std::string >::type toString(const Source &t)
Converts every type which is either a pod (plain old data) type or is convertable to a string (this m...
Definition: convert.inl:25

Member Function Documentation

◆ fromString()

template<typename Destination >
static bool iox::cxx::convert::fromString ( const char *  v,
Destination &  dest 
)
static

Sets dest from a given string. If the conversion fails false is returned and the value of dest is undefined.

Parameters
[in]vstring which contains the value of dest
[in]destdestination to which the value should be written
Returns
false = if the conversion fails otherwise true

◆ stringIsNumber()

bool iox::cxx::convert::stringIsNumber ( const char *  v,
const NumberType  type 
)
inlinestatic

checks if a given string v is a number

Parameters
[in]vstring which contains the number
[in]typeis the expected contained type in v
Returns
true if the given string is a number, otherwise false

◆ toString() [1/2]

template<typename Source >
std::enable_if< std::is_convertible< Source, std::string >::value, std::string >::type iox::cxx::convert::toString ( const Source &  t)
inlinestatic

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 iox::cxx::convert::toString ( const Source &  t)
static

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

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