QMCPACK
SimpleParser.h File Reference
+ Include dependency graph for SimpleParser.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OhmmsAsciiParser
 

Functions

char * readLine (char *s, int max, std::istream &fp)
 
int getwords (std::vector< std::string > &slist, std::istream &fp, int dummy=0, const std::string &extra_tokens="")
 
int getwordsWithMergedNumbers (std::vector< std::string > &slist, std::istream &fp, int dummy=0, const std::string &extra_tokens="")
 
int getwords (std::vector< std::string > &slist, std::istream &fp, std::string &aline)
 
int getwords (std::vector< std::string > &slist, std::istream &fpos, const char *field, const char *terminate)
 
int getXwords (std::vector< std::string > &slist, std::istream &fp)
 
unsigned parsewords (const char *inbuf, std::vector< std::string > &slist, const std::string &extra_tokens="")
 
unsigned parsewords (const char *inbuf, std::list< std::string > &slist)
 
void readXmol (std::istream &, double *, int)
 

Function Documentation

◆ getwords() [1/3]

int getwords ( std::vector< std::string > &  slist,
std::istream &  fp,
int  dummy = 0,
const std::string &  extra_tokens = "" 
)

Definition at line 117 of file SimpleParser.cpp.

References parsewords(), readLine(), and qmcplusplus::Units::time::s.

121 {
122  const int max = 1024;
123  char s[max];
124  if (readLine(s, max, fp))
125  return parsewords(s, slist, extra_tokens);
126  else
127  return -1;
128 }
char * readLine(char *s, int max, std::istream &fp)
unsigned parsewords(const char *inbuf, std::vector< std::string > &slist, const std::string &extra_tokens)

◆ getwords() [2/3]

int getwords ( std::vector< std::string > &  slist,
std::istream &  fp,
std::string &  aline 
)

Definition at line 100 of file SimpleParser.cpp.

References parsewords(), readLine(), and qmcplusplus::Units::time::s.

Referenced by GamesAsciiParser::getCI(), DiracParser::getCOSCI(), GamesAsciiParser::getCSF(), QPParser::getGaussianCenters(), GamesAsciiParser::getGaussianCenters(), DiracParser::getGaussianCenters(), QPParser::getGeometry(), GamesAsciiParser::getGeometry(), DiracParser::getGeometry(), QPParser::getMO(), GamesAsciiParser::getMO(), QPParser::getMO_single_set(), GamesAsciiParser::getMO_single_set(), GamesAsciiParser::getORMAS(), QPParser::getQPCI(), DiracParser::getSpinors(), getwords(), main(), GaussianFCHKParser::parse(), QPParser::parse(), DiracParser::parse(), DiracParser::parseCOSCIOrbInfo(), readXmol(), and qmcplusplus::TEST_CASE().

101 {
102  const int max = 1024;
103  char s[max];
104  if (readLine(s, max, fp))
105  {
106  aline.clear();
107  aline.append(s);
108  return parsewords(s, slist);
109  }
110  else
111  return -1;
112 }
char * readLine(char *s, int max, std::istream &fp)
unsigned parsewords(const char *inbuf, std::vector< std::string > &slist, const std::string &extra_tokens)

◆ getwords() [3/3]

int getwords ( std::vector< std::string > &  slist,
std::istream &  fpos,
const char *  field,
const char *  terminate 
)

Definition at line 179 of file SimpleParser.cpp.

References getwords().

180 {
181  slist.clear();
182  std::array<char, 128> end_key;
183  if (std::snprintf(end_key.data(), end_key.size(), "</%s>", field) < 0)
184  throw std::runtime_error("Error extract end_key from field.");
185 
186  std::vector<std::string> vlist;
187  while (true)
188  {
189  if (getwords(vlist, fpos) == 0)
190  continue;
191  if (vlist[0] == terminate || vlist[0] == end_key.data())
192  break;
193  slist.insert(slist.end(), std::make_move_iterator(vlist.begin()), std::make_move_iterator(vlist.end()));
194  };
195  return slist.size();
196 }
int getwords(std::vector< std::string > &slist, std::istream &fp, std::string &aline)

◆ getwordsWithMergedNumbers()

int getwordsWithMergedNumbers ( std::vector< std::string > &  slist,
std::istream &  fp,
int  dummy = 0,
const std::string &  extra_tokens = "" 
)

Definition at line 132 of file SimpleParser.cpp.

References parsewords(), readLine(), and qmcplusplus::Units::time::s.

Referenced by GamesAsciiParser::getMO_single_set(), and qmcplusplus::TEST_CASE().

