2 Dimensional Ising Model
Simulate the change in energy and magnetization in a ferro magnet
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1
17#ifndef __UTILS__
18#define __UTILS__
19
20#include <armadillo>
21#include <iomanip>
22#include <sstream>
23#include <string>
24#include <sys/stat.h>
25#include <vector>
26
35#ifdef DBG
36#define DEBUG(msg) \
37 std::cout << __FILE__ << " " << __LINE__ << ": " << msg << std::endl
38#else
39#define DEBUG(msg)
40#endif
41
45#define __METHOD_NAME__ details::methodName(__PRETTY_FUNCTION__)
46
47namespace details {
58inline std::string methodName(const std::string &pretty_function)
59{
60 size_t colons = pretty_function.find("::");
61 size_t begin = pretty_function.substr(0, colons).rfind(" ") + 1;
62 size_t end = pretty_function.rfind("(") - begin;
63
64 return pretty_function.substr(begin, end) + "()";
65}
66
67} // namespace details
68
69namespace utils {
70
81std::string scientific_format(double d, int width = 20, int prec = 10);
82
94std::string scientific_format(const std::vector<double> &v, int width = 20,
95 int prec = 10);
96
107bool mkpath(std::string path, int mode = 0777);
108
115std::string dirname(const std::string &path);
116
117} // namespace utils
118
119#endif
std::string methodName(const std::string &pretty_function)
Takes in the PRETTY_FUNCTION string and removes the return type.
Definition: utils.hpp:58
bool mkpath(std::string path, int mode=0777)
Make path given.
Definition: utils.cpp:32
std::string scientific_format(double d, int width=20, int prec=10)
Turns a double into a string written in scientific format.
Definition: utils.cpp:16
std::string dirname(const std::string &path)
Get the directory name of the path.
Definition: utils.cpp:58