Directory: | ./ |
---|---|
File: | src/header_generator.cpp |
Date: | 2025-04-25 19:10:50 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 41 | 41 | 100.0% |
Branches: | 64 | 64 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
10 | ///Get the licence in string | ||
11 | /** @return licence in string | ||
12 | */ | ||
13 | 73 | PString licenceSaveStr(){ | |
14 | 73 | PString body(""); | |
15 |
1/1✓ Branch 1 taken 73 times.
|
73 | body += "/***************************************\n"; |
16 |
1/1✓ Branch 1 taken 73 times.
|
73 | body += "\tAuteur : Pierre Aubert\n"; |
17 |
1/1✓ Branch 1 taken 73 times.
|
73 | body += "\tMail : pierre.aubert@lapp.in2p3.fr\n"; |
18 |
1/1✓ Branch 1 taken 73 times.
|
73 | body += "\tLicence : CeCILL-C\n"; |
19 |
1/1✓ Branch 1 taken 73 times.
|
73 | body += "****************************************/\n"; |
20 | 73 | return body; | |
21 | } | ||
22 | |||
23 | ///Saves the policy | ||
24 | /** @param fs : file in witch to write | ||
25 | */ | ||
26 | 40 | void licenceSave(std::ofstream & fs){ | |
27 |
2/2✓ Branch 2 taken 40 times.
✓ Branch 5 taken 40 times.
|
40 | fs << licenceSaveStr() << std::endl; |
28 | 40 | } | |
29 | |||
30 | ///Create the macro of multi inclusion file name | ||
31 | /** @param fileName : header file name | ||
32 | * @return macro of multi inclusion file name | ||
33 | */ | ||
34 | 24 | PString makeMultiIncludeDefineMacro(const PString & fileName){ | |
35 |
6/6✓ Branch 2 taken 24 times.
✓ Branch 5 taken 24 times.
✓ Branch 8 taken 24 times.
✓ Branch 11 taken 24 times.
✓ Branch 14 taken 24 times.
✓ Branch 17 taken 24 times.
|
48 | return "__" + fileName.replace(".", "_").toUpper() + "__"; |
36 | } | ||
37 | |||
38 | ///Fonction qui sauve le fichier header | ||
39 | /** @param fileName : header file name | ||
40 | */ | ||
41 | 2 | void saveHeaderFile(const PPath & fileName){ | |
42 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::ofstream fs; |
43 |
1/1✓ Branch 2 taken 2 times.
|
2 | fs.open(fileName.c_str()); |
44 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | if(!fs.is_open()){ |
45 |
4/4✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
|
1 | std::cerr << "saveHeaderFile : can't open file '" << fileName << "'" << std::endl; |
46 | 1 | return; | |
47 | } | ||
48 |
1/1✓ Branch 1 taken 1 times.
|
1 | PString defineStr(makeMultiIncludeDefineMacro(fileName)); |
49 |
1/1✓ Branch 1 taken 1 times.
|
1 | licenceSave(fs); |
50 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | fs << "#ifndef " << defineStr << std::endl; |
51 |
3/3✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
|
1 | fs << "#define " << defineStr << std::endl; |
52 |
6/6✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
1 | fs << std::endl << std::endl << std::endl << std::endl << std::endl << std::endl; |
53 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | fs << "#endif" << std::endl; |
54 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.close(); |
55 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | } |
56 | |||
57 | ///Fonction qui sauve le fichier source | ||
58 | /** @param fileName : source file name | ||
59 | * @param headerName : header file name | ||
60 | */ | ||
61 | 2 | void saveSourceFile(const PPath & fileName, const PString & headerName){ | |
62 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::ofstream fs; |
63 |
1/1✓ Branch 2 taken 2 times.
|
2 | fs.open(fileName.c_str()); |
64 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | if(!fs.is_open()){ |
65 |
4/4✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
|
1 | std::cerr << "saveSourceFile : can't open file '" << fileName << "'" << std::endl; |
66 | 1 | return; | |
67 | } | ||
68 |
1/1✓ Branch 1 taken 1 times.
|
1 | licenceSave(fs); |
69 |
10/10✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 28 taken 1 times.
|
1 | fs << std::endl << "#include \"" << headerName << "\"" << std::endl << std::endl << std::endl << std::endl << std::endl << std::endl; |
70 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.close(); |
71 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | } |
72 | |||
73 | ///Fonction qui sauve le fichier header | ||
74 | /** @param headerName : header file name | ||
75 | * @param sourceName : source file name | ||
76 | */ | ||
77 | 2 | void saveHeaderSourceFile(const PPath & headerName, const PPath & sourceName){ | |
78 | 2 | saveHeaderFile(headerName); | |
79 | 2 | saveSourceFile(sourceName, headerName); | |
80 | 2 | } | |
81 | |||
82 | |||
83 |