22 #ifndef __PLUMED_tools_Tools_h
23 #define __PLUMED_tools_Tools_h
48 const double pi(3.141592653589793238462643383279502884197169399375105820974944592307);
59 static std::vector<std::string>
getWords(
const std::string & line,
const char* sep=NULL,
int* parlevel=NULL,
const char* parenthesis=
"{");
61 static bool getline(FILE*,std::string & line);
67 static bool convert(
const std::string & str,
double & t);
69 static bool convert(
const std::string & str,
float & t);
71 static bool convert(
const std::string & str,
int & t);
73 static bool convert(
const std::string & str,
long int & t);
75 static bool convert(
const std::string & str,
unsigned & t);
79 static bool convert(
const std::string & str,std::string & t);
82 static void convert(T i,std::string & str);
84 static void trim(std::string & s);
88 static double pbc(
double);
95 static bool getKey(std::vector<std::string>& line,
const std::string & key,std::string & s);
98 static bool parse(std::vector<std::string>&line,
const std::string&key,T&val);
101 static bool parseVector(std::vector<std::string>&line,
const std::string&key,std::vector<T>&val);
103 static bool parseFlag(std::vector<std::string>&line,
const std::string&key,
bool&val);
107 template <
typename T>
112 static std::vector<std::string>
ls(
const std::string&);
121 static std::string
extension(
const std::string&);
123 static double fastpow(
double base,
int exp);
127 bool Tools::parse(std::vector<std::string>&line,
const std::string&key,T&val){
129 if(!
getKey(line,key+
"=",s))
return false;
130 if(s.length()>0 && !
convert(s,val))
return false;
137 if(!
getKey(line,key+
"=",s))
return false;
140 std::vector<std::string> words=
getWords(s,
"\t\n ,");
141 for(
unsigned i=0;i<words.size();++i){
143 if(!
convert(words[i],v))
return false;
152 std::sort(vec.begin(), vec.end());
153 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
158 for(std::vector<std::string>::iterator p=line.begin();p!=line.end();++p){
171 if(std::numeric_limits<int>::round_style == std::round_toward_zero) {
172 const double offset=100.0;
173 const double y=x+offset;
174 if(y>=0)
return y-int(y+0.5);
175 else return y-int(y-0.5);
176 }
else if(std::numeric_limits<int>::round_style == std::round_to_nearest) {
178 }
else return x-floor(x+0.5);
183 std::ostringstream ostr;
Simple class to store the index of an atom.
const double epsilon(std::numeric_limits< double >::epsilon())
Very small non-zero number.
const double kBoltzmann(0.0083144621)
Boltzman constant in kj/K.
const double pi(3.141592653589793238462643383279502884197169399375105820974944592307)
PI.