136 {
137  const int max = 1024;
138  char s[max];
139  if (readLine(s, max, fp))
140  {
141  std::regex dash("-");
142  const std::string space_dash(" -");
143  std::string merged(s);
144  std::string unmerged = std::regex_replace(merged, dash, space_dash, std::regex_constants::format_default);
145  return parsewords(unmerged.c_str(), slist, extra_tokens);
146  }
147  else
148  {
149  return -1;
150  }
151 }
char * readLine(char *s, int max, std::istream &fp)
unsigned parsewords(const char *inbuf, std::vector< std::string > &slist, const std::string &extra_tokens)

◆ getXwords()

int getXwords ( std::vector< std::string > &  slist,
std::istream &  fp 
)

Definition at line 218 of file SimpleParser.cpp.

References parseXwords(), readLine(), and qmcplusplus::Units::time::s.

219 {
220  const int max = 1024;
221  char s[max];
222  if (readLine(s, max, fp))
223  return parseXwords(s, slist);
224  else
225  return -1;
226 }
char * readLine(char *s, int max, std::istream &fp)
unsigned parseXwords(const char *inbuf, std::vector< std::string > &slist)

◆ parsewords() [1/2]

unsigned parsewords ( const char *  inbuf,
std::vector< std::string > &  slist,
const std::string &  extra_tokens = "" 
)

Definition at line 66 of file SimpleParser.cpp.

Referenced by DiracParser::getCOSCI(), DiracParser::getGaussianCenters(), DiracParser::getGeometry(), GamesAsciiParser::getORMAS(), DiracParser::getSpinors(), getwords(), getwordsWithMergedNumbers(), PairCorrEstimator::PairCorrEstimator(), GaussianFCHKParser::parse(), QPParser::parse(), GamesAsciiParser::parse(), DiracParser::parse(), DiracParser::parseCOSCIOrbInfo(), and qmcplusplus::TEST_CASE().

67 {
68  std::string token = "=, \t\n\"";
69  token.append(extra_tokens);
70 
71  std::string tmpstr(inbuf);
72  slist.clear();
73  int num = 0;
74  char* tokenp = strtok(tmpstr.data(), token.c_str());
75  while (tokenp && tokenp[0] != '#')
76  {
77  num++;
78  slist.push_back(std::string(tokenp));
79  tokenp = strtok(nullptr, token.c_str());
80  }
81  return num;
82 }

◆ parsewords() [2/2]

unsigned parsewords ( const char *  inbuf,
std::list< std::string > &  slist 
)

Definition at line 84 of file SimpleParser.cpp.

85 {
86  const char* token = "=, \t\n";
87  std::string tmpstr(inbuf);
88  slist.clear();
89  unsigned num = 0;
90  char* tokenp = strtok(tmpstr.data(), token);
91  while (tokenp && tokenp[0] != '#')
92  {
93  num++;
94  slist.push_back(std::string(tokenp));
95  tokenp = strtok(nullptr, token);
96  }
97  return num;
98 }

◆ readLine()

char* readLine ( char *  s,
int  max,
std::istream &  fp 
)

Definition at line 28 of file SimpleParser.cpp.

References qmcplusplus::Units::time::s.

Referenced by getwords(), getwordsWithMergedNumbers(), getXwords(), and qmcplusplus::TEST_CASE().

29 {
30  char ch;
31  int i = 0;
32  while (fp.get(ch) && !(ch == '\n' || ch == ';'))
33  {
34  if (ch == '\\') // line continuation character
35  {
36  // check if backslash is followed by a newline
37  fp.get(ch);
38  if (ch == '\n')
39  {
40  // backslash followed by newline, do nothing
41  }
42  else
43  {
44  // backslash not followed by newline
45  if (i < max - 1)
46  s[i++] = '\\';
47  if (i < max - 1)
48  s[i++] = ch; //
49  }
50  }
51  else
52  {
53  if (i < max - 1)
54  s[i++] = ch;
55  }
56  }
57  if (max > 0)
58  s[i] = '\0'; // add terminating NULL
59  if (!(ch == '\n' || ch == ';'))
60  return nullptr; // return NULL for end of file
61  return s;
62 }

◆ readXmol()

void readXmol ( std::istream &  ,
double *  ,
int   
)

Definition at line 153 of file SimpleParser.cpp.

References getwords().

154 {
155  std::vector<std::string> slist;
156  getwords(slist, fxmol);
157  unsigned natom = atoi(slist.front().c_str());
158  getwords(slist, fxmol);
159  int ii = 0;
160  for (int i = 0; i < natom; i++)
161  {
162  getwords(slist, fxmol);
163  for (int ivar = 1; ivar <= numvar; ivar++)
164  {
165  data[ii++] = atof(slist[ivar].c_str());
166  }
167  }
168 }
int getwords(std::vector< std::string > &slist, std::istream &fp, std::string &aline)