OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
UtilInput.hpp
Go to the documentation of this file.
1 
12 #ifndef __UTILINPUT_HEADER__
13 #define __UTILINPUT_HEADER__
14 
15 // Standard header files
16 #include <fstream>
17 #include <iostream>
18 #include <sstream>
19 #include <string>
20 #include <vector>
21 
22 // OpenCAEPoro header files
23 #include "OCPConst.hpp"
24 
25 using namespace std;
26 
28 #define ParamCheck1(exp) \
29  std::cout << exp << " in " << __func__ << "() in " << __LINE__ << " in " \
30  << __FILE__;
31 
34 constexpr inline long long Map_Str2Int(const char* mystr, const USI& len)
35 {
36  long long res = 0;
37  long long t = 100;
38  for (USI i = 0; i < len; i++) {
39  res += (int)mystr[len - 1 - i] * t;
40  t *= 100;
41  }
42  return res;
43 }
44 
50 bool ReadLine(ifstream& ifs, vector<string>& result);
51 
54 void DealDefault(vector<string>& result);
55 
58 template <typename T>
59 void DealData(const vector<string>& vbuf, vector<OCP_USI>& obj, vector<T>& region)
60 {
61  obj.resize(0);
62  region.resize(0);
63  for (auto& str : vbuf) {
64  auto pos = str.find('*');
65 
66  if (pos != string::npos) {
67  USI len = str.size();
68  OCP_USI num = stoi(str.substr(0, pos));
69  USI val = stoi(str.substr(pos + 1, len - (pos + 1)));
70  obj.push_back(num);
71  region.push_back(val);
72  }
73  }
74 }
75 
76 #endif /* end if __UTILINPUT_HEADER__ */
77 
78 /*----------------------------------------------------------------------------*/
79 /* Brief Change History of This File */
80 /*----------------------------------------------------------------------------*/
81 /* Author Date Actions */
82 /*----------------------------------------------------------------------------*/
83 /* Shizhe Li Oct/01/2021 Create file */
84 /* Chensong Zhang Oct/15/2021 Format file */
85 /*----------------------------------------------------------------------------*/
Definition of build-in datatypes and consts.
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
unsigned int OCP_USI
Long unsigned integer.
Definition: OCPConst.hpp:24
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
constexpr long long Map_Str2Int(const char *mystr, const USI &len)
Definition: UtilInput.hpp:34
bool ReadLine(ifstream &ifs, vector< string > &result)
Definition: UtilInput.cpp:14
void DealData(const vector< string > &vbuf, vector< OCP_USI > &obj, vector< T > &region)
Definition: UtilInput.hpp:59