OpenCAEPoro  v0.5.0
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 OCP_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  if (pos != string::npos) {
66  USI len = str.size();
67  OCP_USI num = stoi(str.substr(0, pos));
68  USI val = stoi(str.substr(pos + 1, len - (pos + 1)));
69  obj.push_back(num);
70  region.push_back(val);
71  }
72  }
73 }
74 
75 #endif /* end if __UTILINPUT_HEADER__ */
76 
77 /*----------------------------------------------------------------------------*/
78 /* Brief Change History of This File */
79 /*----------------------------------------------------------------------------*/
80 /* Author Date Actions */
81 /*----------------------------------------------------------------------------*/
82 /* Shizhe Li Oct/01/2021 Create file */
83 /* Chensong Zhang Oct/15/2021 Format file */
84 /*----------------------------------------------------------------------------*/
Definition of build-in datatypes and consts.
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
unsigned int OCP_USI
Long unsigned integer.
Definition: OCPConst.hpp:25
unsigned int OCP_BOOL
OCP_BOOL in OCP.
Definition: OCPConst.hpp:29
void DealDefault(vector< string > &result)
Definition: UtilInput.cpp:50
OCP_BOOL ReadLine(ifstream &ifs, vector< string > &result)
Definition: UtilInput.cpp:14
constexpr long long Map_Str2Int(const char *mystr, const USI &len)
Definition: UtilInput.hpp:34
void DealData(const vector< string > &vbuf, vector< OCP_USI > &obj, vector< T > &region)
Definition: UtilInput.hpp:59