NAMD
eabffunc.C
Go to the documentation of this file.
1 //
2 // The extended adaptive biasing force method has been contributed to NAMD by the following authors:
3 //
4 // Haohao Fu and Christophe Chipot
5 // Laboratoire International Associ\'e
6 // Centre National de la Recherche Scientifique et University of Illinois at Urbana--Champaign
7 // Unit\'e Mixte de Recherche No. 7565, Universit\'e de Lorraine
8 // B.P. 70239, 54506 Vand\oe uvre-lès-Nancy cedex, France
9 //
10 // Copyright 2016, Centre National de la Recherche Scientifique
11 //
12 
13 #ifndef FUNC_CPP
14 #define FUNC_CPP
15 
16 #include "eabffunc.h"
17 
18 
19 // the trim method of string
20 // accept a string, remove the space in the left and right of the string
21 // return the reference of the same string
22 std::string& eabffunc::trim(std::string &s)
23 {
24  if (s.empty())
25  {
26  return s;
27  }
28 
29  s.erase(0, s.find_first_not_of(" "));
30  s.erase(s.find_last_not_of(" ") + 1);
31  return s;
32 }
33 
34 
35 // the split of string
36 // accept a string, return a vector<string>
37 void eabffunc::split(const std::string &s, std::vector<std::string>& ret)
38 {
39  std::stringstream temp(s);
40  std::string token;
41  while (temp >> token)
42  {
43  ret.push_back(token);
44  }
45 }
46 
47 // convert string to int
48 int eabffunc::chartoint(const std::string& c)
49 {
50  std::stringstream temp(c);
51  int token;
52  temp >> token;
53  return token;
54 }
55 
56 // convert string to double
57 double eabffunc::chartodouble(const std::string& c)
58 {
59  std::stringstream temp(c);
60  double token;
61  temp >> token;
62  return token;
63 }
64 
65 // convert double to int
66 int eabffunc::doubletoint(const double a)
67 {
68  if (a > 0)
69  return int(a + 0.000001);
70  else
71  return int(a - 0.000001);
72 }
73 
74 #endif
std::string & trim(std::string &s)
Definition: eabffunc.C:22
int chartoint(const std::string &c)
Definition: eabffunc.C:48
double chartodouble(const std::string &c)
Definition: eabffunc.C:57
void split(const std::string &s, std::vector< std::string > &ret)
Definition: eabffunc.C:37
int doubletoint(const double)
Definition: eabffunc.C:66