Microflow 3D  v1.0
MF::Parser::TextParser Class Reference

The object of TextParser class parses case, program and thread config files. More...

#include <TextParser.h>

Public Member Functions

 TextParser ()=default
 
 ~TextParser ()=default
 
config4cpp::Configuration * CaseConfigFileParse (const char *pPathToCaseFile, const char *pScope, bool verbose)
 
config4cpp::Configuration * ProgramConfigFileParse (const char *pPathToConfigFile, const char *pScope, bool verbose)
 
config4cpp::Configuration * ThreadConfigFileParse (const char *pPathToThreadFile, const char *pScope, bool verbose)
 

Detailed Description

The object of TextParser class parses case, program and thread config files.

If verbose mode is true, the content of parsed files is printed on the console.

Definition at line 23 of file TextParser.h.

Constructor & Destructor Documentation

◆ TextParser()

MF::Parser::TextParser::TextParser ( )
default

◆ ~TextParser()

MF::Parser::TextParser::~TextParser ( )
default

Member Function Documentation

◆ CaseConfigFileParse()

config4cpp::Configuration * MF::Parser::TextParser::CaseConfigFileParse ( const char *  pPathToCaseFile,
const char *  pScope,
bool  verbose 
)

Definition at line 12 of file TextParser.cpp.

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 }

◆ ProgramConfigFileParse()

config4cpp::Configuration * MF::Parser::TextParser::ProgramConfigFileParse ( const char *  pPathToConfigFile,
const char *  pScope,
bool  verbose 
)

Definition at line 49 of file TextParser.cpp.

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 }

◆ ThreadConfigFileParse()

config4cpp::Configuration * MF::Parser::TextParser::ThreadConfigFileParse ( const char *  pPathToThreadFile,
const char *  pScope,
bool  verbose 
)

Definition at line 86 of file TextParser.cpp.

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 }

The documentation for this class was generated from the following files: