MolSim
Loading...
Searching...
No Matches
Functions
StringUtils Namespace Reference

Namespace defining utility functions for working with strings. More...

Functions

static double toDouble (const std::string &str)
 Converts a string to a double.
 
static double toInt (const std::string &str)
 Converts a string to an integer.
 
template<size_t N>
static std::array< int, N > toIntArray (const std::string &str)
 Converts a string into an integer array.
 
template<size_t N>
static std::array< double, N > toDoubleArray (const std::string &str, bool reqBrackets=true)
 Converts a string into a double array.
 
static WriterType toWriterType (const std::string &type)
 Converts a string to a WriterType enum using a dedicated map.
 
static SimulationType toSimulationType (const std::string &type)
 Converts a string to a SimulationType enum using a dedicated map.
 
static ParallelizationType toParallelizationType (const std::string &type)
 Converts a string to a ParallelizationType enum using a dedicated map.
 
static std::string fromChar (char c)
 Converts a char to a string.
 
static std::string fromWriterType (WriterType writerType)
 Converts a WriterType to a string.
 
static std::string fromSimulationType (SimulationType simulationType)
 Converts a SimulationType to a string.
 
static std::string fromParallelizationType (ParallelizationType parallelizationType)
 Converts a ParallelizationType to a string.
 
template<typename T >
static std::string fromNumber (T number)
 Converts a number to a string.
 
template<typename T >
static std::string fromVector (const std::vector< T > &vec)
 Converts a vector to a string.
 

Detailed Description

Namespace defining utility functions for working with strings.

Function Documentation

◆ fromChar()

static std::string StringUtils::fromChar ( char  c)
inlinestatic

Converts a char to a string.

Parameters
cThe character to be converted.
Returns
The resulting string.

◆ fromNumber()

template<typename T >
static std::string StringUtils::fromNumber ( number)
inlinestatic

Converts a number to a string.

Template Parameters
TThe type of the number.
Parameters
numberThe number to be converted.
Returns
A string representation of the number.

◆ fromParallelizationType()

static std::string StringUtils::fromParallelizationType ( ParallelizationType  parallelizationType)
inlinestatic

Converts a ParallelizationType to a string.

Parameters
parallelizationTypeAn instance of the ParallelizationType enum to be converted.
Returns
The resulting string.

◆ fromSimulationType()

static std::string StringUtils::fromSimulationType ( SimulationType  simulationType)
inlinestatic

Converts a SimulationType to a string.

Parameters
simulationTypeAn instance of the SimulationType enum to be converted.
Returns
The resulting string.

◆ fromVector()

template<typename T >
static std::string StringUtils::fromVector ( const std::vector< T > &  vec)
inlinestatic

Converts a vector to a string.

Template Parameters
TThe type of the vector elements.
Parameters
vecThe vector to stringify.

◆ fromWriterType()

static std::string StringUtils::fromWriterType ( WriterType  writerType)
inlinestatic

Converts a WriterType to a string.

Parameters
writerTypeAn instance of the WriterType enum to be converted.
Returns
The resulting string.

◆ toDouble()

static double StringUtils::toDouble ( const std::string &  str)
inlinestatic

Converts a string to a double.

Parameters
strA reference to the string to be converted.
Returns
The converted string as a double.

◆ toDoubleArray()

template<size_t N>
static std::array< double, N > StringUtils::toDoubleArray ( const std::string &  str,
bool  reqBrackets = true 
)
inlinestatic

Converts a string into a double array.

The string must be of the format "{_, _, ..., _}" (excluding quotes) and contain exactly as many elements as specified. If the string is empty, however, an empty array will always be returned. If the provided length of array is longer than the amount of elements read, the remaining array slots will be filled with zeroes. If the provided length of the array is shorter than the amount of elements read, the array will be truncated.

Each number may have an arbitrary amount of leading whitespaces. Trailing whitespaces are not allowed.

Template Parameters
NThe length of the array.
Parameters
strThe string to be converted, should be formatted as comma-separated decimal numbers between curly braces.
reqBracketsIf specified, the array must be enclosed by curly brackets. Otherwise, the format is simply "_, _, ..., _".
Returns
The corresponding array of doubles.

◆ toInt()

static double StringUtils::toInt ( const std::string &  str)
inlinestatic

Converts a string to an integer.

Parameters
strA reference to the string to be converted.
Returns
The converted string as an int.

◆ toIntArray()

template<size_t N>
static std::array< int, N > StringUtils::toIntArray ( const std::string &  str)
inlinestatic

Converts a string into an integer array.

The string must be of the format "{_, _, ..., _}" (excluding quotes) and contain exactly as many elements as specified. If the string is empty, however, an empty array will always be returned. If the provided length of array is longer than the amount of elements read, the remaining array slots will be filled with zeroes. If the provided length of the array is shorter than the amount of elements read, the array will be truncated.

Each number may have an arbitrary amount of leading whitespaces. Trailing whitespaces are not allowed.

Template Parameters
NThe length of the array.
Parameters
strThe string to be converted, should be formatted as comma-separated integers between curly braces.
Returns
The corresponding array of integers.

◆ toParallelizationType()

static ParallelizationType StringUtils::toParallelizationType ( const std::string &  type)
inlinestatic

Converts a string to a ParallelizationType enum using a dedicated map.

Parameters
typeThe string containing the desired ParallelizationType.
Returns
The desired ParallelizationType enum if the type string is valid, otherwise terminates with error.

◆ toSimulationType()

static SimulationType StringUtils::toSimulationType ( const std::string &  type)
inlinestatic

Converts a string to a SimulationType enum using a dedicated map.

Parameters
typeThe string containing the desired SimulationType.
Returns
The desired SimulationType enum if the type string is valid, otherwise terminates with error.

◆ toWriterType()

static WriterType StringUtils::toWriterType ( const std::string &  type)
inlinestatic

Converts a string to a WriterType enum using a dedicated map.

Parameters
typeThe string containing the desired WriterType.
Returns
The desired WriterType enum if the type string is valid, otherwise terminates with error.