GCC Code Coverage Report


Directory: ./
File: src/TraitBackEnd/CPP/CppTraitConfigStream/CppTraitConfigStream.cpp
Date: 2026-10-16 17:52:29
Exec Total Coverage
Lines: 63 64 98.4%
Functions: 12 12 100.0%
Branches: 130 137 94.9%

Line Branch Exec Source
1
2 /***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : LGPL-3.0-only
6 ****************************************/
7
8 #include "type_utils.h"
9 #include "CppTraitConfigStream.h"
10
11 ///Consctructor of CppTraitConfigStream
12 4 CppTraitConfigStream::CppTraitConfigStream()
13 4 :PAbstractTraitBackend()
14 4 {}
15
16 ///Desctructor of CppTraitConfigStream
17 8 CppTraitConfigStream::~CppTraitConfigStream(){}
18
19 ///Add extra include on the header
20 /** @param[out] fs : file to be completed
21 * @param mode : mode of the generator
22 */
23 6 void CppTraitConfigStream::headerExtraInclude(std::ofstream & fs, const GeneratorMode & mode) const{
24
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 6 times.
6 if(!mode.enableConfigStream){return;}
25 6 fs << "#include \"phoenix_config_stream.h\"" << std::endl;
26 }
27
28 ///Declaration of public methods
29 /** @param[out] fs : file to be completed
30 * @param classConfig : PClassConfig to be used
31 * @param mode : mode of the generator
32 */
33 7 void CppTraitConfigStream::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
34
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 7 times.
7 if(!mode.enableConfigStream){return;}
35
36 }
37
38 ///Implementation of public methods
39 /** @param[out] fs : file to be completed
40 * @param classConfig : PClassConfig to be used
41 * @param mode : mode of the generator
42 */
43 10 void CppTraitConfigStream::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
44
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 10 times.
10 if(!mode.enableConfigStream){return;}
45
46 }
47
48 ///Declaration of protected methods
49 /** @param[out] fs : file to be completed
50 * @param classConfig : PClassConfig to be used
51 * @param mode : mode of the generator
52 */
53 7 void CppTraitConfigStream::protectedMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
54
55 7 }
56
57 ///Implementation of protected methods
58 /** @param[out] fs : file to be completed
59 * @param classConfig : PClassConfig to be used
60 * @param mode : mode of the generator
61 */
62 10 void CppTraitConfigStream::protectedMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
63
64 10 }
65
66 ///Declaration of private methods
67 /** @param[out] fs : file to be completed
68 * @param classConfig : PClassConfig to be used
69 * @param mode : mode of the generator
70 */
71 7 void CppTraitConfigStream::privateMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
72
73 7 }
74
75 ///Implementation of private methods
76 /** @param[out] fs : file to be completed
77 * @param classConfig : PClassConfig to be used
78 * @param mode : mode of the generator
79 */
80 10 void CppTraitConfigStream::privateMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
81
82 10 }
83
84 ///Declaration of extra functions
85 /** @param[out] fs : file to be completed
86 * @param classConfig : PClassConfig to be used
87 * @param mode : mode of the generator
88 */
89 10 void CppTraitConfigStream::classExtraFunctionDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
90
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 10 times.
10 if(!mode.enableConfigStream){return;}
91
2/2
✓ Branch 0 (4→5) taken 10 times.
✓ Branch 2 (5→6) taken 10 times.
10 PString name(classConfig.getName());
92
3/3
✓ Branch 0 (6→7) taken 10 times.
✓ Branch 2 (7→8) taken 3 times.
✓ Branch 3 (7→14) taken 7 times.
10 if(classConfig.getIsEnum()){
93
3/3
✓ Branch 0 (8→9) taken 3 times.
✓ Branch 2 (9→10) taken 3 times.
✓ Branch 4 (10→11) taken 3 times.
3 name = name + "::" + name;
94 }
95
2/2
✓ Branch 0 (14→15) taken 10 times.
✓ Branch 2 (15→16) taken 10 times.
10 fs << "template<>" << std::endl;
96
7/7
✓ Branch 0 (16→17) taken 10 times.
✓ Branch 2 (17→18) taken 10 times.
✓ Branch 4 (18→19) taken 10 times.
✓ Branch 6 (19→20) taken 10 times.
✓ Branch 8 (20→21) taken 10 times.
✓ Branch 10 (21→22) taken 10 times.
✓ Branch 12 (22→23) taken 10 times.
10 fs << "bool phoenix_config_stream<"<<name<<">(ConfigNodeIter & iter, "<<name<<" & data, const GenericConfigCheck * checker);" << std::endl << std::endl;
97 10 }
98
99 ///Implementation of extra functions
100 /** @param[out] fs : file to be completed
101 * @param classConfig : PClassConfig to be used
102 * @param mode : mode of the generator
103 */
104 10 void CppTraitConfigStream::classExtraFunctionImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
105
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 10 times.
10 if(!mode.enableConfigStream){return;}
106
107
2/2
✓ Branch 0 (4→5) taken 10 times.
✓ Branch 2 (5→6) taken 10 times.
10 PString name(classConfig.getName());
108 // PString fullName(classConfig.getFullName());
109
4/4
✓ Branch 0 (6→7) taken 10 times.
✓ Branch 2 (7→8) taken 10 times.
✓ Branch 4 (8→9) taken 10 times.
✓ Branch 6 (9→10) taken 10 times.
10 fs << "///Load and save the given " << name << " depending on the ConfigNodeIter mode (interface with PhoenixConfigStream)" << std::endl;
110
2/2
✓ Branch 0 (10→11) taken 10 times.
✓ Branch 2 (11→12) taken 10 times.
10 fs << "/**\t@param[out] iter : ConfigNodeIter to be used to load and save the configuration" << std::endl;
111
4/4
✓ Branch 0 (12→13) taken 10 times.
✓ Branch 2 (13→14) taken 10 times.
✓ Branch 4 (14→15) taken 10 times.
✓ Branch 6 (15→16) taken 10 times.
10 fs << " * \t@param[out] data : " << name << " to load or save" << std::endl;
112
4/4
✓ Branch 0 (16→17) taken 10 times.
✓ Branch 2 (17→18) taken 10 times.
✓ Branch 4 (18→19) taken 10 times.
✓ Branch 6 (19→20) taken 10 times.
10 fs << " * \t@param checker : check caracteristics of the given " << name << " (eg: boundaries or size)" << std::endl;
113
2/2
✓ Branch 0 (20→21) taken 10 times.
✓ Branch 2 (21→22) taken 10 times.
10 fs << " * \t@return true on success, false otherwise" << std::endl;
114
2/2
✓ Branch 0 (22→23) taken 10 times.
✓ Branch 2 (23→24) taken 10 times.
10 fs << "*/" << std::endl;
115
1/1
✓ Branch 0 (24→25) taken 10 times.
10 const PVecString & listTemplate = classConfig.getListTemplate();
116
1/2
✓ Branch 0 (26→27) taken 10 times.
✗ Branch 1 (26→29) not taken.
10 if(listTemplate.size() == 0LU){
117
2/2
✓ Branch 0 (27→28) taken 10 times.
✓ Branch 2 (28→30) taken 10 times.
10 fs << "template<>" << std::endl;
118 }else{
119 ✗ fs << mode.templateDeclaration;
120 }
121
3/3
✓ Branch 0 (30→31) taken 10 times.
✓ Branch 2 (31→32) taken 3 times.
✓ Branch 3 (31→38) taken 7 times.
10 if(classConfig.getIsEnum()){
122
3/3
✓ Branch 0 (32→33) taken 3 times.
✓ Branch 2 (33→34) taken 3 times.
✓ Branch 4 (34→35) taken 3 times.
3 name = name + "::" + name;
123 }
124
125
8/8
✓ Branch 0 (38→39) taken 10 times.
✓ Branch 2 (39→40) taken 10 times.
✓ Branch 4 (40→41) taken 10 times.
✓ Branch 6 (41→42) taken 10 times.
✓ Branch 8 (42→43) taken 10 times.
✓ Branch 10 (43→44) taken 10 times.
✓ Branch 12 (44→45) taken 10 times.
✓ Branch 14 (45→46) taken 10 times.
10 fs << "bool phoenix_config_stream<"<<name << mode.defTemplate<<">(ConfigNodeIter & iter, "<<name << mode.defTemplate<<" & data, const GenericConfigCheck * checker){" << std::endl;
126
2/2
✓ Branch 0 (46→47) taken 10 times.
✓ Branch 2 (47→48) taken 10 times.
10 fs << "\tbool b(true);" << std::endl;
127
3/3
✓ Branch 0 (48→49) taken 10 times.
✓ Branch 2 (49→50) taken 3 times.
✓ Branch 3 (49→65) taken 7 times.
10 if(classConfig.getIsEnum()){
128
2/2
✓ Branch 0 (50→51) taken 3 times.
✓ Branch 2 (51→52) taken 3 times.
3 fs << "\tPString value = iter->getString();" << std::endl;
129
2/2
✓ Branch 0 (52→53) taken 3 times.
✓ Branch 2 (53→54) taken 3 times.
3 fs << "\tif(!fromString(data, value)){" << std::endl;
130
7/7
✓ Branch 0 (54→55) taken 3 times.
✓ Branch 2 (55→56) taken 3 times.
✓ Branch 4 (56→57) taken 3 times.
✓ Branch 6 (57→58) taken 3 times.
✓ Branch 8 (58→59) taken 3 times.
✓ Branch 10 (59→60) taken 3 times.
✓ Branch 12 (60→61) taken 3 times.
3 fs << "\t\t*iter.getOut() << \"phoenix_config_stream<"<<name << mode.defTemplate<<"> : cannot load enum '"<<name<<"' with value '\"<<value<<\"'\" << std::endl;" << std::endl;
131
2/2
✓ Branch 0 (61→62) taken 3 times.
✓ Branch 2 (62→63) taken 3 times.
3 fs << "\t\tb = false;" << std::endl;
132
2/2
✓ Branch 0 (63→64) taken 3 times.
✓ Branch 2 (64→138) taken 3 times.
3 fs << "\t}" << std::endl;
133 }else{
134
1/1
✓ Branch 0 (65→66) taken 7 times.
7 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
135
2/2
✓ Branch 0 (136→67) taken 19 times.
✓ Branch 1 (136→137) taken 7 times.
52 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
136 //TODO : add a call to the ConfigCheck when it will be available in the pdata
137
4/4
✓ Branch 0 (69→70) taken 19 times.
✓ Branch 2 (70→71) taken 19 times.
✓ Branch 4 (73→74) taken 19 times.
✓ Branch 6 (74→75) taken 19 times.
57 PString attrName(it->getName().firstToUpper()), attrKey(it->getName().toSnakeCase());
138
4/4
✓ Branch 0 (77→78) taken 19 times.
✓ Branch 2 (78→79) taken 19 times.
✓ Branch 4 (79→80) taken 1 times.
✓ Branch 5 (79→113) taken 18 times.
19 if(getIsPointerType(it->getType())){
139 //phoenix_config_stream has a dedicated overload for T*& : go through a local variable since the getter returns the pointer by value, not by reference
140
5/5
✓ Branch 0 (82→83) taken 1 times.
✓ Branch 2 (83→84) taken 1 times.
✓ Branch 4 (84→85) taken 1 times.
✓ Branch 6 (88→89) taken 1 times.
✓ Branch 8 (89→90) taken 1 times.
3 PString pointeeType(it->getType().eraseFirstLastChar(" \n\t*")), localVar(it->getName().toSnakeCase());
141
8/8
✓ Branch 0 (90→91) taken 1 times.
✓ Branch 2 (91→92) taken 1 times.
✓ Branch 4 (92→93) taken 1 times.
✓ Branch 6 (93→94) taken 1 times.
✓ Branch 8 (94→95) taken 1 times.
✓ Branch 10 (95→96) taken 1 times.
✓ Branch 12 (96→97) taken 1 times.
✓ Branch 14 (97→98) taken 1 times.
1 fs << "\t" << pointeeType << " * " << localVar << "(data.get" << attrName << "());" << std::endl;
142
6/6
✓ Branch 0 (98→99) taken 1 times.
✓ Branch 2 (99→100) taken 1 times.
✓ Branch 4 (100→101) taken 1 times.
✓ Branch 6 (101→102) taken 1 times.
✓ Branch 8 (102→103) taken 1 times.
✓ Branch 10 (103→104) taken 1 times.
1 fs << "\tb &= phoenix_config_stream(iter, " << localVar << ", \"" << attrKey << "\", checker);" << std::endl;
143
6/6
✓ Branch 0 (104→105) taken 1 times.
✓ Branch 2 (105→106) taken 1 times.
✓ Branch 4 (106→107) taken 1 times.
✓ Branch 6 (107→108) taken 1 times.
✓ Branch 8 (108→109) taken 1 times.
✓ Branch 10 (109→110) taken 1 times.
1 fs << "\tdata.set" << attrName << "(" << localVar << ");" << std::endl;
144 1 }else{
145
9/9
✓ Branch 0 (113→114) taken 18 times.
✓ Branch 2 (116→117) taken 18 times.
✓ Branch 4 (117→118) taken 18 times.
✓ Branch 6 (118→119) taken 18 times.
✓ Branch 8 (119→120) taken 18 times.
✓ Branch 10 (120→121) taken 18 times.
✓ Branch 12 (121→122) taken 18 times.
✓ Branch 14 (122→123) taken 18 times.
✓ Branch 16 (123→124) taken 18 times.
36 fs << "\tb &= phoenix_config_stream<"<<it->getType()<<">(iter, data.get"<<attrName<<"(), \""<<attrKey<<"\", checker);" << std::endl;
146 }
147 19 }
148 }
149
2/2
✓ Branch 0 (138→139) taken 10 times.
✓ Branch 2 (139→140) taken 10 times.
10 fs << "\treturn b;" << std::endl;
150
3/3
✓ Branch 0 (140→141) taken 10 times.
✓ Branch 2 (141→142) taken 10 times.
✓ Branch 4 (142→143) taken 10 times.
10 fs << "}" << std::endl << std::endl;
151 10 }
152
153
154
155
156