All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Static Public Member Functions | List of all members
PLMD::Tools Class Reference

Empty class which just contains several (static) tools. More...

#include <Tools.h>

Static Public Member Functions

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 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 bool convert (const std::string &str, double &t)
 Convert a string to a 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 void trim (std::string &s)
 Remove trailing blanks. More...
 
static void trimComments (std::string &s)
 Remove trailing comments. More...
 
static double pbc (double)
 Apply pbc for a unitary cell. More...
 
static bool getKey (std::vector< std::string > &line, const std::string &key, std::string &s)
 Retrieve a key from a vector of options. More...
 
template<class T >
static bool parse (std::vector< std::string > &line, const std::string &key, T &val)
 Find a keyword on the input line, eventually deleting it, and saving its value to val. More...
 
template<class T >
static bool parseVector (std::vector< std::string > &line, const std::string &key, std::vector< T > &val)
 Find a keyword on the input line, eventually deleting it, and saving its value to a vector. 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...
 
static void interpretRanges (std::vector< std::string > &)
 Interpret atom ranges. More...
 
template<typename T >
static void removeDuplicates (std::vector< T > &vec)
 Remove duplicates from a vector of type T. More...
 
static void interpretLabel (std::vector< std::string > &s)
 interpret ":" syntax for labels More...
 
static std::vector< std::string > ls (const std::string &)
 list files in a directory More...
 
static void stripLeadingAndTrailingBlanks (std::string &str)
 removes leading and trailing blanks from 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...
 

Detailed Description

Empty class which just contains several (static) tools.

Definition at line 52 of file Tools.h.

Member Function Documentation

bool PLMD::Tools::convert ( const std::string &  str,
double &  t 
)
static

Convert a string to a double, reading it.

Definition at line 74 of file Tools.cpp.

bool PLMD::Tools::convert ( const std::string &  str,
float &  t 
)
static

Convert a string to a float, reading it.

Definition at line 67 of file Tools.cpp.

bool PLMD::Tools::convert ( const std::string &  str,
int &  t 
)
static

Convert a string to a int, reading it.

Definition at line 33 of file Tools.cpp.

bool PLMD::Tools::convert ( const std::string &  str,
long int &  t 
)
static

Convert a string to a long int, reading it.

Definition at line 42 of file Tools.cpp.

bool PLMD::Tools::convert ( const std::string &  str,
unsigned &  t 
)
static

Convert a string to an unsigned int, reading it.

Definition at line 51 of file Tools.cpp.

bool PLMD::Tools::convert ( const std::string &  str,
AtomNumber t 
)
static

Convert a string to a atom number, reading it.

Definition at line 60 of file Tools.cpp.

bool PLMD::Tools::convert ( const std::string &  str,
std::string &  t 
)
static

Convert a string to a string (i.e. copy)

Definition at line 107 of file Tools.cpp.

template<typename T >
void PLMD::Tools::convert ( i,
std::string &  str 
)
static

Convert anything into a string.

Definition at line 182 of file Tools.h.

std::string PLMD::Tools::extension ( const std::string &  s)
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"

Definition at line 289 of file Tools.cpp.

double PLMD::Tools::fastpow ( double  base,
int  exp 
)
inlinestatic

Fast int power.

Definition at line 189 of file Tools.h.

bool PLMD::Tools::getKey ( std::vector< std::string > &  line,
const std::string &  key,
std::string &  s 
)
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"

Definition at line 215 of file Tools.cpp.

bool PLMD::Tools::getline ( FILE *  fp,
std::string &  line 
)
static

Get a line from the file pointer ifile.

Definition at line 190 of file Tools.cpp.

bool PLMD::Tools::getParsedLine ( IFile ifile,
std::vector< std::string > &  line 
)
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.

Definition at line 153 of file Tools.cpp.

vector< string > PLMD::Tools::getWords ( const std::string &  line,
const char *  sep = NULL,
int *  parlevel = NULL,
const char *  parenthesis = "{" 
)
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

Definition at line 112 of file Tools.cpp.

void PLMD::Tools::interpretLabel ( std::vector< std::string > &  s)
static

interpret ":" syntax for labels

Definition at line 261 of file Tools.cpp.

void PLMD::Tools::interpretRanges ( std::vector< std::string > &  s)
static

Interpret atom ranges.

Definition at line 231 of file Tools.cpp.

vector< string > PLMD::Tools::ls ( const std::string &  d)
static

list files in a directory

Definition at line 272 of file Tools.cpp.

template<class T >
bool PLMD::Tools::parse ( std::vector< std::string > &  line,
const std::string &  key,
T &  val 
)
static

Find a keyword on the input line, eventually deleting it, and saving its value to val.

Definition at line 127 of file Tools.h.

bool PLMD::Tools::parseFlag ( std::vector< std::string > &  line,
const std::string &  key,
bool &  val 
)
inlinestatic

Find a keyword without arguments on the input line.

Definition at line 157 of file Tools.h.

template<class T >
bool PLMD::Tools::parseVector ( std::vector< std::string > &  line,
const std::string &  key,
std::vector< T > &  val 
)
static

Find a keyword on the input line, eventually deleting it, and saving its value to a vector.

Definition at line 135 of file Tools.h.

double PLMD::Tools::pbc ( double  x)
inlinestatic

Apply pbc for a unitary cell.

beware: this brings any number into a pbc that ranges from -0.5 to 0.5

Definition at line 170 of file Tools.h.

template<typename T >
void PLMD::Tools::removeDuplicates ( std::vector< T > &  vec)
static

Remove duplicates from a vector of type T.

Definition at line 150 of file Tools.h.

void PLMD::Tools::stripLeadingAndTrailingBlanks ( std::string &  str)
static

removes leading and trailing blanks from a string

Definition at line 283 of file Tools.cpp.

void PLMD::Tools::trim ( std::string &  s)
static

Remove trailing blanks.

Definition at line 205 of file Tools.cpp.

void PLMD::Tools::trimComments ( std::string &  s)
static

Remove trailing comments.

Definition at line 210 of file Tools.cpp.


The documentation for this class was generated from the following files: