Empty class which just contains several (static) tools. More...
#include <Tools.h>
Classes | |
class | DirectoryChanger |
Tiny class that changes directory and comes back when going out of scope. More... | |
Static Public Member Functions | |
static double | bessel0 (const double &val) |
Modified 0th-order Bessel function of the first kind. More... | |
static bool | caseInSensStringCompare (const std::string &str1, const std::string &str2) |
compare two string in a case insensitive manner More... | |
static bool | convert (const std::string &str, double &t) |
Convert a string to a double, reading it. More... | |
static bool | convert (const std::string &str, long double &t) |
Convert a string to a long double, reading it. More... | |
static bool | convert (const std::string &str, float &t) |
Convert a string to a float, reading it. More... | |
static bool | convert (const std::string &str, int &t) |
Convert a string to a int, reading it. More... | |
static bool | convert (const std::string &str, long int &t) |
Convert a string to a long int, reading it. More... | |
static bool | convert (const std::string &str, unsigned &t) |
Convert a string to an unsigned int, reading it. More... | |
static bool | convert (const std::string &str, AtomNumber &t) |
Convert a string to a atom number, reading it. More... | |
static bool | convert (const std::string &str, std::string &t) |
Convert a string to a string (i.e. copy) More... | |
template<typename T > | |
static void | convert (T i, std::string &str) |
Convert anything into a string. More... | |
static std::string | extension (const std::string &) |
Extract the extensions from a file name. More... | |
static double | fastpow (double base, int exp) |
Fast int power. More... | |
static bool | findKeyword (const std::vector< std::string > &line, const std::string &key) |
Find a keyword on the input line, just reporting if it exists or not. More... | |
static bool | getKey (std::vector< std::string > &line, const std::string &key, std::string &s, int rep=-1) |
Retrieve a key from a vector of options. More... | |
static bool | getline (FILE *, std::string &line) |
Get a line from the file pointer ifile. More... | |
static bool | getParsedLine (IFile &ifile, std::vector< std::string > &line) |
Get a parsed line from the file pointer ifile This function already takes care of joining continued lines and splitting the resulting line into an array of words. More... | |
static std::vector< std::string > | getWords (const std::string &line, const char *sep=NULL, int *parlevel=NULL, const char *parenthesis="{") |
Split the line in words using separators. More... | |
static void | interpretLabel (std::vector< std::string > &s) |
interpret ":" syntax for labels More... | |
static void | interpretRanges (std::vector< std::string > &) |
Interpret atom ranges. More... | |
static std::vector< std::string > | ls (const std::string &) |
list files in a directory More... | |
template<class T > | |
static bool | parse (std::vector< std::string > &line, const std::string &key, T &val, int rep=-1) |
Find a keyword on the input line, eventually deleting it, and saving its value to val. More... | |
static bool | parseFlag (std::vector< std::string > &line, const std::string &key, bool &val) |
Find a keyword without arguments on the input line. More... | |
template<class T > | |
static bool | parseVector (std::vector< std::string > &line, const std::string &key, std::vector< T > &val, int rep=-1) |
Find a keyword on the input line, eventually deleting it, and saving its value to a vector. More... | |
static double | pbc (double) |
Apply pbc for a unitary cell. More... | |
template<typename T > | |
static void | removeDuplicates (std::vector< T > &vec) |
Remove duplicates from a vector of type T. More... | |
static bool | startWith (const std::string &full, const std::string &start) |
Check if a string full starts with string start. More... | |
static void | stripLeadingAndTrailingBlanks (std::string &str) |
removes leading and trailing blanks from a string More... | |
static void | trim (std::string &s) |
Remove trailing blanks. More... | |
static void | trimComments (std::string &s) |
Remove trailing comments. More... | |
template<typename T > | |
static std::vector< T * > | unique2raw (const std::vector< std::unique_ptr< T >> &) |
Tool to create a vector of raw pointers from a vector of unique_pointers (const version). More... | |
template<typename T > | |
static std::vector< const T * > | unique2raw (const std::vector< std::unique_ptr< const T >> &) |
Tool to create a vector of raw pointers from a vector of unique_pointers. More... | |
Static Private Member Functions | |
template<class T > | |
static bool | convertToAny (const std::string &str, T &t) |
class to convert a string to a generic type T More... | |
template<class T > | |
static bool | convertToReal (const std::string &str, T &t) |
class to convert a string to a real type T. More... | |
Empty class which just contains several (static) tools.
|
static |
Modified 0th-order Bessel function of the first kind.
|
static |
compare two string in a case insensitive manner
|
static |
Convert a string to a double, reading it.
|
static |
Convert a string to a long double, reading it.
|
static |
Convert a string to a float, reading it.
|
static |
Convert a string to a int, reading it.
|
static |
Convert a string to a long int, reading it.
|
static |
Convert a string to an unsigned int, reading it.
|
static |
Convert a string to a atom number, reading it.
|
static |
Convert a string to a string (i.e. copy)
|
static |
Convert anything into a string.
|
staticprivate |
class to convert a string to a generic type T
|
staticprivate |
class to convert a string to a real type T.
T should be either float, double, or long double
|
static |
Extract the extensions from a file name.
E.g.: extension("pippo.xyz")="xyz". It only returns extensions with a length between 1 and 4 E.g.: extension("pippo.12345")="" whereas extenion("pippo.1234")="1234"; It is also smart enough to detect "/", so that extension("pippo/.t")="" whereas extension("pippo/a.t")="t"
|
inlinestatic |
Fast int power.
|
static |
Find a keyword on the input line, just reporting if it exists or not.
|
static |
Retrieve a key from a vector of options.
It finds a key starting with "key=" or equal to "key" and copy the part after the = on s. E.g.: line.push_back("aa=xx"); getKey(line,"aa",s); will set s="xx"
|
static |
Get a line from the file pointer ifile.
|
static |
Get a parsed line from the file pointer ifile This function already takes care of joining continued lines and splitting the resulting line into an array of words.
|
static |
Split the line in words using separators.
It also take into account parenthesis. Outer parenthesis found are removed from output, and the text between them is considered as a single word. Only the outer parenthesis are processed, to allow nesting them. parlevel, if not NULL, is increased or decreased according to the number of opened/closed parenthesis
|
static |
interpret ":" syntax for labels
|
static |
Interpret atom ranges.
|
static |
list files in a directory
|
static |
Find a keyword on the input line, eventually deleting it, and saving its value to val.
|
inlinestatic |
Find a keyword without arguments on the input line.
|
static |
Find a keyword on the input line, eventually deleting it, and saving its value to a vector.
|
inlinestatic |
Apply pbc for a unitary cell.
beware: this brings any number into a pbc that ranges from -0.5 to 0.5
|
static |
Remove duplicates from a vector of type T.
|
static |
Check if a string full starts with string start.
Same as full.find(start)==0
|
static |
removes leading and trailing blanks from a string
|
static |
Remove trailing blanks.
|
static |
Remove trailing comments.
|
static |
Tool to create a vector of raw pointers from a vector of unique_pointers (const version).
Returning a vector is fast in C++11. It can be used in order to feed a vector<unique_ptr<T>> to a function that takes a vector<T*>.
// some function that takes a vec void func(std::vector<Data*> & vec); std::vector<std::unique_ptr<Data>> vec; // func(vec); // does not compile func(Tools::unique2raw(vec)); // compiles
Notice that the conversion is fast but takes some time to allocate the new vector and copy the pointers. In case the function acting on the vector<T*> is very fast and we do not want to add significant overhead, it might be convenient to store a separate set of raw pointers.
// some function that takes a vec void func(std::vector<Data*> & vec); std::vector<std::unique_ptr<Data>> vec; // conversion done only once: auto vec_ptr=Tools::unique2raw(vec); for(int i=0;i<1000;i++){ func(vec_ptr); }
|
static |
Tool to create a vector of raw pointers from a vector of unique_pointers.
See the non const version.
Hosted by GitHub | 1.8.14 |