GCC Code Coverage Report


Directory: ./
File: src/TraitBackEnd/CPP/CppTraitDataStream/CppTraitDataStream.cpp
Date: 2026-10-16 17:52:29
Exec Total Coverage
Lines: 73 74 98.6%
Functions: 12 12 100.0%
Branches: 102 115 88.7%

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 "CppTraitDataStream.h"
10
11 ///Consctructor of CppTraitDataStream
12 4 CppTraitDataStream::CppTraitDataStream()
13 4 :PAbstractTraitBackend()
14 4 {}
15
16 ///Desctructor of CppTraitDataStream
17 8 CppTraitDataStream::~CppTraitDataStream(){}
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 CppTraitDataStream::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.enableDataStream){return;}
25 6 fs << "#include <array>" << std::endl;
26 6 fs << "#include <algorithm>" << std::endl;
27 6 fs << "#include \"phoenix_data_stream.h\"" << std::endl;
28 }
29
30 ///Declaration of public methods
31 /** @param[out] fs : file to be completed
32 * @param classConfig : PClassConfig to be used
33 * @param mode : mode of the generator
34 */
35 7 void CppTraitDataStream::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
36
4/7
✓ Branch 0 (2→3) taken 7 times.
✗ Branch 1 (2→5) not taken.
✓ Branch 2 (3→4) taken 7 times.
✗ Branch 4 (4→5) not taken.
✓ Branch 5 (4→6) taken 7 times.
✗ Branch 6 (7→8) not taken.
✓ Branch 7 (7→9) taken 7 times.
7 if(!mode.enableDataStream || classConfig.getIsEnum()){return;}
37
2/2
✓ Branch 0 (9→10) taken 7 times.
✓ Branch 2 (10→11) taken 7 times.
7 PString name(classConfig.getName());
38
1/1
✓ Branch 0 (11→12) taken 7 times.
7 fs << std::endl;
39
4/4
✓ Branch 0 (12→13) taken 7 times.
✓ Branch 2 (13→14) taken 7 times.
✓ Branch 4 (14→15) taken 7 times.
✓ Branch 6 (15→16) taken 7 times.
7 fs << "\t\t///Load the current "<<name<<" with a stream" << std::endl;
40
2/2
✓ Branch 0 (16→17) taken 7 times.
✓ Branch 2 (17→18) taken 7 times.
7 fs << "\t\t/** @param[out] ds : stream to be used" << std::endl;
41
2/2
✓ Branch 0 (18→19) taken 7 times.
✓ Branch 2 (19→20) taken 7 times.
7 fs << "\t\t * @return true on success, false otherwise" << std::endl;
42
2/2
✓ Branch 0 (20→21) taken 7 times.
✓ Branch 2 (21→22) taken 7 times.
7 fs << "\t\t*/" << std::endl;
43
2/2
✓ Branch 0 (22→23) taken 7 times.
✓ Branch 2 (23→24) taken 7 times.
7 fs << "\t\ttemplate<typename Stream, DataStreamMode::DataStreamMode Mode>" << std::endl;
44
2/2
✓ Branch 0 (24→25) taken 7 times.
✓ Branch 2 (25→26) taken 7 times.
7 fs << "\t\tbool readWriteStream(Stream & ds){" << std::endl;
45
46
1/1
✓ Branch 0 (26→27) taken 7 times.
7 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
47
1/2
✗ Branch 0 (28→29) not taken.
✓ Branch 1 (28→31) taken 7 times.
7 if(vecAttr.size() == 0lu){
48 ✗ fs << "\t\t\treturn true;" << std::endl;
49 }else{
50 //Neither "b = f() && b" (each && counts toward SonarQube's cognitive complexity) nor "b &= f()" (SonarQube flags bitwise ops on bool) scale to many attributes.
51 //Collecting every (always-evaluated, no short-circuit) result in an array and reducing it with a single std::all_of keeps cognitive complexity constant regardless of attribute count.
52
4/4
✓ Branch 0 (31→32) taken 7 times.
✓ Branch 2 (33→34) taken 7 times.
✓ Branch 4 (34→35) taken 7 times.
✓ Branch 6 (35→36) taken 7 times.
7 fs << "\t\t\tconst std::array<bool, " << vecAttr.size() << "> vecIsOk{" << std::endl;
53
1/1
✓ Branch 0 (36→37) taken 7 times.
7 PString separator("\t\t\t\t");
54
2/2
✓ Branch 0 (56→38) taken 19 times.
✓ Branch 1 (56→57) taken 7 times.
52 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
55
5/5
✓ Branch 0 (38→39) taken 19 times.
✓ Branch 2 (39→40) taken 19 times.
✓ Branch 4 (42→43) taken 19 times.
✓ Branch 6 (43→44) taken 19 times.
✓ Branch 8 (44→45) taken 19 times.
38 fs << separator << "streamAttribute<Stream, Mode>(ds, p_" << it->getName() << ")";
56
1/1
✓ Branch 0 (45→46) taken 19 times.
19 separator = ",\n\t\t\t\t";
57 }
58
3/3
✓ Branch 0 (57→58) taken 7 times.
✓ Branch 2 (58→59) taken 7 times.
✓ Branch 4 (59→60) taken 7 times.
7 fs << std::endl << "\t\t\t};" << std::endl;
59
2/2
✓ Branch 0 (60→61) taken 7 times.
✓ Branch 2 (61→62) taken 7 times.
7 fs << "\t\t\treturn std::all_of(vecIsOk.begin(), vecIsOk.end(), [](bool isOk){return isOk;});" << std::endl;
60 7 }
61
3/3
✓ Branch 0 (64→65) taken 7 times.
✓ Branch 2 (65→66) taken 7 times.
✓ Branch 4 (66→67) taken 7 times.
7 fs << "\t\t}" << std::endl << std::endl;
62 7 }
63
64 ///Implementation of public methods
65 /** @param[out] fs : file to be completed
66 * @param classConfig : PClassConfig to be used
67 * @param mode : mode of the generator
68 */
69 10 void CppTraitDataStream::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
70
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 10 times.
10 if(!mode.enableDataStream){return;}
71
72 }
73
74 ///Declaration of protected methods
75 /** @param[out] fs : file to be completed
76 * @param classConfig : PClassConfig to be used
77 * @param mode : mode of the generator
78 */
79 7 void CppTraitDataStream::protectedMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
80
3/6
✓ Branch 0 (2→3) taken 7 times.
✗ Branch 1 (2→5) not taken.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→6) taken 7 times.
✗ Branch 4 (7→8) not taken.
✓ Branch 5 (7→9) taken 7 times.
7 if(!mode.enableDataStream || classConfig.getIsEnum()){return;}
81 7 fs << std::endl;
82 7 fs << "\t\t///Streams a single attribute" << std::endl;
83 7 fs << "\t\t/** @param[out] ds : stream to be used" << std::endl;
84 7 fs << "\t\t * @param data : attribute to be streamed" << std::endl;
85 7 fs << "\t\t * @return true on success, false otherwise" << std::endl;
86 7 fs << "\t\t*/" << std::endl;
87 7 fs << "\t\ttemplate<typename Stream, DataStreamMode::DataStreamMode Mode, typename T>" << std::endl;
88 7 fs << "\t\tstatic bool streamAttribute(Stream & ds, T & data){" << std::endl;
89 7 fs << "\t\t\treturn DataStream<Stream, Mode, T>::data_stream(ds, data);" << std::endl;
90 7 fs << "\t\t}" << std::endl << std::endl;
91 }
92
93 ///Implementation of protected methods
94 /** @param[out] fs : file to be completed
95 * @param classConfig : PClassConfig to be used
96 * @param mode : mode of the generator
97 */
98 10 void CppTraitDataStream::protectedMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
99
100 10 }
101
102 ///Declaration of private methods
103 /** @param[out] fs : file to be completed
104 * @param classConfig : PClassConfig to be used
105 * @param mode : mode of the generator
106 */
107 7 void CppTraitDataStream::privateMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
108
109 7 }
110
111 ///Implementation of private methods
112 /** @param[out] fs : file to be completed
113 * @param classConfig : PClassConfig to be used
114 * @param mode : mode of the generator
115 */
116 10 void CppTraitDataStream::privateMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
117
118 10 }
119
120 ///Declaration of extra functions
121 /** @param[out] fs : file to be completed
122 * @param classConfig : PClassConfig to be used
123 * @param mode : mode of the generator
124 */
125 10 void CppTraitDataStream::classExtraFunctionDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
126
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 10 times.
13 if(!mode.enableDataStream){return;}
127
2/2
✓ Branch 0 (4→5) taken 10 times.
✓ Branch 2 (5→6) taken 10 times.
10 PString name(classConfig.getName());
128
1/1
✓ Branch 0 (6→7) taken 10 times.
10 PString fullName(classConfig.getFullName());
129
3/3
✓ Branch 0 (7→8) taken 10 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 3 (8→17) taken 7 times.
10 if(classConfig.getIsEnum()){
130
7/7
✓ Branch 0 (9→10) taken 3 times.
✓ Branch 2 (10→11) taken 3 times.
✓ Branch 4 (11→12) taken 3 times.
✓ Branch 6 (12→13) taken 3 times.
✓ Branch 8 (13→14) taken 3 times.
✓ Branch 10 (14→15) taken 3 times.
✓ Branch 12 (15→16) taken 3 times.
3 fs << "PHOENIX_DATA_STREAM_ENUM("<<name<<"::"<<name<<")" << std::endl << std::endl;
131 3 return;
132 }
133
4/4
✓ Branch 0 (17→18) taken 7 times.
✓ Branch 2 (18→19) taken 7 times.
✓ Branch 4 (19→20) taken 7 times.
✓ Branch 6 (20→21) taken 7 times.
7 fs << "///@brief Generic "<<name<<" serialisation/deserialisation, load/save and size function for PhoenixDataStream" << std::endl;
134
2/2
✓ Branch 0 (21→22) taken 7 times.
✓ Branch 2 (22→23) taken 7 times.
7 fs << "template<typename Stream, DataStreamMode::DataStreamMode Mode>" << std::endl;
135
4/4
✓ Branch 0 (23→24) taken 7 times.
✓ Branch 2 (24→25) taken 7 times.
✓ Branch 4 (25→26) taken 7 times.
✓ Branch 6 (26→27) taken 7 times.
7 fs << "struct DataStream<Stream, Mode, "<<fullName<<">{" << std::endl;
136
3/3
✓ Branch 0 (27→28) taken 7 times.
✓ Branch 2 (28→29) taken 7 times.
✓ Branch 4 (29→30) taken 7 times.
7 fs << "\t///Generic function to load/save/serialise/deserialise "<<name << std::endl;
137
2/2
✓ Branch 0 (30→31) taken 7 times.
✓ Branch 2 (31→32) taken 7 times.
7 fs << "\t/**\t@param[out] ds : stream to be used" << std::endl;
138
4/4
✓ Branch 0 (32→33) taken 7 times.
✓ Branch 2 (33→34) taken 7 times.
✓ Branch 4 (34→35) taken 7 times.
✓ Branch 6 (35→36) taken 7 times.
7 fs << "\t * \t@param data : "<<name<<" to be used" << std::endl;
139
2/2
✓ Branch 0 (36→37) taken 7 times.
✓ Branch 2 (37→38) taken 7 times.
7 fs << "\t * \t@return true on success, false otherwise" << std::endl;
140
2/2
✓ Branch 0 (38→39) taken 7 times.
✓ Branch 2 (39→40) taken 7 times.
7 fs << "\t*/" << std::endl;
141
4/4
✓ Branch 0 (40→41) taken 7 times.
✓ Branch 2 (41→42) taken 7 times.
✓ Branch 4 (42→43) taken 7 times.
✓ Branch 6 (43→44) taken 7 times.
7 fs << "\tstatic bool data_stream(Stream & ds, "<<fullName<<" & data){" << std::endl;
142
2/2
✓ Branch 0 (44→45) taken 7 times.
✓ Branch 2 (45→46) taken 7 times.
7 fs << "\t\treturn data.readWriteStream<Stream, Mode>(ds);" << std::endl;
143
2/2
✓ Branch 0 (46→47) taken 7 times.
✓ Branch 2 (47→48) taken 7 times.
7 fs << "\t}" << std::endl;
144
3/3
✓ Branch 0 (48→49) taken 7 times.
✓ Branch 2 (49→50) taken 7 times.
✓ Branch 4 (50→51) taken 7 times.
7 fs << "};" << std::endl << std::endl;
145
4/4
✓ Branch 0 (53→54) taken 7 times.
✓ Branch 1 (53→55) taken 3 times.
✓ Branch 2 (58→59) taken 7 times.
✓ Branch 3 (58→61) taken 3 times.
20 }
146
147 ///Implementation of extra functions
148 /** @param[out] fs : file to be completed
149 * @param classConfig : PClassConfig to be used
150 * @param mode : mode of the generator
151 */
152 10 void CppTraitDataStream::classExtraFunctionImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
153
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 10 times.
10 if(!mode.enableDataStream){return;}
154
155 }
156
157
158
159
160