Class convert

Class Documentation

class convert

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

Public Types

enum class NumberType

Values:

enumerator INTEGER
enumerator UNSIGNED_INTEGER
enumerator FLOAT

Public Static 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)

Parameters:
  • Source – type of the value which should be converted to a string

  • t[in] value which should be converted to a string

Returns:

string representation of t

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)

Parameters:
  • Source – type of the value which should be converted to a string

  • t[in] value which should be converted to a string

Returns:

string representation of t

template<typename Destination>
static bool fromString(const char *v, Destination &dest) noexcept

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

Parameters:
  • v[in] string which contains the value of dest

  • dest[in] destination to which the value should be written

Returns:

false = if the conversion fails otherwise true

static bool stringIsNumber(const char *v, const NumberType type) noexcept

checks if a given string v is a number

Parameters:
  • v[in] string which contains the number

  • type[in] is the expected contained type in v

Returns:

true if the given string is a number, otherwise false

Public Static Attributes

static constexpr int32_t STRTOULL_BASE = 10