PhoenixGenerator  2.0.0
Set of tools to generate code
parserClassConfig.h File Reference
#include "PFileParser.h"
#include "PClassConfig.h"
+ Include dependency graph for parserClassConfig.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool parserClassConfig (std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
 Parser list class config. More...
 
bool saveParserClassConfig (const PPath &baseFileNameOutput, const PPath &fileName, bool enableDataStream, bool enableTypeStream, bool enableUnitTest, const PPath &testParentDir=PPath("./"), const PString &libName=PString(""))
 Parser list class config. More...
 

Function Documentation

◆ parserClassConfig()

bool parserClassConfig ( std::vector< PClassConfig > &  listClassConfig,
PVecPath listInclude,
const PPath fileName 
)

Parser list class config.

Parameters
[out]listClassConfig: list of class config
listInclude: list of include
fileName: file name of the config
Returns
true on success, false otherwise

Definition at line 215 of file parserClassConfig.cpp.

215  {
216  if(fileName == "") return false;
217  PFileParser parser;
218  parser.setWhiteSpace(" \t\n");
219  parser.setSeparator("{};/*");
220  if(!parser.open(fileName)) return false;
221  PString currentComment("");
222  PVecString listTemplate;
223  while(!parser.isEndOfFile()){
224  if(parser.isMatch("#")){
225  if(parser.isMatch("include")){
226  listInclude.push_back(parser.getUntilKeyWithoutPatern("\n").eraseChar(" \t\n"));
227  }
228  }else if(updateCurrentComment(parser, currentComment)){}
229  else if(updateCurrentTemplate(parser, listTemplate)){}
230  else if(parseEnumConfig(listClassConfig, parser, currentComment)){}
231  else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PClassConfig
232  if(!parsePClassConfig(listClassConfig, parser, currentComment, listTemplate)){
233  errorUnexpectedToken(parser, parser.getNextToken());
234  return false;
235  }
236  }
237  parser.skipWhiteSpace();
238  }
239  return true;
240 }
std::vector< PString > PVecString
Definition: PString.h:96
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition: PFileParser.h:20
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
Definition: PFileParser.cpp:43
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
Definition: PFileParser.cpp:24
PString getNextToken()
Get the next token.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
Definition: PFileParser.cpp:35
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
void skipWhiteSpace()
Skip the white space if there is at the current caracter position.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Definition: PFileParser.cpp:88
Extends the std::string.
Definition: PString.h:16
PString eraseChar(char ch) const
Erase char ch of current string.
Definition: PString.cpp:478
bool updateCurrentComment(PFileParser &parser, PString &currentComment)
Fonction qui met à jour un commentaire.
bool parseEnumConfig(std::vector< PClassConfig > &listClassConfig, PFileParser &parser, PString &currentComment)
Parse an enum definition.
bool parsePClassConfig(std::vector< PClassConfig > &listClassConfig, PFileParser &parser, PString &currentComment, PVecString &listTemplate)
Parse a PClassConfig.
bool updateCurrentTemplate(PFileParser &parser, PVecString &currentTemplate)
Update a template definition.
void errorUnexpectedToken(const PFileParser &parser, const PString &token)
Affiche une erreur de token non attendu.

References PString::eraseChar(), errorUnexpectedToken(), PFileParser::getNextToken(), PFileParser::getUntilKeyWithoutPatern(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::open(), parseEnumConfig(), parsePClassConfig(), PFileParser::setSeparator(), PFileParser::setWhiteSpace(), PFileParser::skipWhiteSpace(), updateCurrentComment(), and updateCurrentTemplate().

Referenced by project_wrapper_generator(), and saveParserClassConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveParserClassConfig()

bool saveParserClassConfig ( const PPath baseFileNameOutput,
const PPath fileName,
bool  enableDataStream,
bool  enableTypeStream,
bool  enableUnitTest,
const PPath testParentDir,
const PString libName 
)

Parser list class config.

Parameters
baseFileNameOutput: base of the output files
fileName: file name of the config
enableDataStream: true to enable the serialization/deserialization with data
enableTypeStream: true to test phoenix_getTypeName function
enableUnitTest: true to enable unit tests
testParentDir: parent directory of tests
libName: name of the generated library to link with
Returns
true on success, false otherwise

Definition at line 253 of file parserClassConfig.cpp.

253  {
254  PVecPath listInclude;
255  std::vector<PClassConfig> listClassConfig;
256  if(!parserClassConfig(listClassConfig, listInclude, fileName)){
257  std::cerr << "saveParserClassConfig : can't load file '" << fileName << "'" << std::endl;
258  return false;
259  }
260  if(!saveClassImplDecl( listClassConfig, baseFileNameOutput, listInclude, enableDataStream, enableTypeStream)){
261  std::cerr << "saveParserClassConfig : can't save files '" << baseFileNameOutput << "'[.h or .cpp]" << std::endl;
262  return false;
263  }
264  if(enableUnitTest){
265  PPath unitTestDir(testParentDir / PPath("TESTS"));
266  if(!saveClassTest(unitTestDir, libName, listClassConfig, baseFileNameOutput.getFileName(), enableDataStream, enableTypeStream)){
267  std::cerr << "saveParserClassConfig : can't save unit tests in directory'" << unitTestDir << "'" << std::endl;
268  return false;
269  }
270  }
271 
272  return true;
273 }
std::vector< PPath > PVecPath
Definition: PPath.h:75
Path of a directory or a file.
Definition: PPath.h:17
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
bool parserClassConfig(std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
Parser list class config.
bool saveClassTest(const PPath &outputTestDir, const PString &libName, const PClassConfig &classConfig, const PPath &baseFileName, bool enableDataStream, bool enableTypeStream)
Save the unit test of the generated PClassConfig.
bool saveClassImplDecl(const std::vector< PClassConfig > &classConfig, const PPath &baseFileName, const PVecPath &listInclude, bool enableDataStream, bool enableTypeStream)
Creates header file.

References PPath::getFileName(), parserClassConfig(), saveClassImplDecl(), and saveClassTest().

Referenced by project_generator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: