Utils

Some useful functions,classes and templates that are used to perform standard programming tasks (like serialization, formatting, time measurement etc.). More...

Classes

class  julian::DataFrame
 Class used to handle data read from csv files. More...
 
class  julian::DataEntryClerk
 Class used to provide data to julian::DataFrame. More...
 
class  julian::ObjectFactory< T >
 Class implements a factory pattern. More...
 
class  julian::RunTimeMeasurment
 Class used to measure run time of the program. More...
 
class  julian::SmartPointer< T >
 Template of deep-coping smart pointer. More...
 
class  julian::ValueFactory< T >
 Class implements a factory pattern. More...
 

Functions

std::string julian::formatter::currency (double x)
 Function converts double to money value. More...
 
std::string julian::formatter::percentage (double x)
 Function converts double to percentage. More...
 
template<class T >
void serializeText (T object, std::string file)
 Serialize object to text file. More...
 
template<class T >
void serializeBinary (T object, std::string file)
 Serialize object to binary file. More...
 
template<class T >
void serializeXML (T object, std::string file)
 Serialize object to xml file. More...
 
template<class T >
deserializeText (std::string file)
 Deserializes object from text file. More...
 
template<class T >
deserializeBinary (std::string file)
 Deserializes object from binary file. More...
 
template<class T >
deserializeXML (std::string file)
 Deserializes object from xml file. More...
 
bool julian::isCloseEnough (double x1, double x2, int n)
 Function checks if difference between two numbers is small enough. More...
 
double julian::roundNumber (double x, int n)
 Function rounds number to a decimal place. More...
 
double julian::convertStr2Dbl (std::string input)
 Function converts string to double. More...
 
std::string julian::convertDbl2Str (double input)
 Function converts double to string. More...
 
std::vector< double > julian::convertStr2Dbl (std::vector< std::string > input)
 Function converts vector of strings to vector of doubles. More...
 
void julian::writeToCsv (std::string file_name, std::map< std::string, std::vector< double > > data)
 Function saves data to csv file. More...
 
std::pair< std::string, std::string > julian::catchDataAndSettingFileNames (int ac, char *av[])
 Function uses boost::program_options to catch the name of data and setting file. More...
 
template<typename T >
std::vector< T > julian::combineVectors (std::vector< T > v1, std::vector< T > v2)
 Combines vector v1 and v2 without duplicates. More...
 
template<class T >
std::ostream & julian::operator<< (std::ostream &s, std::vector< T > &v)
 Overloaded << operator for vectors. More...
 
template<typename T , typename S >
void julian::sort_vectors (std::vector< T > &benchmark, std::vector< S > &sorted)
 Sorting one vector basic on contents of another. More...
 

Detailed Description

Some useful functions,classes and templates that are used to perform standard programming tasks (like serialization, formatting, time measurement etc.).

Function Documentation

std::pair< std::string, std::string > julian::catchDataAndSettingFileNames ( int  ac,
char *  av[] 
)

Function uses boost::program_options to catch the name of data and setting file.

The function catches the program options, that is (name, value) pairs from the user. Allowed programme options are data and settings .

Returns
std::pair of strings: first string is name of data file, second name of settings file
Examples:
algebraicBootstrapperExample.cpp, constrainedBootstrapperExample.cpp, rootFindingBootstrapperExample.cpp, and unconstrainedBootstrapperExample.cpp.
template<typename T >
std::vector< T > julian::combineVectors ( std::vector< T >  v1,
std::vector< T >  v2 
)

Combines vector v1 and v2 without duplicates.

Parameters
v1vector #1
v2vector #2
Returns
Combined vector v1 and v2 without duplicates.
std::string julian::convertDbl2Str ( double  input)

Function converts double to string.

Parameters
input
Returns
std::string
double julian::convertStr2Dbl ( std::string  input)

Function converts string to double.

Parameters
input
Returns
double
std::vector< double > julian::convertStr2Dbl ( std::vector< std::string >  input)

Function converts vector of strings to vector of doubles.

Parameters
input
Returns
std::vector<double>
std::string julian::formatter::currency ( double  x)

Function converts double to money value.

Function converts double to money value. For example: 12345.6789 to 12'345.68

Parameters
xGiven number
Returns
string representing money value
template<class T >
T deserializeBinary ( std::string  file)

Deserializes object from binary file.

Note
Class T must have serialization interface implemented.
template<class T >
T deserializeText ( std::string  file)

Deserializes object from text file.

Note
Class T must have serialization interface implemented.
template<class T >
T deserializeXML ( std::string  file)

Deserializes object from xml file.

Note
Class T must have serialization interface implemented.
bool julian::isCloseEnough ( double  x1,
double  x2,
int  n 
)

Function checks if difference between two numbers is small enough.

Parameters
x1First number
x2Second number
n
Returns
True if difference between x1 and x2 is smaller than $10^{-n}$
template<class T >
std::ostream & julian::operator<< ( std::ostream &  s,
std::vector< T > &  v 
)

Overloaded << operator for vectors.

std::string julian::formatter::percentage ( double  x)

Function converts double to percentage.

Function converts double to money value. For example: 0.054321 to 5.4321%

Parameters
xGiven number
Returns
string representing money value
double julian::roundNumber ( double  x,
int  n 
)

Function rounds number to a decimal place.

Parameters
xRounded number
nDecimal place
Returns
Rounded to a n-th decimal place
template<class T >
void serializeBinary ( object,
std::string  file 
)

Serialize object to binary file.

Note
Class T must have serialization interface implemented.
Examples:
serializationExample.cpp.
template<class T >
void serializeText ( object,
std::string  file 
)

Serialize object to text file.

Note
Class T must have serialization interface implemented.
template<class T >
void serializeXML ( object,
std::string  file 
)

Serialize object to xml file.

Note
Class T must have serialization interface implemented.
template<typename T , typename S >
julian::sort_vectors ( std::vector< T > &  benchmark,
std::vector< S > &  sorted 
)

Sorting one vector basic on contents of another.

Parameters
benchmarkOn basis of this vector another is sorted
sortedVector that is sorted
void julian::writeToCsv ( std::string  file_name,
std::map< std::string, std::vector< double > >  data 
)

Function saves data to csv file.

Function writes data to csv. Keys of map representing data are columns names. Columns are map's values

Parameters
file_namename of the file
datastd map where keys are column names and values are columns.