Microflow 3D  v1.0
TextParser.cpp
Go to the documentation of this file.
1 // ==============================================================================================
2 // Microflow 3D, http://www.microflow.pwr.edu.pl/
3 // Created by Roman Szafran on 02.03.19.
4 // Copyright (c) 2019 Wroclaw University of Science and Technology.
5 // Distributed under the Apache License, Version 2.0. You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0 or see accompanying file license.txt.
7 // Redistributions of source code must retain the above copyright and license notice.
8 // ==============================================================================================
9 
10 #include "TextParser.h"
11 
12 config4cpp::Configuration* MF::Parser::TextParser::CaseConfigFileParse(const char* pPathToCaseFile, const char* pScope, bool verbose)
13 {
14  config4cpp::StringVector namesVec;
15  config4cpp::StringVector namesList;
16  pCaseParams = config4cpp::Configuration::create();
17 
18  try {
19  setlocale(LC_ALL, "en_US.UTF-8");
20  pCaseParams->parse(pPathToCaseFile);
21  std::cout << "Parsed file: -----> " << pPathToCaseFile << std::endl;
22 
23  // If verbose mode activated, displays on console the case config file content
24  if (verbose == 1)
25  {
26  pCaseParams->listLocallyScopedNames(pScope,"",config4cpp::Configuration::CFG_SCOPE_AND_VARS, true, namesVec);
27  for (int i = 0; i < namesVec.length(); i++)
28  if (pCaseParams->type(pScope,namesVec[i]) == pCaseParams->CFG_STRING)
29  std::cout <<"\t"<< namesVec[i] <<" = "<<pCaseParams->lookupString(pScope, namesVec[i])<< std::endl;
30  else if (pCaseParams->type(pScope,namesVec[i]) == pCaseParams->CFG_SCOPE)
31  std::cout << std::endl << namesVec[i] << ":" << std::endl << std::endl;
32  else if (pCaseParams->type(pScope,namesVec[i]) == pCaseParams->CFG_LIST)
33  {
34  pCaseParams->lookupList(pScope, namesVec[i], namesList);
35  std::cout <<"\t"<< namesVec[i] <<" = [";
36  for (int j = 0; j < namesList.length()-1; j++)
37  std::cout << namesList[j] << ",";
38  std::cout << namesList[namesList.length()-1];
39  std::cout << "]"<< std::endl;
40  }
41  else
42  std::cout << namesVec[i] << " = " << "Unhandled format of data" << std::endl;
43  std::cout << std::endl;
44  }
45  } catch(const config4cpp::ConfigurationException &exception){std::cout <<"File processing error "; std::cout << exception.c_str() << std::endl; exit(EXIT_FAILURE);}
46  return (pCaseParams);
47 }
48 
49 config4cpp::Configuration* MF::Parser::TextParser::ProgramConfigFileParse(const char* pPathToConfigFile, const char* pScope, bool verbose)
50 {
51  config4cpp::StringVector namesVec;
52  config4cpp::StringVector namesList;
53  pProgramParams = config4cpp::Configuration::create();
54 
55  try {
56  setlocale(LC_ALL, "en_US.UTF-8");
57  pProgramParams->parse(pPathToConfigFile);
58  std::cout << "Parsed file: -----> " << pPathToConfigFile << std::endl;
59 
60  // If verbose mode activated, displays on console the program config file content
61  if (verbose == 1)
62  {
63  pProgramParams->listLocallyScopedNames(pScope,"",config4cpp::Configuration::CFG_SCOPE_AND_VARS, true, namesVec);
64  for (int i = 0; i < namesVec.length(); i++)
65  if (pProgramParams->type(pScope,namesVec[i]) == pProgramParams->CFG_STRING)
66  std::cout <<"\t"<< namesVec[i] <<" = "<<pProgramParams->lookupString(pScope, namesVec[i])<< std::endl;
67  else if (pProgramParams->type(pScope,namesVec[i]) == pProgramParams->CFG_SCOPE)
68  std::cout << std::endl << namesVec[i] << ":" << std::endl << std::endl;
69  else if (pProgramParams->type(pScope,namesVec[i]) == pProgramParams->CFG_LIST)
70  {
71  pProgramParams->lookupList(pScope, namesVec[i], namesList);
72  std::cout <<"\t"<< namesVec[i] <<" = [";
73  for (int j = 0; j < namesList.length()-1; j++)
74  std::cout << namesList[j] << ",";
75  std::cout << namesList[namesList.length()-1];
76  std::cout << "]"<< std::endl;
77  }
78  else
79  std::cout << namesVec[i] << " = " << "Unhandled format of data" << std::endl;
80  std::cout << std::endl;
81  }
82  } catch(const config4cpp::ConfigurationException &exception){std::cout <<"File processing error "; std::cout << exception.c_str() << std::endl; exit(EXIT_FAILURE);}
83  return (pProgramParams);
84 }
85 
86 config4cpp::Configuration* MF::Parser::TextParser::ThreadConfigFileParse(const char* pPathToThreadFile, const char* pScope, bool verbose)
87 {
88  config4cpp::StringVector namesVec;
89  config4cpp::StringVector namesList;
90  pThreadParams = config4cpp::Configuration::create();
91 
92  try {
93  setlocale(LC_ALL, "en_US.UTF-8");
94  pThreadParams->parse(pPathToThreadFile);
95  std::cout << "Parsed file: -----> " << pPathToThreadFile << std::endl;
96 
97  // If verbose mode activated, displays on console the thread config file content
98  if (verbose == 1)
99  {
100  pThreadParams->listLocallyScopedNames(pScope,"",config4cpp::Configuration::CFG_SCOPE_AND_VARS, true, namesVec);
101  for (int i = 0; i < namesVec.length(); i++)
102  if (pThreadParams->type(pScope,namesVec[i]) == pThreadParams->CFG_STRING)
103  std::cout <<"\t"<< namesVec[i] <<" = "<<pThreadParams->lookupString(pScope, namesVec[i])<< std::endl;
104  else if (pThreadParams->type(pScope,namesVec[i]) == pThreadParams->CFG_SCOPE)
105  std::cout << std::endl << namesVec[i] << ":" << std::endl << std::endl;
106  else if (pThreadParams->type(pScope,namesVec[i]) == pThreadParams->CFG_LIST)
107  {
108  pThreadParams->lookupList(pScope, namesVec[i], namesList);
109  std::cout <<"\t"<< namesVec[i] <<" = [";
110  for (int j = 0; j < namesList.length()-1; j++)
111  std::cout << namesList[j] << ",";
112  std::cout << namesList[namesList.length()-1];
113  std::cout << "]"<< std::endl;
114  }
115  else
116  std::cout << namesVec[i] << " = " << "Unhandled format of data" << std::endl;
117  std::cout << std::endl;
118  }
119  } catch(const config4cpp::ConfigurationException &exception){std::cout <<"File processing error "; std::cout << exception.c_str() << std::endl; exit(EXIT_FAILURE);}
120  return (pThreadParams);
121 }
122 
config4cpp::Configuration * CaseConfigFileParse(const char *pPathToCaseFile, const char *pScope, bool verbose)
Definition: TextParser.cpp:12
config4cpp::Configuration * ProgramConfigFileParse(const char *pPathToConfigFile, const char *pScope, bool verbose)
Definition: TextParser.cpp:49
config4cpp::Configuration * ThreadConfigFileParse(const char *pPathToThreadFile, const char *pScope, bool verbose)
Definition: TextParser.cpp:86