NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
Utils Namespace Reference

Functions

std::pair< double, double > dot (Vector< Vector< double > > matrix, std::pair< double, double > &v)
 Compute the dot product of a 2x2 matrix and a 2D vector.
 
double dot (std::pair< double, double > &u, std::pair< double, double > &v)
 Compute the dot product of two 2D vectors.
 
double cross (std::pair< double, double > &u, std::pair< double, double > &v)
 Compute the cross product of two 2D vectors.
 
double getDistanceByTwoCoordinates (const std::pair< double, double > &position1, const std::pair< double, double > &position2)
 Computes the Euclidean distance between two coordinates.
 
double power (double base, int exponent)
 Powers.
 
template<typename T >
requires std::is_arithmetic<T>
::value std::string thousandSeparator (T n, int decimals=3)
 Convert a plain numeric value to thousand separated value.
 
template<typename T >
std::string formatDuration (T seconds)
 Format duration.
 
std::string getFilenameWithoutExtension (std::string path)
 
std::string getPrefix (std::string str)
 
Vector< double > splitStringToDoubleVector (const std::string &input, char delimiter=',')
 Splits string to double vector.
 
Vector< int > splitStringToIntVector (const std::string &str)
 The function stringToIntVector takes a string as input and converts it into a Vector<int> by parsing the string for comma-separated integers and pushing each one onto the vector.
 
Vector< std::string > split (const std::string &s, char delimiter)
 This function is splitting a given string "s" into substrings using a delimiter "delimiter" and returning the resulting substrings as a vector of strings.
 
Vector< int > convertStringVectorToIntVector (const std::vector< std::string > &stringVector)
 
std::string trim (const std::string &str)
 This function trim takes in a string str and returns a copy of it with leading and trailing white spaces removed.
 
bool writeToFile (std::stringstream &s, std::string filename)
 
template<typename... Args>
std::stringstream convertTupleToStringStream (const std::tuple< Args... > &t, int limit, std::string delim="\t")
 
template<typename Tuple , size_t... Indices>
void addTupleValuesToStreamImpl (const Tuple &t, std::stringstream &ss, std::index_sequence< Indices... >, int limit, std::string delim)
 
template<typename T >
void writeToStream (const T &value, std::stringstream &ss, std::string delim)
 
std::string removeLastWord (const std::string &originalString)
 
QVector< double > convertQStringVectorToDouble (const QVector< QString > &stringVector)
 
QVector< double > subtractQVector (const QVector< double > l1, const QVector< double > l2)
 
QVector< double > factorQVector (const QVector< double > l1, const double factor)
 
Vector< std::pair< std::string, std::string > > splitStringStream (std::stringstream &ss, const std::string &delimiter=":")
 
std::string replaceAll (std::string str, const std::string &from, const std::string &to)
 

Function Documentation

◆ addTupleValuesToStreamImpl()

template<typename Tuple , size_t... Indices>
void Utils::addTupleValuesToStreamImpl ( const Tuple &  t,
std::stringstream &  ss,
std::index_sequence< Indices... >  ,
int  limit,
std::string  delim 
)
inline

◆ convertQStringVectorToDouble()

QVector< double > Utils::convertQStringVectorToDouble ( const QVector< QString > &  stringVector)
inline

◆ convertStringVectorToIntVector()

Vector< int > Utils::convertStringVectorToIntVector ( const std::vector< std::string > &  stringVector)
inline

◆ convertTupleToStringStream()

template<typename... Args>
std::stringstream Utils::convertTupleToStringStream ( const std::tuple< Args... > &  t,
int  limit,
std::string  delim = "\t" 
)
inline

◆ cross()

double Utils::cross ( std::pair< double, double > &  u,
std::pair< double, double > &  v 
)
inline

Compute the cross product of two 2D vectors.

Parameters
uA pair of doubles representing the first vector.
vA pair of doubles representing the second vector.
Returns
A double representing the pseudo cross product of the two vectors.
Author
Ahmed Aredah
Date
2/14/2023

◆ dot() [1/2]

double Utils::dot ( std::pair< double, double > &  u,
std::pair< double, double > &  v 
)
inline

Compute the dot product of two 2D vectors.

