PhoenixGenerator  2.0.0
Set of tools to generate code
header_generator.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include "header_generator.h"
9 
11 
14  PString body("");
15  body += "/***************************************\n";
16  body += "\tAuteur : Pierre Aubert\n";
17  body += "\tMail : pierre.aubert@lapp.in2p3.fr\n";
18  body += "\tLicence : CeCILL-C\n";
19  body += "****************************************/\n";
20  return body;
21 }
22 
24 
26 void licenceSave(std::ofstream & fs){
27  fs << licenceSaveStr() << std::endl;
28 }
29 
31 
35  return "__" + fileName.replace(".", "_").toUpper() + "__";
36 }
37 
39 
41 void saveHeaderFile(const PPath & fileName){
42  std::ofstream fs;
43  fs.open(fileName.c_str());
44  if(!fs.is_open()){
45  std::cerr << "saveHeaderFile : can't open file '" << fileName << "'" << std::endl;
46  return;
47  }
48  PString defineStr(makeMultiIncludeDefineMacro(fileName));
49  licenceSave(fs);
50  fs << "#ifndef " << defineStr << std::endl;
51  fs << "#define " << defineStr << std::endl;
52  fs << std::endl << std::endl << std::endl << std::endl << std::endl << std::endl;
53  fs << "#endif" << std::endl;
54  fs.close();
55 }
56 
58 
61 void saveSourceFile(const PPath & fileName, const PString & headerName){
62  std::ofstream fs;
63  fs.open(fileName.c_str());
64  if(!fs.is_open()){
65  std::cerr << "saveSourceFile : can't open file '" << fileName << "'" << std::endl;
66  return;
67  }
68  licenceSave(fs);
69  fs << std::endl << "#include \"" << headerName << "\"" << std::endl << std::endl << std::endl << std::endl << std::endl << std::endl;
70  fs.close();
71 }
72 
74 
77 void saveHeaderSourceFile(const PPath & headerName, const PPath & sourceName){
78  saveHeaderFile(headerName);
79  saveSourceFile(sourceName, headerName);
80 }
81 
82 
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204
PString toUpper() const
Convert std::string in upper case.
Definition: PString.cpp:639
void saveSourceFile(const PPath &fileName, const PString &headerName)
Fonction qui sauve le fichier source.
PString licenceSaveStr()
Get the licence in string.
PString makeMultiIncludeDefineMacro(const PString &fileName)
Create the macro of multi inclusion file name.
void saveHeaderFile(const PPath &fileName)
Fonction qui sauve le fichier header.
void licenceSave(std::ofstream &fs)
Saves the policy.
void saveHeaderSourceFile(const PPath &headerName, const PPath &sourceName)
Fonction qui sauve le fichier header.