2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
utils.cpp File Reference

Implementation of the utils. More...

#include "utils.hpp"

Go to the source code of this file.

Functions

std::string utils::scientific_format (double d, int width=20, int prec=10)
 Turns a double into a string written in scientific format.
 
std::string utils::scientific_format (const std::vector< double > &v, int width=20, int prec=10)
 Turns a vector of doubles into a string written in scientific format.
 
bool utils::mkpath (std::string path, int mode=0777)
 Make path given.
 
std::string utils::dirname (const std::string &path)
 Get the directory name of the path.
 
std::string utils::concatpath (const std::string &left, const std::string &right)
 Take 2 strings and concatenate them and make sure there is a directory separator (/) between them.
 

Detailed Description

Implementation of the utils.

Author
Cory Alexander Balaton (coryab)
Janita Ovidie Sandtrøen Willumsen (janitaws)
Version
1.0
Bug:
No known bugs

Definition in file utils.cpp.

Function Documentation

◆ concatpath()

std::string utils::concatpath ( const std::string &  left,
const std::string &  right 
)

Take 2 strings and concatenate them and make sure there is a directory separator (/) between them.

This function doesn't care whether or not the values given as parameters are valid path strings. It is the responsibility of the user to make sure that the values given are valid path strings. The function only guarantees that the output string is a valid path string.

Parameters
leftThe left hand side of the result string
rightThe right hand side of the result string
Returns
string

Definition at line 63 of file utils.cpp.

◆ dirname()

std::string utils::dirname ( const std::string &  path)

Get the directory name of the path.

Parameters
pathThe path to use.
Returns
string

Definition at line 58 of file utils.cpp.

◆ mkpath()

bool utils::mkpath ( std::string  path,
int  mode = 0777 
)

Make path given.

This tries to be the equivalent to "mkdir -p" and creates a new directory whenever it needs to.

Parameters
pathThe path to be created
modeThe mode/permissions for all the new directories
Returns
bool Success/Fail

Definition at line 32 of file utils.cpp.

◆ scientific_format() [1/2]

std::string utils::scientific_format ( const std::vector< double > &  v,
int  width = 20,
int  prec = 10 
)

Turns a vector of doubles into a string written in scientific format.

The code is stolen from https://github.com/anderkve/FYS3150.

Parameters
vThe vector to stringify
widthThe reserved width of the string
precThe precision of the stringified number
Returns
std::string

Definition at line 23 of file utils.cpp.

◆ scientific_format() [2/2]

std::string utils::scientific_format ( double  d,
int  width = 20,
int  prec = 10 
)

Turns a double into a string written in scientific format.

The code is stolen from https://github.com/anderkve/FYS3150.

Parameters
dThe number to stringify
widthThe reserved width of the string
precThe precision of the stringified number
Returns
std::string

Definition at line 16 of file utils.cpp.