GCC Code Coverage Report


Directory: ./
File: src/BackEnd/generator_class_cpp.cpp
Date: 2026-06-23 11:27:41
Exec Total Coverage
Lines: 253 306 82.7%
Functions: 18 18 100.0%
Branches: 436 652 66.9%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "phoenix_color.h"
8 #include "openFileStream.h"
9 #include "header_generator.h"
10 #include "cmakelist_generator.h"
11 #include "generator_class_cpp.h"
12
13 ///Check if the given type is a pointer or not
14 /** @param varType : type to be checked
15 * @return true if the given type is a pointer, false otherwise
16 */
17 16 bool class_getIsPointer(const PString & varType){
18
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 16 times.
16 if(varType.size() == 0lu){return false;}
19
1/4
✗ Branch 0 (6→7) not taken.
✓ Branch 1 (6→10) taken 16 times.
✗ Branch 2 (8→9) not taken.
✗ Branch 3 (8→10) not taken.
16 return varType.find('*') && varType.back() == '*';
20 }
21
22 ///Get the template call in the class declaration
23 /** @param listTemplate : list of template def
24 * @return template definition in the class declaration (< T, U, .... >)
25 */
26 17 PString class_getClassDefTemplate(const PVecString & listTemplate){
27
3/3
✓ Branch 0 (3→4) taken 15 times.
✓ Branch 1 (3→6) taken 2 times.
✓ Branch 2 (4→5) taken 15 times.
17 if(listTemplate.size() == 0lu){return "";}
28
2/2
✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
2 PString defTemplate("<"), comma("");
29
2/2
✓ Branch 0 (30→9) taken 3 times.
✓ Branch 1 (30→31) taken 2 times.
10 for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
30
1/1
✓ Branch 0 (11→12) taken 3 times.
3 PVecString vecPart = it->split(' ');
31
1/2
✓ Branch 0 (13→14) taken 3 times.
✗ Branch 1 (13→19) not taken.
3 if(vecPart.size() != 0lu){
32
2/2
✓ Branch 0 (15→16) taken 3 times.
✓ Branch 2 (16→17) taken 3 times.
3 defTemplate += comma + vecPart.back();
33
1/1
✓ Branch 0 (18→19) taken 3 times.
3 comma = ", ";
34 }
35 3 }
36
1/1
✓ Branch 0 (31→32) taken 2 times.
2 defTemplate += ">";
37
1/1
✓ Branch 0 (32→33) taken 2 times.
2 return defTemplate;
38 2 }
39
40 ///Get the template definition in the class declaration
41 /** @param listTemplate : list of template def
42 * @return template definition in the class declaration (template< .... >)
43 */
44 15 PString class_getClassDeclTempalteDef(const PVecString & listTemplate){
45
2/3
✓ Branch 0 (3→4) taken 15 times.
✗ Branch 1 (3→6) not taken.
✓ Branch 2 (4→5) taken 15 times.
15 if(listTemplate.size() == 0lu){return "";}
46 PString templateDef("template<");
47 PString comma("");
48 for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
49 templateDef += comma;
50 templateDef += *it;
51 comma = ", ";
52 }
53 templateDef += ">\n";
54 return templateDef;
55 }
56
57 ///Saves constructor of the class
58 /** @param[out] fs : header file name
59 * @param classConfig : PClassConfig we vant to save
60 * @param defTemplate : extra template definition for the class name space
61 * @param templateDeclaration : basic template declaration before each method (template< ... >)
62 */
63 7 void class_saveClassConstructorImpl(std::ofstream & fs, const PClassConfig & classConfig, const PString & defTemplate, const PString & templateDeclaration){
64
2/2
✓ Branch 0 (2→3) taken 7 times.
✓ Branch 2 (3→4) taken 7 times.
7 PString name(classConfig.getName());
65
3/3
✓ Branch 0 (4→5) taken 7 times.
✓ Branch 2 (5→6) taken 7 times.
✓ Branch 4 (6→7) taken 7 times.
7 fs << "///Constructor of class " << name << std::endl;
66
1/1
✓ Branch 0 (7→8) taken 7 times.
7 fs << templateDeclaration;
67
5/5
✓ Branch 0 (8→9) taken 7 times.
✓ Branch 2 (9→10) taken 7 times.
✓ Branch 4 (10→11) taken 7 times.
✓ Branch 6 (11→12) taken 7 times.
✓ Branch 8 (12→13) taken 7 times.
7 fs << name << defTemplate << "::" << name << "()";
68
2/3
✓ Branch 0 (13→14) taken 7 times.
✗ Branch 2 (15→16) not taken.
✓ Branch 3 (15→47) taken 7 times.
7 if(classConfig.getListParentClass().size() != 0lu){
69 PVecString::const_iterator it(classConfig.getListParentClass().begin());
70 fs << std::endl << "\t: " << *it << "()";
71 if(classConfig.getListParentClass().size() > 1lu){
72 while(it != classConfig.getListParentClass().end()){
73 fs << ", " << *it << "()";
74 ++it;
75 }
76 }
77 fs << std::endl;
78 }
79
2/2
✓ Branch 0 (47→48) taken 7 times.
✓ Branch 2 (48→49) taken 7 times.
7 fs << "{" << std::endl;
80
4/4
✓ Branch 0 (49→50) taken 7 times.
✓ Branch 2 (50→51) taken 7 times.
✓ Branch 4 (51→52) taken 7 times.
✓ Branch 6 (52→53) taken 7 times.
7 fs << "\tinitialisation" << name << "();" << std::endl;
81
3/3
✓ Branch 0 (53→54) taken 7 times.
✓ Branch 2 (54→55) taken 7 times.
✓ Branch 4 (55→56) taken 7 times.
7 fs << "}" << std::endl << std::endl;
82 7 }
83
84 ///Saves the copy function of a class
85 /** @param[out] fs : header file name
86 * @param classConfig : PClassConfig we vant to save
87 * @param defTemplate : extra template definition for the class name space
88 * @param templateDeclaration : basic template declaration before each method (template< ... >)
89 */
90 7 void class_saveClassInitialisationFunctionImpl(std::ofstream & fs, const PClassConfig & classConfig, const PString & defTemplate, const PString & templateDeclaration){
91
2/2
✓ Branch 0 (2→3) taken 7 times.
✓ Branch 2 (3→4) taken 7 times.
7 PString name(classConfig.getName());
92
3/3
✓ Branch 0 (4→5) taken 7 times.
✓ Branch 2 (5→6) taken 7 times.
✓ Branch 4 (6→7) taken 7 times.
7 fs << "///Initialisation Function of class " << name << std::endl;
93
1/1
✓ Branch 0 (7→8) taken 7 times.
7 fs << templateDeclaration;
94
7/7
✓ Branch 0 (8→9) taken 7 times.
✓ Branch 2 (9→10) taken 7 times.
✓ Branch 4 (10→11) taken 7 times.
✓ Branch 6 (11→12) taken 7 times.
✓ Branch 8 (12→13) taken 7 times.
✓ Branch 10 (13→14) taken 7 times.
✓ Branch 12 (14→15) taken 7 times.
7 fs << "void " << name << defTemplate << "::initialisation" << name << "(){" << std::endl;
95
2/2
✓ Branch 0 (15→16) taken 7 times.
✓ Branch 2 (16→17) taken 7 times.
7 fs << "\t//Initialisation of the attributes of the class" << std::endl;
96
1/1
✓ Branch 0 (17→18) taken 7 times.
7 const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
97
2/2
✓ Branch 0 (86→19) taken 16 times.
✓ Branch 1 (86→87) taken 7 times.
46 for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
98
3/4
✓ Branch 0 (21→22) taken 16 times.
✓ Branch 2 (22→23) taken 16 times.
✗ Branch 4 (23→24) not taken.
✓ Branch 5 (23→36) taken 16 times.
16 if(it->getDefaultValue() != ""){
99 fs << "\tp_" << it->getName() << " = "<<it->getDefaultValue()<<";" << std::endl;
100 }else{
101
2/2
✓ Branch 0 (38→39) taken 16 times.
✓ Branch 2 (39→40) taken 16 times.
16 PString varType(it->getType());
102
1/1
✓ Branch 0 (40→41) taken 16 times.
16 bool isSimpleType = getIsSimpleType(varType);
103
1/1
✓ Branch 0 (41→42) taken 16 times.
16 bool isPtr(class_getIsPointer(varType));
104
1/2
✗ Branch 0 (42→43) not taken.
✓ Branch 1 (42→50) taken 16 times.
16 if(isPtr){
105 fs << "\tp_" << it->getName() << " = NULL;" << std::endl;
106
2/2
✓ Branch 0 (50→51) taken 8 times.
✓ Branch 1 (50→65) taken 8 times.
16 }else if(isSimpleType){
107
1/1
✓ Branch 0 (51→52) taken 8 times.
8 PString defaultValue(getDefaultValueTypeInCpp(varType));
108
2/3
✓ Branch 0 (52→53) taken 8 times.
✓ Branch 2 (53→54) taken 8 times.
✗ Branch 3 (53→63) not taken.
8 if(defaultValue != ""){
109
7/7
✓ Branch 0 (54→55) taken 8 times.
✓ Branch 2 (57→58) taken 8 times.
✓ Branch 4 (58→59) taken 8 times.
✓ Branch 6 (59→60) taken 8 times.
✓ Branch 8 (60→61) taken 8 times.
✓ Branch 10 (61→62) taken 8 times.
✓ Branch 12 (62→63) taken 8 times.
16 fs << "\tp_" << it->getName() << " = "<<defaultValue<<";" << std::endl;
110 }
111
2/3
✓ Branch 0 (65→66) taken 8 times.
✗ Branch 2 (66→67) not taken.
✓ Branch 3 (66→74) taken 8 times.
16 }else if(varType == "PString"){
112 fs << "\tp_" << it->getName() << " = \"\";" << std::endl;
113 }
114 16 }
115 }
116
3/3
✓ Branch 0 (87→88) taken 7 times.
✓ Branch 2 (88→89) taken 7 times.
✓ Branch 4 (89→90) taken 7 times.
7 fs << "}" << std::endl << std::endl;
117 7 }
118
119 ///Check if the vector of PClassAttribute has default value
120 /** @param vecAttr : vector of attribute to be checked
121 * @return true if there is at least one default value, false if there is none
122 */
123 1 bool generator_checkDefaultValueExist(const std::vector<PClassAttribute> & vecAttr){
124 1 bool hasDefaultValue = false;
125
5/6
✓ Branch 0 (17→18) taken 2 times.
✓ Branch 1 (17→20) taken 1 times.
✓ Branch 2 (18→19) taken 2 times.
✗ Branch 3 (18→20) not taken.
✓ Branch 4 (21→3) taken 2 times.
✓ Branch 5 (21→22) taken 1 times.
6 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end() && !hasDefaultValue; ++it){
126
2/2
✓ Branch 0 (5→6) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
2 hasDefaultValue |= it->getDefaultValue() != "";
127 }
128 1 return hasDefaultValue;
129 }
130
131 ///Create the declaration of the given class
132 /** @param manager : PTraitBackendManager which handles all trait backend
133 * @param[out] fs : file to be completed
134 * @param classConfig : configuration of the class to be used
135 * @param mode : mode of the generator
136 */
137 1 void generator_enum_cpp_header(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){
138
6/7
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 4 (4→5) taken 1 times.
✗ Branch 5 (4→8) not taken.
✓ Branch 6 (5→6) taken 1 times.
✓ Branch 8 (6→7) taken 1 times.
✓ Branch 10 (7→8) taken 1 times.
1 if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl;
139
2/2
✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
1 PString name(classConfig.getName());
140
3/3
✓ Branch 0 (10→11) taken 1 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 4 (12→13) taken 1 times.
1 fs << "namespace " << name << " {\n";
141
7/8
✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
✗ Branch 5 (15→20) not taken.
✓ Branch 6 (16→17) taken 1 times.
✓ Branch 8 (17→18) taken 1 times.
✓ Branch 10 (18→19) taken 1 times.
✓ Branch 12 (19→20) taken 1 times.
1 if(classConfig.getClassDocumentation() != ""){fs << "\t"<< classConfig.getClassDocumentation() << std::endl;}
142
3/3
✓ Branch 0 (20→21) taken 1 times.
✓ Branch 2 (21→22) taken 1 times.
✓ Branch 4 (22→23) taken 1 times.
1 fs << "\tenum " << name << " {\n\t\t";
143
1/1
✓ Branch 0 (23→24) taken 1 times.
1 const std::vector<PClassAttribute> & vecAttr(classConfig.getListAttribute());
144
1/1
✓ Branch 0 (24→25) taken 1 times.
1 bool isDefaultCounterActivated = !generator_checkDefaultValueExist(vecAttr);
145
1/1
✓ Branch 0 (25→26) taken 1 times.
1 PString comma("");
146 1 size_t i(0lu);
147
2/2
✓ Branch 0 (67→27) taken 2 times.
✓ Branch 1 (67→68) taken 1 times.
6 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
148
3/8
✓ Branch 0 (29→30) taken 2 times.
✓ Branch 2 (30→31) taken 2 times.
✗ Branch 4 (31→32) not taken.
✓ Branch 5 (31→38) taken 2 times.
✗ Branch 6 (32→33) not taken.
✗ Branch 8 (35→36) not taken.
✗ Branch 10 (36→37) not taken.
✗ Branch 12 (37→38) not taken.
2 if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl;
149
3/3
✓ Branch 0 (38→39) taken 2 times.
✓ Branch 2 (41→42) taken 2 times.
✓ Branch 4 (42→43) taken 2 times.
4 fs << comma << it->getName();
150
1/2
✓ Branch 0 (43→44) taken 2 times.
✗ Branch 1 (43→46) not taken.
2 if(isDefaultCounterActivated){
151
2/2
✓ Branch 0 (44→45) taken 2 times.
✓ Branch 2 (45→56) taken 2 times.
2 fs << " = " << i;
152 }else if(it->getDefaultValue() != ""){
153 fs << " = " << it->getDefaultValue();
154 }
155
1/1
✓ Branch 0 (56→57) taken 2 times.
2 comma = ",\n\t\t";
156 2 ++i;
157 }
158
2/2
✓ Branch 0 (68→69) taken 1 times.
✓ Branch 2 (69→70) taken 1 times.
1 fs << "\n\t};" << std::endl;
159
3/3
✓ Branch 0 (70→71) taken 1 times.
✓ Branch 2 (71→72) taken 1 times.
✓ Branch 4 (72→73) taken 1 times.
1 fs << "}" << std::endl << std::endl;
160
1/1
✓ Branch 0 (73→74) taken 1 times.
1 manager.classExtraFunctionDeclaration(fs, classConfig, mode);
161
2/2
✓ Branch 0 (74→75) taken 1 times.
✓ Branch 2 (75→76) taken 1 times.
1 fs << std::endl << std::endl;
162 1 }
163
164
165 ///Create the declaration of the given class
166 /** @param manager : PTraitBackendManager which handles all trait backend
167 * @param[out] fs : file to be completed
168 * @param classConfig : configuration of the class to be used
169 * @param mode : mode of the generator
170 */
171 7 void generator_class_cpp_header(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){
172
6/7
✓ Branch 0 (2→3) taken 7 times.
✓ Branch 2 (3→4) taken 7 times.
✓ Branch 4 (4→5) taken 7 times.
✗ Branch 5 (4→8) not taken.
✓ Branch 6 (5→6) taken 7 times.
✓ Branch 8 (6→7) taken 7 times.
✓ Branch 10 (7→8) taken 7 times.
7 if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl;
173
2/2
✓ Branch 0 (8→9) taken 7 times.
✓ Branch 2 (9→10) taken 7 times.
7 PString name(classConfig.getName());
174
2/2
✓ Branch 0 (10→11) taken 7 times.
✓ Branch 2 (11→12) taken 7 times.
7 PString namespaceName(classConfig.getNamespace());
175
1/1
✓ Branch 0 (12→13) taken 7 times.
7 GeneratorMode classMode(mode);
176
1/1
✓ Branch 0 (13→14) taken 7 times.
7 const PVecString & listTemplate = classConfig.getListTemplate();
177
1/1
✓ Branch 0 (14→15) taken 7 times.
7 PString defTemplate(class_getClassDefTemplate(listTemplate));
178
1/1
✓ Branch 0 (15→16) taken 7 times.
7 PString templateDeclaration(class_getClassDeclTempalteDef(listTemplate));
179
1/1
✓ Branch 0 (16→17) taken 7 times.
7 classMode.defTemplate = defTemplate;
180
1/1
✓ Branch 0 (17→18) taken 7 times.
7 classMode.templateDeclaration = templateDeclaration;
181
182
1/1
✓ Branch 0 (18→19) taken 7 times.
7 fs << classMode.templateDeclaration;
183
1/1
✓ Branch 0 (19→20) taken 7 times.
7 fs << "class ";
184
2/3
✓ Branch 0 (20→21) taken 7 times.
✗ Branch 2 (21→22) not taken.
✓ Branch 3 (21→24) taken 7 times.
7 if(namespaceName != ""){
185 fs << namespaceName << "::";
186 }
187
1/1
✓ Branch 0 (24→25) taken 7 times.
7 fs << name;
188
2/3
✓ Branch 0 (25→26) taken 7 times.
✗ Branch 2 (27→28) not taken.
✓ Branch 3 (27→55) taken 7 times.
7 if(classConfig.getListParentClass().size() != 0lu){
189 PVecString::const_iterator it(classConfig.getListParentClass().begin());
190 fs << " : public " << *it;
191 if(classConfig.getListParentClass().size() > 1lu){
192 while(it != classConfig.getListParentClass().end()){
193 fs << ", " << *it;
194 ++it;
195 }
196 }
197 }
198
2/2
✓ Branch 0 (55→56) taken 7 times.
✓ Branch 2 (56→57) taken 7 times.
7 fs << "{" << std::endl;
199
2/2
✓ Branch 0 (57→58) taken 7 times.
✓ Branch 2 (58→59) taken 7 times.
7 fs << "\tpublic:" << std::endl;
200
4/4
✓ Branch 0 (59→60) taken 7 times.
✓ Branch 2 (60→61) taken 7 times.
✓ Branch 4 (61→62) taken 7 times.
✓ Branch 6 (62→63) taken 7 times.
7 fs << "\t\t" << name << "();" << std::endl;
201
4/4
✓ Branch 0 (63→64) taken 7 times.
✓ Branch 2 (64→65) taken 7 times.
✓ Branch 4 (65→66) taken 7 times.
✓ Branch 6 (66→67) taken 7 times.
7 fs << "\t\tvirtual ~" << name << "() = default;" << std::endl;
202
203
1/1
✓ Branch 0 (67→68) taken 7 times.
7 manager.publicMethodDeclaration(fs, classConfig, classMode);
204
2/2
✓ Branch 0 (68→69) taken 7 times.
✓ Branch 2 (69→70) taken 7 times.
7 fs << "\tprotected:" << std::endl;
205
1/1
✓ Branch 0 (70→71) taken 7 times.
7 manager.protectedMethodDeclaration(fs, classConfig, classMode);
206
207
2/2
✓ Branch 0 (71→72) taken 7 times.
✓ Branch 2 (72→73) taken 7 times.
7 fs << "\tprivate:" << std::endl;
208
4/4
✓ Branch 0 (73→74) taken 7 times.
✓ Branch 2 (74→75) taken 7 times.
✓ Branch 4 (75→76) taken 7 times.
✓ Branch 6 (76→77) taken 7 times.
7 fs << "\t\tvoid initialisation" << name << "();" << std::endl;
209
1/1
✓ Branch 0 (77→78) taken 7 times.
7 manager.privateMethodDeclaration(fs, classConfig, classMode);
210
1/1
✓ Branch 0 (78→79) taken 7 times.
7 const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
211
2/2
✓ Branch 0 (113→80) taken 16 times.
✓ Branch 1 (113→114) taken 7 times.
46 for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
212
7/8
✓ Branch 0 (82→83) taken 16 times.
✓ Branch 2 (83→84) taken 16 times.
✓ Branch 4 (84→85) taken 16 times.
✗ Branch 5 (84→91) not taken.
✓ Branch 6 (85→86) taken 16 times.
✓ Branch 8 (88→89) taken 16 times.
✓ Branch 10 (89→90) taken 16 times.
✓ Branch 12 (90→91) taken 16 times.
32 if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl;
213
214
8/8
✓ Branch 0 (91→92) taken 16 times.
✓ Branch 2 (94→95) taken 16 times.
✓ Branch 4 (95→96) taken 16 times.
✓ Branch 6 (96→97) taken 16 times.
✓ Branch 8 (99→100) taken 16 times.
✓ Branch 10 (100→101) taken 16 times.
✓ Branch 12 (101→102) taken 16 times.
✓ Branch 14 (102→103) taken 16 times.
48 fs << "\t\t" << it->getType() << " p_" << it->getName() << ";" << std::endl;
215 }
216
3/3
✓ Branch 0 (114→115) taken 7 times.
✓ Branch 2 (115→116) taken 7 times.
✓ Branch 4 (116→117) taken 7 times.
7 fs << "};" << std::endl << std::endl;
217
1/1
✓ Branch 0 (117→118) taken 7 times.
7 manager.classExtraFunctionDeclaration(fs, classConfig, classMode);
218
2/2
✓ Branch 0 (118→119) taken 7 times.
✓ Branch 2 (119→120) taken 7 times.
7 fs << std::endl << std::endl;
219 7 }
220
221 ///Create the declaration of the given class
222 /** @param manager : PTraitBackendManager which handles all trait backend
223 * @param headerFile : file to be saved
224 * @param vecClassConfig : configuration of the class to be used
225 * @param mode : mode of the generator
226 * @param vecInclude : vector of include files to be added into the header
227 * @param includeTemplate : extra include for the template implementation
228 * @return true on success, false otherwise
229 */
230 6 bool generator_class_cpp_headerFile(const PTraitBackendManager & manager, const PPath & headerFile, const std::vector<PClassConfig> & vecClassConfig, const GeneratorMode & mode,
231 const PVecPath & vecInclude, const PString & includeTemplate)
232 {
233
2/3
✓ Branch 0 (2→3) taken 6 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 6 times.
6 if(headerFile == "") return false;
234
1/1
✓ Branch 0 (5→6) taken 6 times.
6 std::ofstream fs;
235
2/3
✓ Branch 0 (6→7) taken 6 times.
✗ Branch 2 (7→8) not taken.
✓ Branch 3 (7→9) taken 6 times.
6 if(!openFileStream(fs, headerFile)){return false;}
236
1/1
✓ Branch 0 (9→10) taken 6 times.
6 licenceSave(fs);
237
2/2
✓ Branch 0 (10→11) taken 6 times.
✓ Branch 2 (11→12) taken 6 times.
6 PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName()));
238
3/3
✓ Branch 0 (13→14) taken 6 times.
✓ Branch 2 (14→15) taken 6 times.
✓ Branch 4 (15→16) taken 6 times.
6 fs << "#ifndef " << macroDef << std::endl;
239
4/4
✓ Branch 0 (16→17) taken 6 times.
✓ Branch 2 (17→18) taken 6 times.
✓ Branch 4 (18→19) taken 6 times.
✓ Branch 6 (19→20) taken 6 times.
6 fs << "#define " << macroDef << std::endl << std::endl;
240
2/2
✓ Branch 0 (20→21) taken 6 times.
✓ Branch 2 (21→22) taken 6 times.
6 fs << "#include <string>" << std::endl;
241
1/2
✗ Branch 0 (23→24) not taken.
✓ Branch 1 (23→42) taken 6 times.
6 if(vecInclude.size() != 0lu){
242 for(PVecPath::const_iterator it(vecInclude.begin()); it != vecInclude.end(); ++it){
243 fs << "#include " << *it << std::endl;
244 }
245 fs << std::endl;
246 }
247
1/1
✓ Branch 0 (42→43) taken 6 times.
6 manager.headerExtraInclude(fs, mode);
248
1/1
✓ Branch 0 (43→44) taken 6 times.
6 fs << std::endl;
249
2/2
✓ Branch 0 (65→45) taken 7 times.
✓ Branch 1 (65→66) taken 6 times.
26 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
250
3/3
✓ Branch 0 (47→48) taken 7 times.
✓ Branch 2 (48→49) taken 1 times.
✓ Branch 3 (48→52) taken 6 times.
7 if(it->getIsEnum()){
251
1/1
✓ Branch 0 (51→55) taken 1 times.
1 generator_enum_cpp_header(manager, fs, *it, mode);
252 // saveEnumDecl(fs, *it, mode);
253 }else{
254
1/1
✓ Branch 0 (54→55) taken 6 times.
6 generator_class_cpp_header(manager, fs, *it, mode);
255 }
256 }
257
258
2/3
✓ Branch 0 (66→67) taken 6 times.
✗ Branch 2 (67→68) not taken.
✓ Branch 3 (67→73) taken 6 times.
6 if(includeTemplate != ""){
259 fs << "#include \""<<includeTemplate<<"\"" << std::endl << std::endl;
260 }
261
262
5/5
✓ Branch 0 (73→74) taken 6 times.
✓ Branch 2 (74→75) taken 6 times.
✓ Branch 4 (75→76) taken 6 times.
✓ Branch 6 (76→77) taken 6 times.
✓ Branch 8 (77→78) taken 6 times.
6 fs << std::endl << std::endl << "#endif" << std::endl << std::endl;
263
1/1
✓ Branch 0 (78→79) taken 6 times.
6 fs.close();
264 6 return true;
265 6 }
266
267 ///Create the implementation of the given class
268 /** @param manager : PTraitBackendManager which handles all trait backend
269 * @param[out] fs : file to be completed
270 * @param classConfig : configuration of the class to be used
271 * @param mode : mode of the generator
272 */
273 8 void generator_class_cpp_source(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){
274
1/1
✓ Branch 0 (2→3) taken 8 times.
8 manager.classExtraFunctionImplementation(fs, classConfig, mode);
275
1/1
✓ Branch 0 (3→4) taken 8 times.
8 GeneratorMode classMode(mode);
276
1/1
✓ Branch 0 (4→5) taken 8 times.
8 const PVecString & listTemplate = classConfig.getListTemplate();
277
1/1
✓ Branch 0 (5→6) taken 8 times.
8 PString defTemplate(class_getClassDefTemplate(listTemplate));
278
1/1
✓ Branch 0 (6→7) taken 8 times.
8 PString templateDeclaration(class_getClassDeclTempalteDef(listTemplate));
279
1/1
✓ Branch 0 (7→8) taken 8 times.
8 classMode.defTemplate = defTemplate;
280
1/1
✓ Branch 0 (8→9) taken 8 times.
8 classMode.templateDeclaration = templateDeclaration;
281
3/3
✓ Branch 0 (9→10) taken 8 times.
✓ Branch 2 (10→11) taken 7 times.
✓ Branch 3 (10→12) taken 1 times.
8 if(!classConfig.getIsEnum()){
282
1/1
✓ Branch 0 (11→12) taken 7 times.
7 class_saveClassConstructorImpl(fs, classConfig, defTemplate, templateDeclaration);
283 }
284
1/1
✓ Branch 0 (12→13) taken 8 times.
8 manager.publicMethodImplementation(fs, classConfig, classMode);
285
1/1
✓ Branch 0 (13→14) taken 8 times.
8 manager.protectedMethodImplementation(fs, classConfig, classMode);
286
1/1
✓ Branch 0 (14→15) taken 8 times.
8 manager.privateMethodImplementation(fs, classConfig, classMode);
287
3/3
✓ Branch 0 (15→16) taken 8 times.
✓ Branch 2 (16→17) taken 7 times.
✓ Branch 3 (16→18) taken 1 times.
8 if(!classConfig.getIsEnum()){
288
1/1
✓ Branch 0 (17→18) taken 7 times.
7 class_saveClassInitialisationFunctionImpl(fs, classConfig, defTemplate, templateDeclaration);
289 }
290 8 }
291
292 ///Create the implementation of the given file
293 /** @param manager : PTraitBackendManager which handles all trait backend
294 * @param sourceFile : source file to be saved
295 * @param headerFile : header to be used with this source file
296 * @param vecClassConfig : vector of configuration of the classes to be used
297 * @param mode : mode of the generator
298 * @param isTemplateImpl : true to activate
299 * @return true on success, false otherwise
300 */
301 6 bool generator_class_cpp_sourceFile(const PTraitBackendManager & manager, const PPath & sourceFile, const PPath & headerFile,
302 const std::vector<PClassConfig> & vecClassConfig, const GeneratorMode & mode, bool isTemplateImpl)
303 {
304
5/8
✓ Branch 0 (2→3) taken 6 times.
✓ Branch 2 (3→4) taken 6 times.
✗ Branch 3 (3→6) not taken.
✓ Branch 4 (4→5) taken 6 times.
✗ Branch 6 (5→6) not taken.
✓ Branch 7 (5→7) taken 6 times.
✗ Branch 8 (8→9) not taken.
✓ Branch 9 (8→10) taken 6 times.
6 if(sourceFile == "" || headerFile == "") return false;
305
1/1
✓ Branch 0 (10→11) taken 6 times.
6 std::ofstream fs;
306
2/3
✓ Branch 0 (11→12) taken 6 times.
✗ Branch 2 (12→13) not taken.
✓ Branch 3 (12→14) taken 6 times.
6 if(!openFileStream(fs, sourceFile)){return false;}
307
1/1
✓ Branch 0 (14→15) taken 6 times.
6 licenceSave(fs);
308
1/2
✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→32) taken 6 times.
6 if(isTemplateImpl){
309 PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName() + "_IMPL"));
310 fs << "#ifndef " << macroDef << std::endl;
311 fs << "#define " << macroDef << std::endl << std::endl;
312 }
313
7/7
✓ Branch 0 (32→33) taken 6 times.
✓ Branch 2 (33→34) taken 6 times.
✓ Branch 4 (34→35) taken 6 times.
✓ Branch 6 (35→36) taken 6 times.
✓ Branch 8 (36→37) taken 6 times.
✓ Branch 10 (37→38) taken 6 times.
✓ Branch 12 (38→39) taken 6 times.
6 fs << std::endl << "#include \"" << headerFile.getFileName() << "\"" << std::endl << std::endl;
314 6 bool hasNamespace(false);
315
2/2
✓ Branch 0 (69→41) taken 7 times.
✓ Branch 1 (69→70) taken 6 times.
26 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
316
4/8
✓ Branch 0 (43→44) taken 7 times.
✓ Branch 2 (44→45) taken 7 times.
✗ Branch 4 (45→46) not taken.
✓ Branch 5 (45→48) taken 7 times.
✗ Branch 6 (46→47) not taken.
✗ Branch 7 (46→48) not taken.
✗ Branch 8 (49→50) not taken.
✓ Branch 9 (49→59) taken 7 times.
7 if(it->getNamespace() != "" && !hasNamespace){
317 fs << "using namespace " << it->getNamespace() << ";" << std::endl << std::endl;
318 hasNamespace = true;
319 }
320 }
321
2/2
✓ Branch 0 (84→71) taken 7 times.
✓ Branch 1 (84→85) taken 6 times.
26 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
322
1/1
✓ Branch 0 (73→74) taken 7 times.
7 generator_class_cpp_source(manager, fs, *it, mode);
323 }
324
1/2
✗ Branch 0 (85→86) not taken.
✓ Branch 1 (85→89) taken 6 times.
6 if(isTemplateImpl){
325 fs << "#endif" << std::endl << std::endl;
326 }
327
1/1
✓ Branch 0 (89→90) taken 6 times.
6 fs.close();
328
329 6 return true;
330 6 }
331
332
333
334 ///Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated
335 /** @param[out] hasSource : true if the configuration needs .cpp file
336 * @param[out] hasTemplate : true if the configuration needs _impl.h file
337 * @param vecClassConfig : class config we want to save
338 */
339 6 void class_checkClassConfig(bool & hasSource, bool & hasTemplate, const std::vector<PClassConfig> & vecClassConfig){
340 6 hasSource = false;
341 6 hasTemplate = false;
342
2/2
✓ Branch 0 (17→3) taken 7 times.
✓ Branch 1 (17→18) taken 6 times.
26 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
343
1/1
✓ Branch 0 (5→6) taken 7 times.
7 bool isTemplate = it->getListTemplate().size() != 0lu;
344 7 hasSource |= !isTemplate;
345 7 hasTemplate |= isTemplate;
346 }
347 6 }
348
349 ///Creates header and source files
350 /** @param manager : PTraitBackendManager which handles all trait backend
351 * @param vecClassConfig : vector of class config we want to save
352 * @param baseFileName : base file name for header or source file
353 * @param outputSourceDir : output directory where to save sources
354 * @param mode : all modes of the generator (data/check/type/config stream)
355 * @return true on success, false otherwise
356 */
357 6 bool generator_class_cpp(const PTraitBackendManager & manager, const std::vector<PClassConfig> & vecClassConfig, const PPath & outputSourceDir, const PPath & baseFileName, const GeneratorMode & mode, const PVecPath & vecInclude){
358
2/3
✓ Branch 0 (2→3) taken 6 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→13) taken 6 times.
6 if(baseFileName == ""){
359 std::cerr << termRed() << "generator_class_cpp : baseFileName is empty" << termDefault() << std::endl;
360 return false;
361 }
362 6 bool hasSource(false), hasTemplate(false);
363
1/1
✓ Branch 0 (13→14) taken 6 times.
6 class_checkClassConfig(hasSource, hasTemplate, vecClassConfig);
364
1/1
✓ Branch 0 (14→15) taken 6 times.
6 PString includeTemplate("");
365
1/2
✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→24) taken 6 times.
6 if(hasTemplate){
366 includeTemplate = PString(baseFileName.getFileName() + "_impl.h");
367 }
368
4/4
✓ Branch 0 (24→25) taken 6 times.
✓ Branch 2 (25→26) taken 6 times.
✓ Branch 4 (26→27) taken 6 times.
✓ Branch 6 (27→28) taken 6 times.
6 PPath headerFile = outputSourceDir / PPath(baseFileName + ".h");
369
2/3
✓ Branch 0 (31→32) taken 6 times.
✗ Branch 2 (32→33) not taken.
✓ Branch 3 (32→44) taken 6 times.
6 if(!generator_class_cpp_headerFile(manager, headerFile, vecClassConfig, mode, vecInclude, includeTemplate)){
370 std::cerr << termRed() << "generator_class_cpp : cannot generate header file '"<<headerFile<<"'" << termDefault() << std::endl;
371 return false;
372 }
373
1/2
✓ Branch 0 (44→45) taken 6 times.
✗ Branch 1 (44→81) not taken.
6 if(hasSource){
374
5/5
✓ Branch 0 (45→46) taken 6 times.
✓ Branch 2 (46→47) taken 6 times.
✓ Branch 4 (47→48) taken 6 times.
✓ Branch 6 (48→49) taken 6 times.
✓ Branch 8 (49→50) taken 6 times.
6 PPath sourceFile = outputSourceDir / PPath(baseFileName + PString(".cpp"));
375
6/7
✓ Branch 0 (54→55) taken 6 times.
✓ Branch 2 (55→56) taken 6 times.
✓ Branch 4 (56→57) taken 6 times.
✓ Branch 6 (57→58) taken 6 times.
✓ Branch 8 (58→59) taken 6 times.
✗ Branch 10 (63→64) not taken.
✓ Branch 11 (63→75) taken 6 times.
6 if(!generator_class_cpp_sourceFile(manager, sourceFile, PPath(baseFileName + PString(".h")), vecClassConfig, mode, false)){
376 std::cerr << termRed() << "generator_class_cpp : cannot generate source file '"<<sourceFile<<"'" << termDefault() << std::endl;
377 return false;
378 }
379
1/2
✓ Branch 0 (77→78) taken 6 times.
✗ Branch 1 (77→80) not taken.
6 }
380
1/2
✗ Branch 0 (81→82) not taken.
✓ Branch 1 (81→118) taken 6 times.
6 if(hasTemplate){
381 PPath implFile = outputSourceDir / PPath(baseFileName + PString("_impl.h"));
382 if(!generator_class_cpp_sourceFile(manager, implFile, PPath(baseFileName + PString(".h")), vecClassConfig, mode, true)){
383 std::cerr << termRed() << "generator_class_cpp : cannot generate impl file '"<<implFile<<"'" << termDefault() << std::endl;
384 return false;
385 }
386 }
387 6 return true;
388 6 }
389
390
391 ///Save the CMakeLists to be used to compile the unit test
392 /** @param manager : PTraitBackendManager which handles all trait backend
393 * @param outputCurrentTestDir : current test directoru in which to create the CMakeLists.txt
394 * @param classConfig : class configuration to be used
395 * @param baseFileName : base of output file name of the generated sources
396 * @param mode : all modes of the generator (data/check/type/config stream)
397 * @return true on success, false oterhwise
398 */
399 6 bool generator_class_testMain(const PTraitBackendManager & manager, const PPath & outputCurrentTestDir, const PClassConfig & classConfig, const PPath & baseFileName, const GeneratorMode & mode){
400
1/1
✓ Branch 0 (2→3) taken 6 times.
6 std::ofstream fs;
401
6/7
✓ Branch 0 (3→4) taken 6 times.
✓ Branch 2 (4→5) taken 6 times.
✓ Branch 4 (5→6) taken 6 times.
✓ Branch 6 (6→7) taken 6 times.
✓ Branch 8 (7→8) taken 6 times.
✗ Branch 10 (12→13) not taken.
✓ Branch 11 (12→14) taken 6 times.
6 if(!openFileStream(fs, PPath(outputCurrentTestDir + PString("/main.cpp")))){return false;}
402
1/1
✓ Branch 0 (14→15) taken 6 times.
6 licenceSave(fs);
403 // body += licenceSaveStr() + "\n";
404
2/3
✓ Branch 0 (15→16) taken 6 times.
✓ Branch 2 (16→17) taken 6 times.
✗ Branch 3 (16→23) not taken.
6 if(mode.assertInclude != ""){
405
3/3
✓ Branch 0 (17→18) taken 6 times.
✓ Branch 2 (18→19) taken 6 times.
✓ Branch 4 (19→20) taken 6 times.
6 fs << "#include \"" + mode.assertInclude + "\"\n\n";
406 }
407
3/3
✓ Branch 0 (23→24) taken 6 times.
✓ Branch 2 (24→25) taken 6 times.
✓ Branch 4 (25→26) taken 6 times.
6 fs << "#include \"" + baseFileName + ".h\"\n\n";
408
3/8
✓ Branch 0 (28→29) taken 6 times.
✓ Branch 2 (29→30) taken 6 times.
✗ Branch 4 (30→31) not taken.
✓ Branch 5 (30→35) taken 6 times.
✗ Branch 6 (31→32) not taken.
✗ Branch 8 (32→33) not taken.
✗ Branch 10 (33→34) not taken.
✗ Branch 12 (34→35) not taken.
6 if(classConfig.getNamespace() != ""){fs << "using namespace " << classConfig.getNamespace() << ";\n\n";}
409
1/1
✓ Branch 0 (35→36) taken 6 times.
6 manager.testFunction(fs, classConfig, mode);
410
1/1
✓ Branch 0 (36→37) taken 6 times.
6 fs << "int main(int argc, char ** argv){\n";
411 //Do other test if the enableDataStream is true
412
1/1
✓ Branch 0 (37→38) taken 6 times.
6 manager.testCallFunction(fs, classConfig, mode);
413
1/1
✓ Branch 0 (38→39) taken 6 times.
6 fs << "\treturn 0;\n";
414
1/1
✓ Branch 0 (39→40) taken 6 times.
6 fs << "}\n";
415
1/1
✓ Branch 0 (40→41) taken 6 times.
6 fs.close();
416 6 return true;
417 6 }
418
419 ///Save the CMakeLists to be used to compile the unit test
420 /** @param outputCurrentTestDir : current test directory in which to create the CMakeLists.txt
421 * @param classConfig : class configuration to be used
422 * @param projectName : configuration of the project
423 * @param mode : all modes of the generator (data/check/type/config stream)
424 * @return true on success, false oterhwise
425 */
426 6 bool generator_class_testCMakeLists( const PPath & outputCurrentTestDir, const PClassConfig & classConfig, const PString & projectName, const GeneratorMode & mode){
427
5/5
✓ Branch 0 (2→3) taken 6 times.
✓ Branch 2 (3→4) taken 6 times.
✓ Branch 4 (4→5) taken 6 times.
✓ Branch 6 (5→6) taken 6 times.
✓ Branch 8 (6→7) taken 6 times.
6 PString body(""), testName("test_class_" + classConfig.getName().toLowerUnderscore());
428
2/2
✓ Branch 0 (9→10) taken 6 times.
✓ Branch 2 (10→11) taken 6 times.
6 body += getCMakeListsHeader();
429
3/3
✓ Branch 0 (12→13) taken 6 times.
✓ Branch 2 (13→14) taken 6 times.
✓ Branch 4 (14→15) taken 6 times.
6 body += "add_executable("+testName+" main.cpp)\n";
430
6/6
✓ Branch 0 (17→18) taken 6 times.
✓ Branch 2 (18→19) taken 6 times.
✓ Branch 4 (19→20) taken 6 times.
✓ Branch 6 (20→21) taken 6 times.
✓ Branch 8 (21→22) taken 6 times.
✓ Branch 10 (22→23) taken 6 times.
6 body += "target_link_libraries("+testName+" ${"+projectName.toUpper()+"_TEST_DEPENDENCIES})\n";
431
1/1
✓ Branch 0 (28→29) taken 6 times.
6 body += "\n";
432
4/4
✓ Branch 0 (29→30) taken 6 times.
✓ Branch 2 (30→31) taken 6 times.
✓ Branch 4 (31→32) taken 6 times.
✓ Branch 6 (32→33) taken 6 times.
6 body += "add_test(NAME "+testName.firstToUpper()+"\n";
433
3/3
✓ Branch 0 (36→37) taken 6 times.
✓ Branch 2 (37→38) taken 6 times.
✓ Branch 4 (38→39) taken 6 times.
6 body += "\tCOMMAND ${CMAKE_CURRENT_BINARY_DIR}/"+testName+"\n";
434
1/1
✓ Branch 0 (41→42) taken 6 times.
6 body += "\tWORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}\n";
435
1/1
✓ Branch 0 (42→43) taken 6 times.
6 body += ")\n\n\n";
436
5/5
✓ Branch 0 (43→44) taken 6 times.
✓ Branch 2 (44→45) taken 6 times.
✓ Branch 4 (45→46) taken 6 times.
✓ Branch 6 (46→47) taken 6 times.
✓ Branch 8 (47→48) taken 6 times.
12 return PPath(outputCurrentTestDir + PString("/CMakeLists.txt")).saveFileContent(body);
437 6 }
438
439 ///Save the unit test of the generated PClassConfig
440 /** @param manager : PTraitBackendManager which handles all trait backend
441 * @param outputTestDir : output directory where to put the genreated test (typically ../TESTS if the program is called from ./src)
442 * @param classConfig : class configuration to be used
443 * @param projectName : configuration of the project
444 * @param baseFileName : base of output file name of the generated sources
445 * @param mode : all modes of the generator (data/check/type/config stream)
446 * @return true on success, false oterhwise
447 */
448 6 bool generator_class_test(const PTraitBackendManager & manager, const PPath & outputTestDir, const PClassConfig & classConfig, const PString & projectName, const PPath & baseFileName, const GeneratorMode & mode){
449
2/2
✓ Branch 0 (2→3) taken 6 times.
✓ Branch 2 (3→4) taken 6 times.
6 PString name(classConfig.getName());
450
6/6
✓ Branch 0 (4→5) taken 6 times.
✓ Branch 2 (5→6) taken 6 times.
✓ Branch 4 (6→7) taken 6 times.
✓ Branch 6 (7→8) taken 6 times.
✓ Branch 8 (8→9) taken 6 times.
✓ Branch 10 (9→10) taken 6 times.
6 PPath outputCurrentTestDir(outputTestDir + PString("/TEST_") + name.toUpper());
451
2/7
✓ Branch 0 (15→16) taken 6 times.
✗ Branch 2 (16→17) not taken.
✓ Branch 3 (16→22) taken 6 times.
✗ Branch 4 (17→18) not taken.
✗ Branch 6 (18→19) not taken.
✗ Branch 8 (19→20) not taken.
✗ Branch 10 (20→21) not taken.
6 if(!outputCurrentTestDir.createDirectory()){std::cerr << "generator_class_test : cannot create TEST directory '"<<outputCurrentTestDir<<"'" << std::endl;return false;}
452
453 6 bool b(true);
454
1/1
✓ Branch 0 (22→23) taken 6 times.
6 b &= generator_class_testCMakeLists(outputCurrentTestDir, classConfig, projectName, mode);
455
1/1
✓ Branch 0 (23→24) taken 6 times.
6 b &= generator_class_testMain(manager, outputCurrentTestDir, classConfig, baseFileName, mode);
456 6 return b;
457 6 }
458
459 ///Save the unit test of the generated PClassConfig
460 /** @param manager : PTraitBackendManager which handles all trait backend
461 * @param outputTestDir : output directory where to put the generated test (typically ../TESTS if the program is called from ./src)
462 * @param vecClassConfig : vector of class configuration to be used
463 * @param projectName : configuration of the project
464 * @param baseFileName : base of output file name of the generated sources
465 * @param mode : all modes of the generator (data/check/type/config stream)
466 * @return true on success, false oterhwise
467 */
468 5 bool generator_class_cpp_test(const PTraitBackendManager & manager, const PPath & outputTestDir, const std::vector<PClassConfig> & vecClassConfig, const PString & projectName, const PPath & baseFileName, const GeneratorMode & mode){
469
1/1
✓ Branch 0 (2→3) taken 5 times.
5 PString cmakeListBody;
470
2/2
✓ Branch 0 (3→4) taken 5 times.
✓ Branch 2 (4→5) taken 5 times.
5 cmakeListBody += getCMakeListsHeader();
471 5 bool b(true);
472
4/4
✓ Branch 0 (7→8) taken 5 times.
✓ Branch 2 (8→9) taken 5 times.
✓ Branch 4 (9→10) taken 5 times.
✓ Branch 6 (10→11) taken 5 times.
5 cmakeListBody += "#Generating tests for " + PString::toString(vecClassConfig.size()) + "\n";
473
2/2
✓ Branch 0 (38→15) taken 6 times.
✓ Branch 1 (38→39) taken 5 times.
22 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
474
5/5
✓ Branch 0 (17→18) taken 6 times.
✓ Branch 2 (18→19) taken 6 times.
✓ Branch 4 (19→20) taken 6 times.
✓ Branch 6 (20→21) taken 6 times.
✓ Branch 8 (21→22) taken 6 times.
6 cmakeListBody += "add_subdirectory(TEST_" + it->getName().toUpper() + ")\n";
475
1/1
✓ Branch 0 (27→28) taken 6 times.
6 b &= generator_class_test(manager, outputTestDir, *it, projectName, baseFileName, mode);
476 }
477
1/1
✓ Branch 0 (39→40) taken 5 times.
5 cmakeListBody += "\n\n";
478
3/3
✓ Branch 0 (40→41) taken 5 times.
✓ Branch 2 (41→42) taken 5 times.
✓ Branch 4 (42→43) taken 5 times.
5 PPath cmakelist(outputTestDir / PPath("CMakeLists.txt"));
479
1/1
✓ Branch 0 (45→46) taken 5 times.
5 b &= cmakelist.saveFileContent(cmakeListBody);
480 5 return b;
481 5 }
482
483 ///Generate the full sources and related unit tests from configuration
484 /** @param manager : PTraitBackendManager which handles all trait backend
485 * @param projectParam : description of classes and how and where to generate sources and test
486 * @return true on success, false otherwise
487 */
488 3 bool generator_class_full(const PTraitBackendManager & manager, const ProjectParam & projectParam){
489 3 bool b(true);
490
1/1
✓ Branch 0 (2→3) taken 3 times.
3 b &= projectParam.outputSourceDir.createDirectory();
491
1/1
✓ Branch 0 (3→4) taken 3 times.
3 b &= projectParam.outputTestDir.createDirectory();
492
1/1
✓ Branch 0 (4→5) taken 3 times.
3 PString cmakeListBody;
493
2/2
✓ Branch 0 (5→6) taken 3 times.
✓ Branch 2 (6→7) taken 3 times.
3 cmakeListBody += getCMakeListsHeader();
494 3 const PVecDataConfig & vecDataConfig = projectParam.vecDataConfig;
495
2/2
✓ Branch 0 (77→10) taken 5 times.
✓ Branch 1 (77→78) taken 3 times.
11 for(const PDataConfig & config : vecDataConfig){
496
4/4
✓ Branch 0 (12→13) taken 5 times.
✓ Branch 2 (13→14) taken 5 times.
✓ Branch 4 (14→15) taken 5 times.
✓ Branch 6 (15→16) taken 5 times.
5 PPath baseFileName = config.getFileName().getFileName().eraseExtension();
497
4/5
✓ Branch 0 (17→18) taken 5 times.
✓ Branch 2 (18→19) taken 5 times.
✓ Branch 4 (19→20) taken 5 times.
✗ Branch 6 (20→21) not taken.
✓ Branch 7 (20→32) taken 5 times.
5 if(!generator_class_cpp(manager, config.getVecClassConfig(), projectParam.outputSourceDir, baseFileName, projectParam.mode, config.getVecInclude())){
498 std::cerr << termRed() << "generator_class_full : cannot generate C++ sources at '"<<projectParam.outputSourceDir<<"'" << termDefault() << std::endl;
499 b = false; //best effort strategy
500 }
501
8/8
✓ Branch 0 (32→33) taken 5 times.
✓ Branch 2 (33→34) taken 5 times.
✓ Branch 4 (34→35) taken 5 times.
✓ Branch 6 (35→36) taken 5 times.
✓ Branch 8 (36→37) taken 5 times.
✓ Branch 10 (37→38) taken 5 times.
✓ Branch 12 (38→39) taken 5 times.
✓ Branch 14 (39→40) taken 5 times.
5 PPath outputCurrentTestDir = projectParam.outputTestDir / PPath("TEST_" + config.getFileName().getFileName().eraseExtension().toUpper());
502
4/4
✓ Branch 0 (45→46) taken 5 times.
✓ Branch 2 (46→47) taken 5 times.
✓ Branch 4 (47→48) taken 5 times.
✓ Branch 6 (48→49) taken 5 times.
5 cmakeListBody += "add_subdirectory(" + outputCurrentTestDir.getFileName() + ")\n";
503
3/4
✓ Branch 0 (52→53) taken 5 times.
✓ Branch 2 (53→54) taken 5 times.
✗ Branch 4 (54→55) not taken.
✓ Branch 5 (54→66) taken 5 times.
5 if(!generator_class_cpp_test(manager, outputCurrentTestDir, config.getVecClassConfig(), projectParam.name, baseFileName, projectParam.mode)){
504 std::cerr << termRed() << "generator_class_full : cannot generate C++ tests at '"<<projectParam.outputTestDir<<"'" << termDefault() << std::endl;
505 b = false; //best effort strategy
506 }
507 5 }
508
1/1
✓ Branch 0 (78→79) taken 3 times.
3 cmakeListBody += "\n\n";
509
3/3
✓ Branch 0 (79→80) taken 3 times.
✓ Branch 2 (80→81) taken 3 times.
✓ Branch 4 (81→82) taken 3 times.
3 PPath cmakelist(projectParam.outputTestDir / PPath("CMakeLists.txt"));
510
1/1
✓ Branch 0 (84→85) taken 3 times.
3 b &= cmakelist.saveFileContent(cmakeListBody);
511 3 return b;
512 3 }
513
514
515
516
517