OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
UtilInput.cpp
Go to the documentation of this file.
1 
12 #include "UtilInput.hpp"
13 
14 bool ReadLine(ifstream& ifs, vector<string>& result)
15 {
16  result.resize(0);
17  string buf;
18 
19  while (!ifs.eof()) {
20  getline(ifs, buf);
21  if (buf.empty()) continue;
22  while (buf[0] == ' ' || buf[0] == '\t' || buf[0] == '\r') buf.erase(0, 1);
23  if (buf.empty() || buf[0] == '#') continue;
24  if (buf.size() > 1 && (buf[0] == '-' && buf[1] == '-')) continue;
25 
26  break;
27  }
28 
29  // file ends
30  if (buf.empty()) return false;
31 
32  // remove the string behind the '/'
33  auto pos = buf.find_first_of('/');
34  if (pos != string::npos) {
35  buf.erase(pos);
36  buf.push_back('/');
37  }
38 
39  // get rid of ' and ,
40  for (auto& s : buf) {
41  if (s == '\'' || s == ',') s = ' ';
42  }
43 
44  istringstream tmp(buf);
45  while (tmp >> buf) result.push_back(buf);
46 
47  return true;
48 }
49 
50 void DealDefault(vector<string>& result)
51 {
52  vector<string> tmp;
53  for (auto& str : result) {
54  auto pos = str.find('*');
55  if (pos == string::npos) {
56  tmp.push_back(str);
57  } else {
58  USI num = atoi(str.substr(0, pos).c_str()); // non number -> 0
59  USI len = str.size();
60  string val = "DEFAULT";
61  if (num == 0) {
62  tmp.push_back(str);
63  } else {
64  if (pos != len - 1) {
65  val = str.substr(pos + 1, len - (pos + 1));
66  }
67  for (USI i = 0; i < num; i++) tmp.push_back(val);
68  }
69  }
70  }
71  swap(result, tmp);
72 }
73 
74 /*----------------------------------------------------------------------------*/
75 /* Brief Change History of This File */
76 /*----------------------------------------------------------------------------*/
77 /* Author Date Actions */
78 /*----------------------------------------------------------------------------*/
79 /* Shizhe Li Oct/01/2021 Create file */
80 /* Chensong Zhang Oct/15/2021 Format file */
81 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
bool ReadLine(ifstream &ifs, vector< string > &result)
Definition: UtilInput.cpp:14
Supply basic tools used to input files.