Parfis  v0.0.7
Public Member Functions | Static Public Member Functions | List of all members
parfis::Global Struct Reference

Global functions. More...

#include <global.h>

Public Member Functions

template<>
int setValueVec (std::vector< int > &vecRef, const std::string &str, char bra, char ket)
 Parses string of the format key=[val1, val2, val3, ...], where vals are int. Fills the supplied vector referece. More...
 
template<>
int setValueVec (std::vector< double > &vecRef, const std::string &str, char bra, char ket)
 Parses string of the format key=[val1, val2, val3, ...], where vals are double. Fills the supplied vector referece. More...
 
template<>
double getNthElement (const std::string &str, int n, char splitChar)
 Gets the n-th element from the array contained in the string and separated by the sepStr. More...
 

Static Public Member Functions

static std::string currentDateTime ()
 Get current date and time in the format YYYY-MM-DD HH:mm:ss. More...
 
static std::string removeWhitespace (const std::string &str)
 Remove all characters that return true to ::isspace. More...
 
static std::tuple< std::string, std::string > splitKeyValue (const std::string &str)
 Create key,value pair from "key=value" string. More...
 
static std::tuple< std::string, std::string > splitKeyString (const std::string &str)
 Gets string after '=' and '#' or end of string. Captures all data as value, range and type of the data string. Used mainly for parsing data that is not the value (ex. range). More...
 
static std::string childName (const std::string &str)
 Return last child name if there is a '.' as a parent-child classifier. More...
 
static std::tuple< std::string, std::string > splitDot (const std::string &str)
 Splits string with a dot to two strings, before and after the dot. More...
 
static bool fileExists (const std::string &fname)
 Check if file. More...
 
static std::vector< std::string > getVector (const std::string &str, char bra, char ket)
 Parses string and returns vector of elements. More...
 
static std::vector< std::string > getInheritanceVector (const std::string &str)
 Returns vector of iheritance. More...
 
template<class T >
static int setValueVec (std::vector< T > &vecRef, const std::string &str, char bra, char ket)
 
template<class T >
static T getNthElement (const std::string &str, int n, char splitChar=',')
 
static std::string to_string (double num)
 Convert double to string.
 
static std::string to_string (float num)
 Convert float to string.
 
static std::string to_string (int num)
 Comvert int to string (for completness and use in Vec3D struct)
 

Detailed Description

Global functions.

Member Function Documentation

◆ childName()

std::string parfis::Global::childName ( const std::string &  str)
static

Return last child name if there is a '.' as a parent-child classifier.

Parameters
strstring of the format "parent.child.child..."
Returns
last child name

◆ currentDateTime()

std::string parfis::Global::currentDateTime ( )
static

Get current date and time in the format YYYY-MM-DD HH:mm:ss.

Get current date and time as a string.

Returns
String of current date and time

◆ fileExists()

bool parfis::Global::fileExists ( const std::string &  fname)
static

Check if file.

Parameters
fnameexists

◆ getInheritanceVector()

std::vector< std::string > parfis::Global::getInheritanceVector ( const std::string &  str)
static

Returns vector of iheritance.

Splits a string where the split character is dot and constructs a vector

Parameters
strstring in the format grandparent.parent.child
Returns
vector of parents and children

◆ getNthElement()

template<>
double parfis::Global::getNthElement ( const std::string &  str,
int  n,
char  splitChar 
)

Gets the n-th element from the array contained in the string and separated by the sepStr.

Template Parameters
double
Parameters
strString containing the array of values
nOrder of element to be returned
splitCharSpliting character (default is ',')
Returns
double Nth value of the array, parsed as double.

◆ getVector()

std::vector< std::string > parfis::Global::getVector ( const std::string &  str,
char  bra,
char  ket 
)
static

Parses string and returns vector of elements.

Parameters
strstring to be parsed of the form [a,b,c]
brastarting array character (ex. '[' or '(')
ketending array character (ex. ']' or ')')
Returns
Vector of strings

◆ removeWhitespace()

std::string parfis::Global::removeWhitespace ( const std::string &  str)
static

Remove all characters that return true to ::isspace.

Parameters
stroriginal string
Returns
String with the removed whitespaces

◆ setValueVec() [1/2]

template<>
int parfis::Global::setValueVec ( std::vector< double > &  vecRef,
const std::string &  str,
char  bra,
char  ket 
)

Parses string of the format key=[val1, val2, val3, ...], where vals are double. Fills the supplied vector referece.

Template Parameters
double
Parameters
vecRefVector referece to be filled with data
strData defined as string
braVector starts with bra character (usually '[')
ketVector ends with character (usually ']')
Returns
int Zero on success

◆ setValueVec() [2/2]

template<>
int parfis::Global::setValueVec ( std::vector< int > &  vecRef,
const std::string &  str,
char  bra,
char  ket 
)

Parses string of the format key=[val1, val2, val3, ...], where vals are int. Fills the supplied vector referece.

Template Parameters
int
Parameters
vecRefVector referece to be filled with data
strData defined as string
braVector starts with bra character (usually '[')
ketVector ends with character (usually ']')
Returns
int Zero on success

◆ splitDot()

std::tuple< std::string, std::string > parfis::Global::splitDot ( const std::string &  str)
static

Splits string with a dot to two strings, before and after the dot.

Parameters
strThe string that has data in the forman str1.str2
Returns
Two strings, str1 str2 as tuple

◆ splitKeyString()

std::tuple< std::string, std::string > parfis::Global::splitKeyString ( const std::string &  str)
static

Gets string after '=' and '#' or end of string. Captures all data as value, range and type of the data string. Used mainly for parsing data that is not the value (ex. range).

Parameters
strThe string that has data in the forman key=value <additional data> (range data)
Returns
Key value pair as str

◆ splitKeyValue()

std::tuple< std::string, std::string > parfis::Global::splitKeyValue ( const std::string &  str)
static

Create key,value pair from "key=value" string.

Parameters
strString must be without whitespace characters
Returns
Key value pair as tuple