Parameters
uA pair of doubles representing the first vector.
vA pair of doubles representing the second vector.
Returns
A double representing the dot product of the two vectors.
Author
Ahmed Aredah
Date
2/14/2023

◆ dot() [2/2]

std::pair< double, double > Utils::dot ( Vector< Vector< double > >  matrix,
std::pair< double, double > &  v 
)
inline

Compute the dot product of a 2x2 matrix and a 2D vector.

Parameters
matrixA 2D vector representing a 2x2 matrix.
vA pair of doubles representing a 2D vector.
Returns
A pair of doubles representing the resulting vector after the dot product operation.
Author
Ahmed Aredah
Date
2/14/2023

◆ factorQVector()

QVector< double > Utils::factorQVector ( const QVector< double >  l1,
const double  factor 
)
inline

◆ formatDuration()

template<typename T >
std::string Utils::formatDuration ( seconds)
inline

Format duration.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
secondsThe seconds.
Returns
The formatted duration.
Template Parameters
TGeneric type parameter.

◆ getDistanceByTwoCoordinates()

double Utils::getDistanceByTwoCoordinates ( const std::pair< double, double > &  position1,
const std::pair< double, double > &  position2 
)
inline

Computes the Euclidean distance between two coordinates.

Parameters
position1A pair of doubles representing the first coordinate.
position2A pair of doubles representing the second coordinate.
Returns
The Euclidean distance between position1 and position2.
Author
Ahmed
Date
2/14/2023

◆ getFilenameWithoutExtension()

std::string Utils::getFilenameWithoutExtension ( std::string  path)
inline

◆ getPrefix()

std::string Utils::getPrefix ( std::string  str)
inline

◆ power()

double Utils::power ( double  base,
int  exponent 
)
inline

Powers.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
baseThe base.
exponentThe exponent.
Returns
A double.

◆ removeLastWord()

std::string Utils::removeLastWord ( const std::string &  originalString)
inline

◆ replaceAll()

std::string Utils::replaceAll ( std::string  str,
const std::string &  from,
const std::string &  to 
)
inline

◆ split()

Vector< std::string > Utils::split ( const std::string &  s,
char  delimiter 
)
inline

This function is splitting a given string "s" into substrings using a delimiter "delimiter" and returning the resulting substrings as a vector of strings.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
sA std::string to process.
delimiterThe delimiter.
Returns
A Vector<std::string>

◆ splitStringStream()

Vector< std::pair< std::string, std::string > > Utils::splitStringStream ( std::stringstream &  ss,
const std::string &  delimiter = ":" 
)
inline

◆ splitStringToDoubleVector()

Vector< double > Utils::splitStringToDoubleVector ( const std::string &  input,
char  delimiter = ',' 
)
inline

Splits string to double vector.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
inputThe input.
delimiter(Optional) The delimiter.
Returns
A Vector<double>

◆ splitStringToIntVector()

Vector< int > Utils::splitStringToIntVector ( const std::string &  str)
inline

The function stringToIntVector takes a string as input and converts it into a Vector<int> by parsing the string for comma-separated integers and pushing each one onto the vector.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
strThe string.
Returns
A Vector<int>

◆ subtractQVector()

QVector< double > Utils::subtractQVector ( const QVector< double >  l1,
const QVector< double >  l2 
)
inline

◆ thousandSeparator()

template<typename T >
requires std::is_arithmetic<T>
::value std::string Utils::thousandSeparator ( n,
int  decimals = 3 
)
inline

Convert a plain numeric value to thousand separated value.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
nA T to process.
Returns
A std::string.
Template Parameters
TGeneric type parameter.

◆ trim()

std::string Utils::trim ( const std::string &  str)
inline

This function trim takes in a string str and returns a copy of it with leading and trailing white spaces removed.

Author
Ahmed Aredah
Date
2/28/2023
Parameters
strThe string.
Returns
A std::string.

◆ writeToFile()

bool Utils::writeToFile ( std::stringstream &  s,
std::string  filename 
)
inline

◆ writeToStream()

template<typename T >
void Utils::writeToStream ( const T &  value,
std::stringstream &  ss,
std::string  delim 
)
inline