Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions Simulating the Schrödinger wave equation using the Crank-Nicolson method in 2+1 dimensions

Loading...
Searching...
No Matches
Macros | Functions
utils.hpp File Reference

Function prototypes and macros that are useful. More...

`#include <armadillo>`
`#include <iomanip>`
`#include <sstream>`
`#include <string>`
`#include <sys/stat.h>`
`#include <vector>`

Go to the source code of this file.

## Macros
#define | DEBUG(msg)
| Writes a debug message.
#define | __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)
| Get the name of the current method/function without the return type.

## Functions
std::string | details::methodName (const std::string &pretty_function)
| Takes in the PRETTY_FUNCTION string and removes the return type.
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.
void | utils::print_sp_matrix_structure (const arma::sp_cx_mat &A)
std::vector< std::string > | utils::split (const std::string &s, char delim)
std::string & | utils::ltrim (std::string &s, const char *t=" \t\n\r\f\v")
std::string & | utils::rtrim (std::string &s, const char *t=" \t\n\r\f\v")
std::string & | utils::trim (std::string &s, const char *t=" \t\n\r\f\v")
std::string | utils::ltrim_copy (std::string s, const char *t=" \t\n\r\f\v")
std::string | utils::rtrim_copy (std::string s, const char *t=" \t\n\r\f\v")
std::string | utils::trim_copy (std::string s, const char *t=" \t\n\r\f\v")

## Detailed Description

Function prototypes and macros that are useful.

Author
  Cory Alexander Balaton (coryab)
  Janita Ovidie Sandtrøen Willumsen (janitaws)

Version
  1.0

These utility function are mainly for convenience and aren't directly related to the project. Anything that is in the details namespace should not be used directly, or else it might cause undefined behavior if not used correctly.

Bug:
  No known bugs

Definition in file utils.hpp.

## Macro Definition Documentation

## ◆ __METHOD_NAME__

#define __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)

Get the name of the current method/function without the return type.

Definition at line 45 of file utils.hpp.

## ◆ DEBUG

#define DEBUG | ( |  | msg | ) |

Writes a debug message.

This macro writes a debug message that includes the filename, line number, and a custom message. The function is wrapped in an ifdef that checks if DBG is defined, so one can choose to display the debug messages by adding the -DDBG flag when compiling.

Definition at line 39 of file utils.hpp.

## 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

  left | The left hand side of the result string
  right | The right hand side of the result string

Returns
  string

## ◆ dirname()

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

Get the directory name of the path.

Parameters

  path | The path to use.

Returns
  string

## ◆ methodName()

std::string details::methodName | ( | const std::string & | pretty_function | ) |
| inline

Takes in the PRETTY_FUNCTION string and removes the return type.

This function should only be used for the METHOD_NAME macro, since it takes the output from PRETTY_FUNCTION and strips the return type.

Parameters

  pretty_function | The string from PRETTY_FUNCTION

Returns
  std::string

Definition at line 58 of file utils.hpp.

## ◆ 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

  path | The path to be created
  mode | The mode/permissions for all the new directories

Returns
  bool Success/Fail

## ◆ 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

  v | The vector to stringify
  width | The reserved width of the string
  prec | The precision of the stringified number

Returns
  std::string

## ◆ 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

  d | The number to stringify
  width | The reserved width of the string
  prec | The precision of the stringified number

Returns
  std::string