GCC Code Coverage Report


Directory: ./
File: src/TraitBackEnd/PythonWrapper/WrapperTraitDataStream/WrapperTraitDataStream.cpp
Date: 2025-12-15 11:32:44
Exec Total Coverage
Lines: 301 443 67.9%
Functions: 22 23 95.7%
Branches: 543 899 60.4%

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 "WrapperTraitDataStream.h"
9
10 ///Do the check call of an attribute of a given class
11 /** @param[out] fs : file to be completed
12 * @param className : name of the class the attribute belongs to
13 * @param attr : class attribute to be checked
14 * @param moduleName : name of the module where the class should be defined
15 * @param expectedType : expected type by respected to the configuration .pdata
16 */
17 2 void data_stream_trait_wrapper_callAttributeCheck(std::ofstream & fs, const PString & className, const PClassAttribute & attr, const PString & moduleName, const PString & expectedType){
18
4/4
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 2 (3→4) taken 2 times.
✓ Branch 4 (4→5) taken 2 times.
✓ Branch 6 (5→6) taken 2 times.
2 PString attrType(attr.getType()), attrName(attr.getName());
19
2/2
✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
2 PString typeNameVar(attrName+"Name");
20
5/5
✓ Branch 0 (9→10) taken 2 times.
✓ Branch 2 (10→11) taken 2 times.
✓ Branch 4 (11→12) taken 2 times.
✓ Branch 6 (12→13) taken 2 times.
✓ Branch 8 (13→14) taken 2 times.
2 fs << "\tstd::string "+typeNameVar+"(_PyType_Name(Py_TYPE(obj."+attrName+")));\n";
21
5/5
✓ Branch 0 (18→19) taken 2 times.
✓ Branch 2 (19→20) taken 2 times.
✓ Branch 4 (20→21) taken 2 times.
✓ Branch 6 (21→22) taken 2 times.
✓ Branch 8 (22→23) taken 2 times.
2 fs << "\tif("+typeNameVar+" != \""+expectedType+"\"){\n";
22
9/9
✓ Branch 0 (27→28) taken 2 times.
✓ Branch 2 (28→29) taken 2 times.
✓ Branch 4 (29→30) taken 2 times.
✓ Branch 6 (30→31) taken 2 times.
✓ Branch 8 (31→32) taken 2 times.
✓ Branch 10 (32→33) taken 2 times.
✓ Branch 12 (33→34) taken 2 times.
✓ Branch 14 (34→35) taken 2 times.
✓ Branch 16 (35→36) taken 2 times.
2 fs << "\t\terror << \"- Type of attribute "+className+"::"+attrName+" is '\"<<"+typeNameVar+"<<\"' and not expected '"+expectedType+"'\\n\";\n";
23
1/1
✓ Branch 0 (44→45) taken 2 times.
2 fs << "\t\tb = false;\n";
24
1/1
✓ Branch 0 (45→46) taken 2 times.
2 fs << "\t}\n";
25 2 }
26
27 ///Do the check implementation of class
28 /** @param[out] fs : file to be completed
29 * @param classConfig : class configuration
30 * @param moduleName : name of the module where the class should be defined
31 */
32 3 void data_stream_trait_wrapper_classImplCheck(std::ofstream & fs, const PClassConfig & classConfig, const PString & moduleName){
33
1/1
✓ Branch 0 (2→3) taken 3 times.
3 PString className(wrapper_getClassName(classConfig));
34
3/3
✓ Branch 0 (3→4) taken 3 times.
✓ Branch 2 (4→5) taken 3 times.
✓ Branch 4 (5→6) taken 3 times.
3 fs << "///Check if the "+className+" contains all the expected types\n";
35
1/1
✓ Branch 0 (8→9) taken 3 times.
3 fs << "/**\t@param[out] error : error to be set if there is one\n";
36
3/3
✓ Branch 0 (9→10) taken 3 times.
✓ Branch 2 (10→11) taken 3 times.
✓ Branch 4 (11→12) taken 3 times.
3 fs << " * \t@param obj : reference to the "+className+"\n";
37
3/3
✓ Branch 0 (14→15) taken 3 times.
✓ Branch 2 (15→16) taken 3 times.
✓ Branch 4 (16→17) taken 3 times.
3 fs << " * \t@return true if the class "+className+" contains expected types, false otherwise\n";
38
1/1
✓ Branch 0 (19→20) taken 3 times.
3 fs << "*/\n";
39
5/5
✓ Branch 0 (20→21) taken 3 times.
✓ Branch 2 (21→22) taken 3 times.
✓ Branch 4 (22→23) taken 3 times.
✓ Branch 6 (23→24) taken 3 times.
✓ Branch 8 (24→25) taken 3 times.
3 fs << "bool "+className+"_check(std::stringstream & error, const "+className+" & obj){\n";
40
1/1
✓ Branch 0 (29→30) taken 3 times.
3 fs << "\tbool b(true);\n";
41
2/3
✓ Branch 0 (30→31) taken 3 times.
✗ Branch 2 (31→32) not taken.
✓ Branch 3 (31→36) taken 3 times.
3 if(classConfig.getIsEnum()){
42 fs << "\t//TODO : WrapperTraitDataStream data_stream_trait_wrapper_classImplCheck not implemented for enum" << std::endl;
43 std::cerr << "\t//TODO : WrapperTraitDataStream data_stream_trait_wrapper_classImplCheck not implemented for enum" << std::endl;
44 }else{
45
1/1
✓ Branch 0 (36→37) taken 3 times.
3 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
46
2/2
✓ Branch 0 (185→38) taken 5 times.
✓ Branch 1 (185→186) taken 3 times.
16 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
47
2/2
✓ Branch 0 (40→41) taken 5 times.
✓ Branch 2 (41→42) taken 5 times.
5 PString attrType(it->getType());
48
3/3
✓ Branch 0 (42→43) taken 5 times.
✓ Branch 2 (43→44) taken 3 times.
✓ Branch 3 (43→45) taken 2 times.
5 if(getIsSimpleType(attrType)){
49 3 continue;
50 }
51
2/2
✓ Branch 0 (47→48) taken 2 times.
✓ Branch 2 (48→49) taken 2 times.
2 PString attrName(it->getName());
52
5/5
✓ Branch 0 (49→50) taken 2 times.
✓ Branch 2 (50→51) taken 2 times.
✓ Branch 4 (51→52) taken 2 times.
✓ Branch 6 (52→53) taken 2 times.
✓ Branch 8 (53→54) taken 2 times.
2 fs << "\t//Check of the attribute "+attrName+" of type "+attrType+"\n";
53
2/3
✓ Branch 0 (58→59) taken 2 times.
✓ Branch 2 (59→60) taken 2 times.
✗ Branch 3 (59→66) not taken.
2 if(attrType == "std::string"){
54
2/2
✓ Branch 0 (60→61) taken 2 times.
✓ Branch 2 (63→64) taken 2 times.
4 data_stream_trait_wrapper_callAttributeCheck(fs, className, *it, moduleName, "str");
55 }else if(attrType == "DataStreamMsg"){
56 data_stream_trait_wrapper_callAttributeCheck(fs, className, *it, moduleName, "bytearray");
57 }else if(generator_typeIsList(attrType)){
58 PString nestedType(generator_getListNestedType(attrType));
59 data_stream_trait_wrapper_callAttributeCheck(fs, className, *it, moduleName, "list");
60 fs << "\t//Now we have to check all elements of "+attrName+"\n";
61 fs << "\tif(b){\t//If obj."+attrName+" is not a list we will have a problem\n";
62 fs << "\t\tfor(long i(0l); i < PyList_Size(obj."+attrName+"); ++i){\n";
63 fs << "\t\t\tPyObject * el = PyList_GET_ITEM(obj."+attrName+", i);\n";
64 fs << "\t\t\tstd::string elType(_PyType_Name(Py_TYPE(el)));\n";
65 PString expectedType(moduleName + "." + nestedType);
66 if(getIsSimpleType(nestedType)){
67 expectedType = wrapper_getExpectedType(nestedType);
68 }else{
69 fs << "\t\t\t//TODO : For some reason python and ipython agree to tell type("+nestedType+") is "+expectedType+" but during my test I get "+nestedType+" so I add it but I don't know why\n";
70 }
71 fs << "\t\t\tif(elType != \""+expectedType+"\" && elType != \""+nestedType+"\"){\n";
72 fs << "\t\t\t\terror << \"- Type of element "+className+"::"+attrName+"[\"<<i<<\"] is '\"+elType+\"' and not expected '"+expectedType+"'\\n\";\n";
73 fs << "\t\t\t\tb = false;\n";
74 fs << "\t\t\t}\n";
75 fs << "\t\t}\n";
76 fs << "\t}\n";
77 }else if(it->getIsEnum()){
78 fs << "\t//Let's check the enum\n";
79 data_stream_trait_wrapper_callAttributeCheck(fs, className, *it, moduleName, it->getType());
80 }
81 5 }
82 }
83
1/1
✓ Branch 0 (187→188) taken 3 times.
3 fs << "\treturn b;\n";
84
1/1
✓ Branch 0 (188→189) taken 3 times.
3 fs << "}\n\n";
85 3 }
86
87 ///Do the implementation of data stream method _fromBytes for one class
88 /** @param[out] fs : file to be completed
89 * @param classConfig : class configuration
90 * @param className : name of the current class
91 */
92 3 void data_stream_trait_wrapper_classPythonFromBytes(std::ofstream & fs, const PClassConfig & classConfig, const PString & className){
93
3/3
✓ Branch 0 (2→3) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
✓ Branch 4 (4→5) taken 3 times.
3 fs << "///Initialise a "+className+" with a ByteArray\n";
94
3/3
✓ Branch 0 (7→8) taken 3 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 4 (9→10) taken 3 times.
3 fs << "/**\t@param self : pointer to the "+className+"\n";
95
3/3
✓ Branch 0 (12→13) taken 3 times.
✓ Branch 2 (13→14) taken 3 times.
✓ Branch 4 (14→15) taken 3 times.
3 fs << " * \t@param args : PyByteArray to initialise the "+className+"\n";
96 3 fs << " * \t@return Py_RETURN_NONE\n";
97 3 fs << "*/\n";
98
3/3
✓ Branch 0 (19→20) taken 3 times.
✓ Branch 2 (20→21) taken 3 times.
✓ Branch 4 (21→22) taken 3 times.
3 fs << "PyObject * "+className+"_fromBytes(PyObject *self, PyObject *args){\n";
99
5/5
✓ Branch 0 (24→25) taken 3 times.
✓ Branch 2 (25→26) taken 3 times.
✓ Branch 4 (26→27) taken 3 times.
✓ Branch 6 (27→28) taken 3 times.
✓ Branch 8 (28→29) taken 3 times.
3 fs << "\t"+className+"* obj = ("+className+"*)self;\n";
100 3 fs << "\tPyObject * byteArray = NULL;\n";
101
3/3
✓ Branch 0 (34→35) taken 3 times.
✓ Branch 2 (35→36) taken 3 times.
✓ Branch 4 (36→37) taken 3 times.
3 fs << wrapper_getObjectParseTuple("byteArray");
102 3 fs << "\t//We have to check if byteArray is a 'bytearray'\n";
103 3 fs << "\tstd::string inputTypeName(_PyType_Name(Py_TYPE(byteArray)));\n";
104 3 fs << "\tif(inputTypeName != \"bytearray\"){\n";
105
5/5
✓ Branch 0 (42→43) taken 3 times.
✓ Branch 2 (43→44) taken 3 times.
✓ Branch 4 (44→45) taken 3 times.
✓ Branch 6 (45→46) taken 3 times.
✓ Branch 8 (46→47) taken 3 times.
3 fs << "\t\tstd::string error(\""+className+"_fromBytes : cannot load "+className+" with given '\"+inputTypeName+\"', expecting 'bytearray'\\n\");\n";
106 3 fs << "\t\tPyErr_SetString(PyExc_RuntimeError, error.c_str());\n";
107 3 fs << "\t\treturn NULL;\n";
108 3 fs << "\t}\n";
109 3 fs << "\tsize_t nbByte = PyByteArray_Size(byteArray);\n";
110 3 fs << "\tif(nbByte == 0lu){\n";
111 3 fs << "\t\tPy_RETURN_NONE;\n";
112 3 fs << "\t}\n";
113 3 fs << "\tDataStreamIter iter = (DataStreamIter)PyByteArray_AsString(byteArray);\n";
114
3/3
✓ Branch 0 (59→60) taken 3 times.
✓ Branch 2 (60→61) taken 3 times.
✓ Branch 4 (61→62) taken 3 times.
3 fs << "\tif(!"+className+"_fromMessage(*obj, iter)){\n";
115
5/5
✓ Branch 0 (64→65) taken 3 times.
✓ Branch 2 (65→66) taken 3 times.
✓ Branch 4 (66→67) taken 3 times.
✓ Branch 6 (67→68) taken 3 times.
✓ Branch 8 (68→69) taken 3 times.
3 fs << "\t\tPyErr_SetString(PyExc_RuntimeError, \""+className+"_fromBytes : cannot load "+className+" with given PyByteArray\\n\");\n";
116 3 fs << "\t\treturn NULL;\n";
117 3 fs << "\t}\n";
118 3 fs << "\tPy_RETURN_NONE;\n";
119 3 fs << "}\n\n";
120
121
3/3
✓ Branch 0 (77→78) taken 3 times.
✓ Branch 2 (78→79) taken 3 times.
✓ Branch 4 (79→80) taken 3 times.
3 fs << "///Load a "+className+" from a DataStreamIter\n";
122
3/3
✓ Branch 0 (82→83) taken 3 times.
✓ Branch 2 (83→84) taken 3 times.
✓ Branch 4 (84→85) taken 3 times.
3 fs << "/**\t@param obj : reference to the "+className+"\n";
123 3 fs << " * \t@param iter : DataStreamIter to be used\n";
124 3 fs << " * \t@return true on success, false otherwise\n";
125 3 fs << "*/\n";
126
5/5
✓ Branch 0 (90→91) taken 3 times.
✓ Branch 2 (91→92) taken 3 times.
✓ Branch 4 (92→93) taken 3 times.
✓ Branch 6 (93→94) taken 3 times.
✓ Branch 8 (94→95) taken 3 times.
3 fs << "size_t "+className+"_fromMessage("+className+" & obj, DataStreamIter & iter){\n";
127 3 fs << "\tbool b(true);\n";
128
1/2
✗ Branch 0 (101→102) not taken.
✓ Branch 1 (101→106) taken 3 times.
3 if(classConfig.getIsEnum()){
129 fs << "\t//TODO : WrapperTraitDataStream data_stream_trait_wrapper_classPythonFromBytes to be implemented" << std::endl;
130 std::cerr << "\t//TODO : WrapperTraitDataStream data_stream_trait_wrapper_classPythonFromBytes to be implemented" << std::endl;
131 }else{
132 3 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
133
2/2
✓ Branch 0 (130→108) taken 5 times.
✓ Branch 1 (130→131) taken 3 times.
16 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
134
1/1
✓ Branch 0 (110→111) taken 5 times.
5 const PString & attrName = it->getName();
135
5/5
✓ Branch 0 (111→112) taken 5 times.
✓ Branch 2 (112→113) taken 5 times.
✓ Branch 4 (113→114) taken 5 times.
✓ Branch 6 (114→115) taken 5 times.
✓ Branch 8 (115→116) taken 5 times.
5 fs << "\tb &= "+className+"_"+attrName+"_fromMessage(obj, iter);\n";
136 }
137 }
138 3 fs << "\treturn b;\n";
139 3 fs << "}\n\n";
140 3 }
141
142 ///Call the check of a class
143 /** @param[out] fs : file to be completed
144 * @param className : name of the class to be checked
145 * @param functionName : name of the function where it is called
146 */
147 6 void data_stream_trait_wrapper_classCheckCall(std::ofstream & fs, const PString & className, const PString & functionName){
148 6 fs << "\t//In case of emergency : check the integrity of the types before getting the size of to ensure all attributes have to good type\n";
149 6 fs << "\tstd::stringstream error(\"\");\n";
150
3/3
✓ Branch 0 (4→5) taken 6 times.
✓ Branch 2 (5→6) taken 6 times.
✓ Branch 4 (6→7) taken 6 times.
6 fs << "\tif(!"+className+"_check(error, *obj)){\n";
151
5/5
✓ Branch 0 (9→10) taken 6 times.
✓ Branch 2 (10→11) taken 6 times.
✓ Branch 4 (11→12) taken 6 times.
✓ Branch 6 (12→13) taken 6 times.
✓ Branch 8 (13→14) taken 6 times.
6 fs << "\t\tstd::string errorText(\""+functionName+" : check of class "+className+" failled\\n\" + error.str());\n";
152 6 fs << "\t\tPyErr_SetString(PyExc_RuntimeError, errorText.c_str());\n";
153 6 fs << "\t\treturn NULL;\n";
154 6 fs << "\t}\n";
155 6 }
156
157 ///Do the implementation of data stream method _toBytes for one class
158 /** @param[out] fs : file to be completed
159 * @param classConfig : class configuration
160 * @param className : name of the current class
161 */
162 3 void data_stream_trait_wrapper_classPythonToBytes(std::ofstream & fs, const PClassConfig & classConfig, const PString & className){
163
164
3/3
✓ Branch 0 (2→3) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
✓ Branch 4 (4→5) taken 3 times.
3 fs << "///Convert a "+className+" to a ByteArray\n";
165
3/3
✓ Branch 0 (7→8) taken 3 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 4 (9→10) taken 3 times.
3 fs << "/**\t@param self : pointer to the "+className+"\n";
166 3 fs << " * \t@param args : not used\n";
167
3/3
✓ Branch 0 (13→14) taken 3 times.
✓ Branch 2 (14→15) taken 3 times.
✓ Branch 4 (15→16) taken 3 times.
3 fs << " * \t@return PyByteArray which contains data of the "+className+"\n";
168 3 fs << "*/\n";
169
3/3
✓ Branch 0 (19→20) taken 3 times.
✓ Branch 2 (20→21) taken 3 times.
✓ Branch 4 (21→22) taken 3 times.
3 fs << "PyObject * "+className+"_toBytes(PyObject *self, PyObject *args){\n";
170
5/5
✓ Branch 0 (24→25) taken 3 times.
✓ Branch 2 (25→26) taken 3 times.
✓ Branch 4 (26→27) taken 3 times.
✓ Branch 6 (27→28) taken 3 times.
✓ Branch 8 (28→29) taken 3 times.
3 fs << "\t"+className+"* obj = ("+className+"*)self;\n";
171
3/3
✓ Branch 0 (33→34) taken 3 times.
✓ Branch 2 (34→35) taken 3 times.
✓ Branch 4 (35→36) taken 3 times.
3 data_stream_trait_wrapper_classCheckCall(fs, className, className+"_toBytes");
172
3/3
✓ Branch 0 (38→39) taken 3 times.
✓ Branch 2 (39→40) taken 3 times.
✓ Branch 4 (40→41) taken 3 times.
3 fs << "\tsize_t nbByte = "+className+"_getSize(*obj);\n";
173 3 fs << "\tif(nbByte == 0lu){\n";
174
3/3
✓ Branch 0 (44→45) taken 3 times.
✓ Branch 2 (45→46) taken 3 times.
✓ Branch 4 (46→47) taken 3 times.
3 fs << "\t\tPyErr_SetString(PyExc_RuntimeError, \"data_stream_trait_wrapper_classPythonToBytes : cannot serialise "+className+" of size 0 into a PyByteArray\\n\");\n";
175 3 fs << "\t\treturn NULL;\n";
176 3 fs << "\t}\n";
177 3 fs << "\tDataStreamMsg msg(nbByte);\n";
178 3 fs << "\tDataStreamIter iter = msg.data();\n";
179 3 fs << "\t\n";
180
3/3
✓ Branch 0 (54→55) taken 3 times.
✓ Branch 2 (55→56) taken 3 times.
✓ Branch 4 (56→57) taken 3 times.
3 fs << "\tif(!"+className+"_toMessage(*obj, iter)){\n";
181
3/3
✓ Branch 0 (59→60) taken 3 times.
✓ Branch 2 (60→61) taken 3 times.
✓ Branch 4 (61→62) taken 3 times.
3 fs << "\t\tPyErr_SetString(PyExc_RuntimeError, \"data_stream_trait_wrapper_dataStreamMethod : cannot save "+className+" into a PyByteArray\\n\");\n";
182 3 fs << "\t\treturn NULL;\n";
183 3 fs << "\t}\n";
184 3 fs << "\treturn PyByteArray_FromStringAndSize((const char*)msg.data(), nbByte);\n";
185 3 fs << "}\n\n";
186
187
3/3
✓ Branch 0 (68→69) taken 3 times.
✓ Branch 2 (69→70) taken 3 times.
✓ Branch 4 (70→71) taken 3 times.
3 fs << "///Write a "+className+" in a DataStreamIter\n";
188
3/3
✓ Branch 0 (73→74) taken 3 times.
✓ Branch 2 (74→75) taken 3 times.
✓ Branch 4 (75→76) taken 3 times.
3 fs << "/**\t@param obj : reference to the "+className+"\n";
189 3 fs << " * \t@param iter : DataStreamIter to be used\n";
190 3 fs << " * \t@return true on success, false otherwise\n";
191 3 fs << "*/\n";
192
5/5
✓ Branch 0 (81→82) taken 3 times.
✓ Branch 2 (82→83) taken 3 times.
✓ Branch 4 (83→84) taken 3 times.
✓ Branch 6 (84→85) taken 3 times.
✓ Branch 8 (85→86) taken 3 times.
3 fs << "size_t "+className+"_toMessage("+className+" & obj, DataStreamIter & iter){\n";
193 3 fs << "\tbool b(true);\n";
194
1/2
✗ Branch 0 (92→93) not taken.
✓ Branch 1 (92→97) taken 3 times.
3 if(classConfig.getIsEnum()){
195 fs << "\t//TODO : WrapperTraitDataStream data_stream_trait_wrapper_classPythonToBytes to be implemented" << std::endl;
196 std::cerr << "\t//TODO : WrapperTraitDataStream data_stream_trait_wrapper_classPythonToBytes to be implemented" << std::endl;
197 }else{
198 3 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
199
2/2
✓ Branch 0 (121→99) taken 5 times.
✓ Branch 1 (121→122) taken 3 times.
16 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
200
1/1
✓ Branch 0 (101→102) taken 5 times.
5 const PString & attrName = it->getName();
201
5/5
✓ Branch 0 (102→103) taken 5 times.
✓ Branch 2 (103→104) taken 5 times.
✓ Branch 4 (104→105) taken 5 times.
✓ Branch 6 (105→106) taken 5 times.
✓ Branch 8 (106→107) taken 5 times.
5 fs << "\tb &= "+className+"_"+attrName+"_toMessage(obj, iter);\n";
202 }
203 }
204 3 fs << "\treturn b;\n";
205 3 fs << "}\n\n";
206 3 }
207
208 ///Do the implementation of data stream method _getSizeInByte for one class
209 /** @param[out] fs : file to be completed
210 * @param classConfig : class configuration
211 * @param className : name of the current class
212 */
213 3 void data_stream_trait_wrapper_classPythonGetSizeInBytes(std::ofstream & fs, const PClassConfig & classConfig, const PString & className){
214
215
3/3
✓ Branch 0 (2→3) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
✓ Branch 4 (4→5) taken 3 times.
3 fs << "///Get the size in bytes of "+className+" for Python API\n";
216
3/3
✓ Branch 0 (7→8) taken 3 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 4 (9→10) taken 3 times.
3 fs << "/**\t@param self : pointer to the "+className+"\n";
217 3 fs << " * \t@param args : not used\n";
218
3/3
✓ Branch 0 (13→14) taken 3 times.
✓ Branch 2 (14→15) taken 3 times.
✓ Branch 4 (15→16) taken 3 times.
3 fs << " * \t@return size of the "+className+" in bytes\n";
219 3 fs << "*/\n";
220
3/3
✓ Branch 0 (19→20) taken 3 times.
✓ Branch 2 (20→21) taken 3 times.
✓ Branch 4 (21→22) taken 3 times.
3 fs << "PyObject * "+className+"_getSizeInByte(PyObject *self, PyObject *args){\n";
221
5/5
✓ Branch 0 (24→25) taken 3 times.
✓ Branch 2 (25→26) taken 3 times.
✓ Branch 4 (26→27) taken 3 times.
✓ Branch 6 (27→28) taken 3 times.
✓ Branch 8 (28→29) taken 3 times.
3 fs << "\t"+className+"* obj = ("+className+"*)self;\n";
222
3/3
✓ Branch 0 (33→34) taken 3 times.
✓ Branch 2 (34→35) taken 3 times.
✓ Branch 4 (35→36) taken 3 times.
3 data_stream_trait_wrapper_classCheckCall(fs, className, className+"_getSizeInByte");
223
3/3
✓ Branch 0 (38→39) taken 3 times.
✓ Branch 2 (39→40) taken 3 times.
✓ Branch 4 (40→41) taken 3 times.
3 fs << "\tsize_t nbByte = "+className+"_getSize(*obj);\n";
224 3 fs << "\treturn Py_BuildValue(\"k\", nbByte);\n";
225 3 fs << "}\n\n";
226
227
3/3
✓ Branch 0 (45→46) taken 3 times.
✓ Branch 2 (46→47) taken 3 times.
✓ Branch 4 (47→48) taken 3 times.
3 fs << "///Get the size of a "+className+"\n";
228
3/3
✓ Branch 0 (50→51) taken 3 times.
✓ Branch 2 (51→52) taken 3 times.
✓ Branch 4 (52→53) taken 3 times.
3 fs << "/**\t@param obj : reference to the "+className+" to be used\n";
229
3/3
✓ Branch 0 (55→56) taken 3 times.
✓ Branch 2 (56→57) taken 3 times.
✓ Branch 4 (57→58) taken 3 times.
3 fs << " * \t@return size of the "+className+" in bytes\n";
230 3 fs << "*/\n";
231
5/5
✓ Branch 0 (61→62) taken 3 times.
✓ Branch 2 (62→63) taken 3 times.
✓ Branch 4 (63→64) taken 3 times.
✓ Branch 6 (64→65) taken 3 times.
✓ Branch 8 (65→66) taken 3 times.
3 fs << "size_t "+className+"_getSize("+className+" & obj){\n";
232 3 fs << "\tsize_t nbByte(0lu);\n";
233
1/2
✗ Branch 0 (72→73) not taken.
✓ Branch 1 (72→75) taken 3 times.
3 if(classConfig.getIsEnum()){
234 fs << "\tnbByte += sizeof(int);" << std::endl;
235 }else{
236 3 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
237
2/2
✓ Branch 0 (99→77) taken 5 times.
✓ Branch 1 (99→100) taken 3 times.
16 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
238
1/1
✓ Branch 0 (79→80) taken 5 times.
5 const PString & attrName = it->getName();
239
5/5
✓ Branch 0 (80→81) taken 5 times.
✓ Branch 2 (81→82) taken 5 times.
✓ Branch 4 (82→83) taken 5 times.
✓ Branch 6 (83→84) taken 5 times.
✓ Branch 8 (84→85) taken 5 times.
5 fs << "\tnbByte += "+className+"_"+attrName+"_getSize(obj);\n";
240 }
241 }
242 3 fs << "\treturn nbByte;\n";
243 3 fs << "}\n\n";
244 3 }
245
246 ///Do the implementation of from message of one attribute
247 /** @param[out] fs : file to be completed
248 * @param className : name of the current class
249 * @param attr : current attribute
250 */
251 5 void data_stream_trait_wrapper_classAttributeFromMessage(std::ofstream & fs, const PString & className, const PClassAttribute & attr){
252
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 const PString & attrName = attr.getName(), & type(attr.getType());
253
1/1
✓ Branch 0 (4→5) taken 5 times.
5 bool isSimpleType(getIsSimpleType(type));
254
2/2
✓ Branch 0 (5→6) taken 5 times.
✓ Branch 2 (6→7) taken 5 times.
5 PString callAttr("self."+attrName);
255
5/5
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
5 fs << "///Load a "+className+"."+attrName+" from a DataStreamMsg\n";
256
3/3
✓ Branch 0 (17→18) taken 5 times.
✓ Branch 2 (18→19) taken 5 times.
✓ Branch 4 (19→20) taken 5 times.
5 fs << "/**\t@param self : reference to the "+className+"\n";
257
1/1
✓ Branch 0 (22→23) taken 5 times.
5 fs << " * \t@param iter : DataStreamIter to be used\n";
258
1/1
✓ Branch 0 (23→24) taken 5 times.
5 fs << " * \t@return true on success, false otherwise\n";
259
1/1
✓ Branch 0 (24→25) taken 5 times.
5 fs << "*/\n";
260
4/4
✓ Branch 0 (25→26) taken 5 times.
✓ Branch 2 (26→27) taken 5 times.
✓ Branch 4 (27→28) taken 5 times.
✓ Branch 6 (28→29) taken 5 times.
5 PString functionName(className+"_" + attrName + "_fromMessage");
261
5/5
✓ 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.
5 fs << "bool "+functionName + "("+className+" & self, DataStreamIter & iter){\n";
262
2/2
✓ Branch 0 (41→42) taken 3 times.
✓ Branch 1 (41→52) taken 2 times.
5 if(isSimpleType){
263
5/5
✓ Branch 0 (42→43) taken 3 times.
✓ Branch 2 (43→44) taken 3 times.
✓ Branch 4 (44→45) taken 3 times.
✓ Branch 6 (45→46) taken 3 times.
✓ Branch 8 (46→47) taken 3 times.
3 fs << "\treturn DataStream<DataStreamIter, DataStreamMode::READ, "+type+">::data_stream(iter, "+callAttr+");\n";
264
2/3
✓ Branch 0 (52→53) taken 2 times.
✓ Branch 2 (53→54) taken 2 times.
✗ Branch 3 (53→66) not taken.
2 }else if(type == "std::string"){
265
1/1
✓ Branch 0 (54→55) taken 2 times.
2 fs << "\tstd::string tmpStr(\"\");\n";
266
3/3
✓ Branch 0 (55→56) taken 2 times.
✓ Branch 2 (56→57) taken 2 times.
✓ Branch 4 (57→58) taken 2 times.
2 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::READ, "+type+">::data_stream(iter, tmpStr)){return false;};\n";
267 // fs << "\tself."+attrName+" = PyBytes_FromStringAndSize(tmpStr.c_str(), tmpStr.size());\n";
268 // fs << "\tself."+attrName+" = PyUnicode_FromStringAndSize(tmpStr.c_str(), tmpStr.size());\n";
269
3/3
✓ Branch 0 (60→61) taken 2 times.
✓ Branch 2 (61→62) taken 2 times.
✓ Branch 4 (62→63) taken 2 times.
2 fs << "\tself."+attrName+" = PyUnicode_DecodeFSDefaultAndSize(tmpStr.c_str(), tmpStr.size());\n";
270
1/1
✓ Branch 0 (65→214) taken 2 times.
2 fs << "\treturn true;\n";
271 }else if(type == "DataStreamMsg"){
272 fs << "\tDataStreamMsg message;\n";
273 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::READ, "+type+">::data_stream(iter, message)){return false;};\n";
274 fs << "\tself."+attrName+" = PyByteArray_FromStringAndSize((const char*)message.data(), message.size());\n";
275 fs << "\treturn true;\n";
276 }else if(generator_typeIsList(type)){
277 fs << "\tsize_t nbElement(0lu);\n";
278 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::READ, size_t>::data_stream(iter, nbElement)){return false;};\n";
279 fs << "\tif(nbElement == 0lu){return true;}\t//The list can be empty\n";
280 fs << "\t"+callAttr+" = PyList_New(nbElement);\n";
281 fs << "\tfor(size_t i(0lu); i < nbElement; ++i){\t//Then we load the content of the list\n";
282 PString nestedType(generator_getListNestedType(type));
283 if(getIsSimpleType(nestedType)){
284 fs << "\t\t"+nestedType+" value = 0;\n";
285 fs << "\t\tif(!DataStream<DataStreamIter, DataStreamMode::READ, "+nestedType+">::data_stream(iter, value)){return false;};\n";
286 fs << "\t\tPyObject * el = "+wrapper_getValueToObject(nestedType)+"(value);\n";
287 // fs << "\t\tPyObject * el = Py_BuildValue(\""+wrapper_getBuildValueStr(nestedType)+"\", value);\n";
288 fs << "\t\tPyList_SET_ITEM("+callAttr+", i, el);\n";
289 }else{
290 fs << "\t\t//If it is not a predefined type, we cannot deal with it\n";
291 fs << "\t\tWP"+nestedType+" * el = (WP"+nestedType+"*)WP"+nestedType+"_newC(&WP"+nestedType+"Type, NULL, NULL);\n";
292 fs << "\t\tif(!WP"+nestedType+"_fromMessage(*el, iter)){return false;}\n";
293 fs << "\t\tPyList_SET_ITEM("+callAttr+", i, el);\n";
294 }
295 fs << "\t}\n";
296 fs << "\treturn true;\n";
297 }else if(attr.getIsEnum()){
298 fs << "\t//TODO : implement the load from a message of type "+type+"\n";
299 fs << "\t//We know, for sure it is an Enum but we have to figure out how we are supposed to deal with it inside the wrapper\n";
300 fs << "\t//And I really wanted to avoid to call the interpreter once more each time we want to deserialise an Enum\n";
301 fs << "\tint enumValue = 0;\n";
302 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::READ, int>::data_stream(iter, enumValue)){\n";
303 fs << "\t\tstd::cerr << \""+functionName+" : cannot read enum value\" << std::endl;\n";
304 fs << "\t\treturn false;\n";
305 fs << "\t}\n";
306 // fs << "\tif(PyObject_SetAttrString("+callAttr+", \"value\", PyLong_FromLong(enumValue)) != 0){\n";
307 // fs << "\t\tstd::cerr << \""+functionName+" : cannot set enum value(\"<<enumValue<<\") in PyObject\" << std::endl;\n";
308 // fs << "\t\treturn false;\n";
309 // fs << "\t}\n";
310 fs << "\tstd::map<int, std::string>::const_iterator it = WP"+type+"EnumValue.find(enumValue);\n";
311 fs << "\tif(it == WP"+type+"EnumValue.end()){\n";
312 fs << "\t\tstd::cerr << \""+functionName+" : cannot find enum value \" << enumValue << \" in map WP"+type+"EnumValue\" << std::endl;\n";
313 fs << "\t\treturn false;\n";
314 fs << "\t}\n";
315
316 fs << "\tPy_DECREF("+callAttr+");\n";
317 fs << "\t"+callAttr+" = WP"+type+"_newGeneric(\"_var_______ = "+type+".\" + it->second, \"_var_______\");\n";
318 fs << "\treturn true;\n";
319
320 // fs << "\treturn PyObject_SetAttrString("+callAttr+", \"name\", PyUnicode_FromStringAndSize(it->second.c_str(), it->second.size())) == 0;\n";
321 }else{
322 fs << "\t//TODO : implement the load from a message of type "+type+"\n";
323 fs << "\treturn true;\n";
324 }
325
1/1
✓ Branch 0 (214→215) taken 5 times.
5 fs << "}\n\n";
326 5 }
327
328 ///Do the implementation of to message of one attribute
329 /** @param[out] fs : file to be completed
330 * @param className : name of the current class
331 * @param attr : current attribute
332 */
333 5 void data_stream_trait_wrapper_classAttributeToMessage(std::ofstream & fs, const PString & className, const PClassAttribute & attr){
334
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 const PString & attrName = attr.getName(), & type(attr.getType());
335
1/1
✓ Branch 0 (4→5) taken 5 times.
5 bool isSimpleType(getIsSimpleType(type));
336
2/2
✓ Branch 0 (5→6) taken 5 times.
✓ Branch 2 (6→7) taken 5 times.
5 PString callAttr("self."+attrName);
337
5/5
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
5 fs << "///Convert a "+className+"."+attrName+" to a DataStreamMsg\n";
338
3/3
✓ Branch 0 (17→18) taken 5 times.
✓ Branch 2 (18→19) taken 5 times.
✓ Branch 4 (19→20) taken 5 times.
5 fs << "/**\t@param self : reference to the "+className+"\n";
339
1/1
✓ Branch 0 (22→23) taken 5 times.
5 fs << " * \t@param iter : DataStreamIter to be used\n";
340
1/1
✓ Branch 0 (23→24) taken 5 times.
5 fs << " * \t@return true on success, false otherwise\n";
341
1/1
✓ Branch 0 (24→25) taken 5 times.
5 fs << "*/\n";
342
7/7
✓ Branch 0 (25→26) taken 5 times.
✓ Branch 2 (26→27) taken 5 times.
✓ Branch 4 (27→28) taken 5 times.
✓ Branch 6 (28→29) taken 5 times.
✓ Branch 8 (29→30) taken 5 times.
✓ Branch 10 (30→31) taken 5 times.
✓ Branch 12 (31→32) taken 5 times.
5 fs << "bool "+className+"_" + attrName + "_toMessage("+className+" & self, DataStreamIter & iter){\n";
343
2/2
✓ Branch 0 (38→39) taken 3 times.
✓ Branch 1 (38→49) taken 2 times.
5 if(isSimpleType){
344
5/5
✓ Branch 0 (39→40) taken 3 times.
✓ Branch 2 (40→41) taken 3 times.
✓ Branch 4 (41→42) taken 3 times.
✓ Branch 6 (42→43) taken 3 times.
✓ Branch 8 (43→44) taken 3 times.
3 fs << "\treturn DataStream<DataStreamIter, DataStreamMode::WRITE, "+type+">::data_stream(iter, "+callAttr+");\n";
345
2/3
✓ Branch 0 (49→50) taken 2 times.
✓ Branch 2 (50→51) taken 2 times.
✗ Branch 3 (50→59) not taken.
2 }else if(type == "std::string"){
346 // fs << "\tsize_t nbChar(PyUnicode_GetLength("+callAttr+"));\n"; //PyUnicode_GET_LENGTH
347
1/1
✓ Branch 0 (51→52) taken 2 times.
2 fs << "\tlong nbChar(0lu);\n";
348
3/3
✓ Branch 0 (52→53) taken 2 times.
✓ Branch 2 (53→54) taken 2 times.
✓ Branch 4 (54→55) taken 2 times.
2 fs << "\tconst char * ptr = PyUnicode_AsUTF8AndSize("+callAttr+", &nbChar);\n";
349
350
1/1
✓ Branch 0 (57→58) taken 2 times.
2 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::WRITE, long>::data_stream(iter, nbChar)){return false;}\n";
351 // fs << "\tconst char * ptr = PyBytes_AsString("+callAttr+");\n"; //PyBytes_AsString
352
1/1
✓ Branch 0 (58→153) taken 2 times.
2 fs << "\treturn DataStream<DataStreamIter, DataStreamMode::WRITE, char>::data_stream(iter, (char*)ptr, nbChar);\n";
353 }else if(type == "DataStreamMsg"){
354 fs << "\tsize_t nbByte(PyByteArray_Size("+callAttr+"));\n";
355 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::WRITE, size_t>::data_stream(iter, nbByte)){return false;}\n";
356 fs << "\tif(nbByte == 0lu){return true;}\t//The bytearray can be empty\n";
357 fs << "\tDataStreamIter dataPtr = (DataStreamIter)PyByteArray_AsString("+callAttr+");\n";
358 fs << "\treturn DataStream<DataStreamIter, DataStreamMode::WRITE, DataStreamType>::data_stream(iter, dataPtr, nbByte);\n";
359 }else if(generator_typeIsList(type)){
360 fs << "\tsize_t nbElement(PyByteArray_Size("+callAttr+"));\n";
361 fs << "\tif(!DataStream<DataStreamIter, DataStreamMode::WRITE, size_t>::data_stream(iter, nbElement)){return false;}\n";
362 fs << "\tif(nbElement == 0lu){return true;}\t//The list can be empty\n";
363 fs << "\tfor(size_t i(0lu); i < nbElement; ++i){\t//Then the content of the list\n";
364 PString nestedType(generator_getListNestedType(type));
365 if(getIsSimpleType(nestedType)){
366 fs << "\t\tPyObject * el = PyList_GET_ITEM("+callAttr+", i);\n";
367 fs << "\t\t"+nestedType+" value = "+wrapper_getObjectToValue(nestedType)+"(el);\n";
368 fs << "\t\tif(!DataStream<DataStreamIter, DataStreamMode::WRITE, "+nestedType+">::data_stream(iter, value)){return false;}\n";
369 }else{
370 fs << "\t\t//If it is not a predefined type, we cannot deal with it\n";
371 fs << "\t\tPyObject * el = PyList_GET_ITEM("+callAttr+", i);\n";
372 fs << "\t\tif(!WP"+nestedType+"_toMessage((WP"+nestedType+"&)*el, iter)){return false;}\n";
373 }
374 fs << "\t}\n";
375 fs << "\treturn true;\n";
376 }else if(attr.getIsEnum()){
377 fs << "\t//TODO : implement the save to a message of type "+type+"\n";
378 fs << "\t//We know, for sure it is an Enum but we have to figure out how we are supposed to deal with it inside the wrapper\n";
379 fs << "\t//And I really wanted to avoid to call the interpreter once more each time we want to serialise an Enum\n";
380 fs << "\tPyObject * attrValue = PyObject_GetAttrString("+callAttr+", \"value\");\n";
381 fs << "\tif(attrValue == NULL){return false;}\n";
382 fs << "\t//Now we have to get the integer inside the attribute\n";
383 fs << "\tint enumValue = PyLong_AsInt(attrValue);\n";
384 fs << "\treturn DataStream<DataStreamIter, DataStreamMode::WRITE, int>::data_stream(iter, enumValue);\n";
385 }else{
386 fs << "\t//TODO : implement the save to a message of type "+type+"\n";
387 fs << "\treturn true;\n";
388 }
389
1/1
✓ Branch 0 (153→154) taken 5 times.
5 fs << "}\n\n";
390 5 }
391
392 ///Do the implementation of get size of one attribute
393 /** @param[out] fs : file to be completed
394 * @param className : name of the current class
395 * @param attr : attribute of the class
396 */
397 5 void data_stream_trait_wrapper_classAttributeGetSize(std::ofstream & fs, const PString & className, const PClassAttribute & attr){
398
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 const PString & attrName = attr.getName(), & type(attr.getType());
399
1/1
✓ Branch 0 (4→5) taken 5 times.
5 bool isSimpleType(getIsSimpleType(type));
400
2/2
✓ Branch 0 (5→6) taken 5 times.
✓ Branch 2 (6→7) taken 5 times.
5 PString callAttr("self."+attrName);
401
5/5
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
5 fs << "///Get the size of "+className+"."+attrName+" in bytes\n";
402
3/3
✓ Branch 0 (17→18) taken 5 times.
✓ Branch 2 (18→19) taken 5 times.
✓ Branch 4 (19→20) taken 5 times.
5 fs << "/**\t@param self : reference to the "+className+"\n";
403
5/5
✓ Branch 0 (22→23) taken 5 times.
✓ Branch 2 (23→24) taken 5 times.
✓ Branch 4 (24→25) taken 5 times.
✓ Branch 6 (25→26) taken 5 times.
✓ Branch 8 (26→27) taken 5 times.
5 fs << " * \t@return size of "+className+"."+attrName+" in bytes\n";
404
1/1
✓ Branch 0 (31→32) taken 5 times.
5 fs << "*/\n";
405
7/7
✓ 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.
5 fs << "size_t "+className+"_" + attrName + "_getSize("+className+" & self){\n";
406
1/1
✓ Branch 0 (45→46) taken 5 times.
5 fs << "\tsize_t nbByte(0lu);\n";
407
2/2
✓ Branch 0 (46→47) taken 3 times.
✓ Branch 1 (46→57) taken 2 times.
5 if(isSimpleType){
408
5/5
✓ Branch 0 (47→48) taken 3 times.
✓ Branch 2 (48→49) taken 3 times.
✓ Branch 4 (49→50) taken 3 times.
✓ Branch 6 (50→51) taken 3 times.
✓ Branch 8 (51→52) taken 3 times.
3 fs << "\tDataStream<size_t, DataStreamMode::WRITE, "+type+">::data_stream(nbByte, "+callAttr+");\n";
409
2/3
✓ Branch 0 (57→58) taken 2 times.
✓ Branch 2 (58→59) taken 2 times.
✗ Branch 3 (58→65) not taken.
2 }else if(type == "std::string"){
410
3/3
✓ Branch 0 (59→60) taken 2 times.
✓ Branch 2 (60→61) taken 2 times.
✓ Branch 4 (61→62) taken 2 times.
2 fs << "\tnbByte += sizeof(size_t) + PyUnicode_GetLength("+callAttr+");\n"; //PyBytes_Size
411 }else if(type == "DataStreamMsg"){
412 fs << "\tnbByte += sizeof(size_t) + PyByteArray_Size("+callAttr+");\n"; //PyBytes_Size
413 }else if(generator_typeIsList(type)){
414 fs << "\tnbByte += sizeof(size_t);\t//First the size of the number of elements in the list\n";
415 PString nestedType(generator_getListNestedType(type));
416 if(getIsSimpleType(nestedType)){
417 fs << "\tnbByte += sizeof("+nestedType+")*PyList_Size("+callAttr+");\t//Then the content of the list\n";
418 }else{
419 fs << "\t//If it is not a predefined type, we cannot deal with it\n";
420 fs << "\tfor(long i(0l); i < PyList_Size("+callAttr+"); ++i){\t//Then the content of the list\n";
421 fs << "\t\tPyObject * el = PyList_GET_ITEM("+callAttr+", i);\n";
422 fs << "\t\tnbByte += WP"+nestedType+"_getSize((WP"+nestedType+"&)*el);\n";
423 fs << "\t}\n";
424 }
425 }else if(attr.getIsEnum()){
426 fs << "\t//The size of an Enum is the size of an integer\n";
427 fs << "\tnbByte += sizeof(int);\n";
428 }else{
429 fs << "\t//TODO : implement the get size of type "+type+"\n";
430 }
431
1/1
✓ Branch 0 (122→123) taken 5 times.
5 fs << "\treturn nbByte;\n";
432
1/1
✓ Branch 0 (123→124) taken 5 times.
5 fs << "}\n\n";
433 5 }
434
435 ///Get the default of a given type for a test
436 /** @param type : type of the attribute to be set
437 * @return corresponding Python
438 */
439 10 PString pythonGetDefaultTestValue(PString & type){
440
12/20
✓ Branch 0 (3→4) taken 6 times.
✓ Branch 1 (3→20) taken 4 times.
✓ Branch 2 (5→6) taken 6 times.
✗ Branch 3 (5→20) not taken.
✓ Branch 4 (7→8) taken 6 times.
✗ Branch 5 (7→20) not taken.
✓ Branch 6 (9→10) taken 6 times.
✗ Branch 7 (9→20) not taken.
✓ Branch 8 (11→12) taken 6 times.
✗ Branch 9 (11→20) not taken.
✓ Branch 10 (13→14) taken 6 times.
✗ Branch 11 (13→20) not taken.
✓ Branch 12 (15→16) taken 6 times.
✗ Branch 13 (15→20) not taken.
✓ Branch 14 (17→18) taken 6 times.
✗ Branch 15 (17→20) not taken.
✗ Branch 16 (19→20) not taken.
✓ Branch 17 (19→21) taken 6 times.
✓ Branch 18 (22→23) taken 4 times.
✓ Branch 19 (22→24) taken 6 times.
10 if(type == "int" || type == "long" || type == "long int" || type == "size_t" || type == "unsigned int" || type == "unsigned short" || type == "char" || type == "unsigned char" || type == "long unsigned int"){
441 4 return "42";
442
5/6
✓ Branch 0 (25→26) taken 4 times.
✓ Branch 1 (25→28) taken 2 times.
✗ Branch 2 (27→28) not taken.
✓ Branch 3 (27→29) taken 4 times.
✓ Branch 4 (30→31) taken 2 times.
✓ Branch 5 (30→32) taken 4 times.
6 }else if(type == "float" || type == "double"){
443 2 return "42.0";
444
1/2
✓ Branch 0 (33→34) taken 4 times.
✗ Branch 1 (33→35) not taken.
4 }else if(type == "std::string"){
445 4 return "\"Shadoko\"";
446 }else if(type == "DataStreamMsg"){
447 return "bytearray(b\"Shadoko\")";
448 }else if(generator_typeIsList(type)){
449 PString nestedType(generator_getListNestedType(type));
450 PString nestedDefaultValue(pythonGetDefaultTestValue(nestedType));
451 if(nestedDefaultValue != ""){
452 return "["+nestedDefaultValue+"]";
453 }else{
454 return "[]";
455 }
456 }
457
458 return "";
459 }
460
461 ///Get the default set of given attribute for a test
462 /** @param varName : name of the variable of the class to be used
463 * @param attr : attribute to be set
464 * @param moduleName : name of the module to be used
465 * @param indentation : indentation of the set
466 * @param mapClass : map of all classes/types defined for this configuration
467 * @return corresponding Python
468 */
469 5 PString pythonDefaultTestValue(const PString & varName, const PClassAttribute & attr, const PString & moduleName, const PString & indentation,
470 const std::map<std::string, PClassConfig> & mapClass)
471 {
472
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 PString type(attr.getType());
473
1/1
✓ Branch 0 (4→5) taken 5 times.
5 PString body(indentation);
474
475
1/1
✓ Branch 0 (5→6) taken 5 times.
5 PString initValue(pythonGetDefaultTestValue(type));
476
2/3
✓ Branch 0 (6→7) taken 5 times.
✓ Branch 2 (7→8) taken 5 times.
✗ Branch 3 (7→21) not taken.
5 if(initValue != ""){
477
7/7
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
✓ Branch 10 (13→14) taken 5 times.
✓ Branch 12 (14→15) taken 5 times.
5 body += varName + "." + attr.getName() + " = "+initValue+"\n";
478 }else if(attr.getIsEnum()){
479 std::map<std::string, PClassConfig>::const_iterator it(mapClass.find(type));
480 if(it != mapClass.end()){
481 //Let's take the last value so we are sure this is not a 0 or a default value
482 body += varName + "." + attr.getName() + " = "+moduleName+"."+type+"."+it->second.getListAttribute().back().getName()+"\n";
483 }
484 }else{
485 return "";
486 }
487
1/1
✓ Branch 0 (55→56) taken 5 times.
5 return body;
488 5 }
489
490 ///Get the default set of given attribute for a test
491 /** @param varName : name of the variable of the class to be used
492 * @param attr : attribute to be set
493 * @param moduleName : name of the module to be used
494 * @param indentation : indentation of the set
495 * @param mapClass : map of all classes/types defined for this configuration
496 * @return corresponding Python
497 */
498 5 PString pythonAssertTestValue(const PString & varName, const PClassAttribute & attr, const PString & moduleName, const PString & indentation,
499 const std::map<std::string, PClassConfig> & mapClass)
500 {
501
2/2
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
5 PString type(attr.getType());
502
1/1
✓ Branch 0 (4→5) taken 5 times.
5 PString body(indentation);
503
504
1/1
✓ Branch 0 (5→6) taken 5 times.
5 PString initValue(pythonGetDefaultTestValue(type));
505
2/3
✓ Branch 0 (6→7) taken 5 times.
✓ Branch 2 (7→8) taken 5 times.
✗ Branch 3 (7→23) not taken.
5 if(initValue != ""){
506
8/8
✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 5 times.
✓ Branch 4 (10→11) taken 5 times.
✓ Branch 6 (11→12) taken 5 times.
✓ Branch 8 (12→13) taken 5 times.
✓ Branch 10 (13→14) taken 5 times.
✓ Branch 12 (14→15) taken 5 times.
✓ Branch 14 (15→16) taken 5 times.
5 body += "assert " + varName + "." + attr.getName() + " == "+initValue+"\n";
507 }else if(attr.getIsEnum()){
508 std::map<std::string, PClassConfig>::const_iterator it(mapClass.find(type));
509 if(it != mapClass.end()){
510 body += "assert " + varName + "." + attr.getName() + ".value == "+moduleName+"."+type+"."+it->second.getListAttribute().back().getName()+".value\n";
511 }
512 }else{
513 return "";
514 }
515
1/1
✓ Branch 0 (59→60) taken 5 times.
5 return body;
516 5 }
517
518 ///Consctructor of WrapperTraitDataStream
519 2 WrapperTraitDataStream::WrapperTraitDataStream()
520 2 :PAbstractWrapperTraitBackend()
521 2 {}
522
523 ///Desctructor of WrapperTraitDataStream
524 4 WrapperTraitDataStream::~WrapperTraitDataStream(){}
525
526 ///Add extra include on the header
527 /** @param[out] fs : file to be completed
528 * @param mode : mode of the generator
529 */
530 3 void WrapperTraitDataStream::headerExtraInclude(std::ofstream & fs, const GeneratorMode & mode) const{
531
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 3 times.
3 if(!mode.enableDataStream){return;}
532 3 fs << "#include \"phoenix_data_stream.h\"" << std::endl;
533 }
534
535 ///Declaration of class method
536 /** @param[out] fs : file to be completed
537 * @param classConfig : PClassConfig to be used
538 * @param mode : mode of the generator
539 */
540 3 void WrapperTraitDataStream::classMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
541
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 3 times.
3 if(!mode.enableDataStream){return;}
542
1/1
✓ Branch 0 (4→5) taken 3 times.
3 PString className(wrapper_getClassName(classConfig));
543
1/1
✓ Branch 0 (5→6) taken 3 times.
3 fs << "//Check function (used by data stream)\n";
544
5/5
✓ Branch 0 (6→7) taken 3 times.
✓ Branch 2 (7→8) taken 3 times.
✓ Branch 4 (8→9) taken 3 times.
✓ Branch 6 (9→10) taken 3 times.
✓ Branch 8 (10→11) taken 3 times.
3 fs << "bool "+className+"_check(std::string & error, const "+className+" & obj);\n";
545
546
1/1
✓ Branch 0 (15→16) taken 3 times.
3 fs << "//PhoenixDataStream interface\n";
547
3/3
✓ Branch 0 (16→17) taken 3 times.
✓ Branch 2 (17→18) taken 3 times.
✓ Branch 4 (18→19) taken 3 times.
3 fs << "PyObject * "+className+"_fromBytes(PyObject *self, PyObject *args);\n";
548
5/5
✓ Branch 0 (21→22) taken 3 times.
✓ Branch 2 (22→23) taken 3 times.
✓ Branch 4 (23→24) taken 3 times.
✓ Branch 6 (24→25) taken 3 times.
✓ Branch 8 (25→26) taken 3 times.
3 fs << "size_t "+className+"_fromMessage("+className+" & obj, DataStreamIter & iter);\n\n";
549
550
3/3
✓ Branch 0 (30→31) taken 3 times.
✓ Branch 2 (31→32) taken 3 times.
✓ Branch 4 (32→33) taken 3 times.
3 fs << "PyObject * "+className+"_toBytes(PyObject *self, PyObject *args);\n";
551
5/5
✓ Branch 0 (35→36) taken 3 times.
✓ Branch 2 (36→37) taken 3 times.
✓ Branch 4 (37→38) taken 3 times.
✓ Branch 6 (38→39) taken 3 times.
✓ Branch 8 (39→40) taken 3 times.
3 fs << "size_t "+className+"_toMessage("+className+" & obj, DataStreamIter & iter);\n\n";
552
553
3/3
✓ Branch 0 (44→45) taken 3 times.
✓ Branch 2 (45→46) taken 3 times.
✓ Branch 4 (46→47) taken 3 times.
3 fs << "PyObject * "+className+"_getSizeInByte(PyObject *self, PyObject *args);\n";
554
5/5
✓ Branch 0 (49→50) taken 3 times.
✓ Branch 2 (50→51) taken 3 times.
✓ Branch 4 (51→52) taken 3 times.
✓ Branch 6 (52→53) taken 3 times.
✓ Branch 8 (53→54) taken 3 times.
3 fs << "size_t "+className+"_getSize("+className+" & obj);\n\n";
555
2/3
✓ Branch 0 (58→59) taken 3 times.
✓ Branch 2 (59→60) taken 3 times.
✗ Branch 3 (59→131) not taken.
3 if(!classConfig.getIsEnum()){
556
1/1
✓ Branch 0 (60→61) taken 3 times.
3 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
557
1/1
✓ Branch 0 (61→62) taken 3 times.
3 fs << "//PhoenixDataStream interface under the hood for all attributes\n";
558
2/2
✓ Branch 0 (129→63) taken 5 times.
✓ Branch 1 (129→130) taken 3 times.
16 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
559
4/4
✓ Branch 0 (65→66) taken 5 times.
✓ Branch 2 (66→67) taken 5 times.
✓ Branch 4 (67→68) taken 5 times.
✓ Branch 6 (68→69) taken 5 times.
10 fs << "//PhoenixDataStream interface under the hood for " + it->getName() + " attribute\n";
560
8/8
✓ Branch 0 (73→74) taken 5 times.
✓ Branch 2 (74→75) taken 5 times.
✓ Branch 4 (75→76) taken 5 times.
✓ Branch 6 (76→77) taken 5 times.
✓ Branch 8 (77→78) taken 5 times.
✓ Branch 10 (78→79) taken 5 times.
✓ Branch 12 (79→80) taken 5 times.
✓ Branch 14 (80→81) taken 5 times.
10 fs << "bool "+className+"_" + it->getName() + "_fromMessage("+className+" & self, DataStreamIter &iter);\n";
561
8/8
✓ Branch 0 (89→90) taken 5 times.
✓ Branch 2 (90→91) taken 5 times.
✓ Branch 4 (91→92) taken 5 times.
✓ Branch 6 (92→93) taken 5 times.
✓ Branch 8 (93→94) taken 5 times.
✓ Branch 10 (94→95) taken 5 times.
✓ Branch 12 (95→96) taken 5 times.
✓ Branch 14 (96→97) taken 5 times.
10 fs << "bool "+className+"_" + it->getName() + "_toMessage("+className+" & self, DataStreamIter &iter);\n";
562
8/8
✓ Branch 0 (105→106) taken 5 times.
✓ Branch 2 (106→107) taken 5 times.
✓ Branch 4 (107→108) taken 5 times.
✓ Branch 6 (108→109) taken 5 times.
✓ Branch 8 (109→110) taken 5 times.
✓ Branch 10 (110→111) taken 5 times.
✓ Branch 12 (111→112) taken 5 times.
✓ Branch 14 (112→113) taken 5 times.
10 fs << "size_t "+className+"_" + it->getName() + "_getSize("+className+" & self);\n\n";
563 }
564 }
565 3 }
566
567 ///Implementation of class method
568 /** @param[out] fs : file to be completed
569 * @param classConfig : PClassConfig to be used
570 * @param mode : mode of the generator
571 */
572 3 void WrapperTraitDataStream::classMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
573
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 3 times.
3 if(!mode.enableDataStream){return;}
574
1/1
✓ Branch 0 (4→5) taken 3 times.
3 PString className(wrapper_getClassName(classConfig));
575
1/1
✓ Branch 0 (5→6) taken 3 times.
3 data_stream_trait_wrapper_classImplCheck(fs, classConfig, mode.moduleName);
576
1/1
✓ Branch 0 (6→7) taken 3 times.
3 data_stream_trait_wrapper_classPythonFromBytes(fs, classConfig, className);
577
1/1
✓ Branch 0 (7→8) taken 3 times.
3 data_stream_trait_wrapper_classPythonToBytes(fs, classConfig, className);
578
1/1
✓ Branch 0 (8→9) taken 3 times.
3 data_stream_trait_wrapper_classPythonGetSizeInBytes(fs, classConfig, className);
579
2/3
✓ Branch 0 (9→10) taken 3 times.
✓ Branch 2 (10→11) taken 3 times.
✗ Branch 3 (10→34) not taken.
3 if(!classConfig.getIsEnum()){
580
1/1
✓ Branch 0 (11→12) taken 3 times.
3 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
581
2/2
✓ Branch 0 (32→13) taken 5 times.
✓ Branch 1 (32→33) taken 3 times.
16 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
582
1/1
✓ Branch 0 (15→16) taken 5 times.
5 data_stream_trait_wrapper_classAttributeFromMessage(fs, className, *it);
583
1/1
✓ Branch 0 (18→19) taken 5 times.
5 data_stream_trait_wrapper_classAttributeToMessage(fs, className, *it);
584
1/1
✓ Branch 0 (21→22) taken 5 times.
5 data_stream_trait_wrapper_classAttributeGetSize(fs, className, *it);
585 }
586 }
587 3 }
588
589 ///Register class getter and setter
590 /** @param[out] fs : file to be completed
591 * @param classConfig : PClassConfig to be used
592 * @param mode : mode of the generator
593 */
594 3 void WrapperTraitDataStream::registerClassGetterSetter(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
595
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 3 times.
3 if(!mode.enableDataStream){return;}
596
597 }
598
599 ///Register class method
600 /** @param[out] fs : file to be completed
601 * @param classConfig : PClassConfig to be used
602 * @param mode : mode of the generator
603 */
604 3 void WrapperTraitDataStream::registerClassMethod(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
605
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 3 times.
3 if(!mode.enableDataStream){return;}
606
1/1
✓ Branch 0 (4→5) taken 3 times.
3 PString className(wrapper_getClassName(classConfig));
607
5/5
✓ Branch 0 (5→6) taken 3 times.
✓ Branch 2 (6→7) taken 3 times.
✓ Branch 4 (7→8) taken 3 times.
✓ Branch 6 (8→9) taken 3 times.
✓ Branch 8 (9→10) taken 3 times.
3 fs << "\t{\"fromBytes\", (PyCFunction)"<<className<<"_fromBytes, METH_VARARGS, \"Doc : load a "<<className<<" from PyByteArray\"},\n";
608
5/5
✓ Branch 0 (10→11) taken 3 times.
✓ Branch 2 (11→12) taken 3 times.
✓ Branch 4 (12→13) taken 3 times.
✓ Branch 6 (13→14) taken 3 times.
✓ Branch 8 (14→15) taken 3 times.
3 fs << "\t{\"toBytes\", (PyCFunction)"<<className<<"_toBytes, METH_NOARGS, \"Doc : convert a "<<className<<" to PyByteArray\"},\n";
609
5/5
✓ Branch 0 (15→16) taken 3 times.
✓ Branch 2 (16→17) taken 3 times.
✓ Branch 4 (17→18) taken 3 times.
✓ Branch 6 (18→19) taken 3 times.
✓ Branch 8 (19→20) taken 3 times.
3 fs << "\t{\"getSize\", (PyCFunction)"<<className<<"_getSizeInByte, METH_NOARGS, \"Doc : Get the size of "<<className<<" in bytes\"},\n";
610 3 }
611
612 ///Implementation of test function
613 /** @param[out] fs : file to be completed
614 * @param classConfig : PClassConfig to be used
615 * @param mode : mode of the generator
616 */
617 5 void WrapperTraitDataStream::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
618
6/7
✓ Branch 0 (2→3) taken 5 times.
✗ Branch 1 (2→5) not taken.
✓ Branch 2 (3→4) taken 5 times.
✓ Branch 4 (4→5) taken 2 times.
✓ Branch 5 (4→6) taken 3 times.
✓ Branch 6 (7→8) taken 2 times.
✓ Branch 7 (7→9) taken 3 times.
5 if(!mode.enableDataStream || classConfig.getIsEnum()){return;}
619
3/3
✓ Branch 0 (9→10) taken 3 times.
✓ Branch 2 (10→11) taken 3 times.
✓ Branch 4 (11→12) taken 3 times.
3 PString className(classConfig.getName()), moduleName(mode.moduleName);
620
3/3
✓ Branch 0 (12→13) taken 3 times.
✓ Branch 2 (13→14) taken 3 times.
✓ Branch 4 (14→15) taken 3 times.
3 fs << "#Unit Test of the " + className + "\n";
621
3/3
✓ Branch 0 (17→18) taken 3 times.
✓ Branch 2 (18→19) taken 3 times.
✓ Branch 4 (19→20) taken 3 times.
3 fs << "def test_datastream_"+className+"():\n";
622
1/1
✓ Branch 0 (22→23) taken 3 times.
3 fs << "\t#Let's test the stream now\n";
623
5/5
✓ Branch 0 (23→24) taken 3 times.
✓ Branch 2 (24→25) taken 3 times.
✓ Branch 4 (25→26) taken 3 times.
✓ Branch 6 (26→27) taken 3 times.
✓ Branch 8 (27→28) taken 3 times.
3 fs << "\tshadok = "+moduleName+"."+className+"()\n";
624
1/1
✓ Branch 0 (32→33) taken 3 times.
3 const std::vector<PClassAttribute> & vecAttr = classConfig.getListAttribute();
625
2/2
✓ Branch 0 (53→34) taken 5 times.
✓ Branch 1 (53→54) taken 3 times.
16 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
626
4/4
✓ Branch 0 (34→35) taken 5 times.
✓ Branch 2 (37→38) taken 5 times.
✓ Branch 4 (38→39) taken 5 times.
✓ Branch 6 (39→40) taken 5 times.
10 fs << pythonDefaultTestValue("shadok", *it, moduleName, "\t", mode.mapClass);
627 }
628
1/1
✓ Branch 0 (54→55) taken 3 times.
3 fs << "\tstream = shadok.toBytes()\n";
629
1/1
✓ Branch 0 (55→56) taken 3 times.
3 fs << "\tassert len(stream) != 0\n";
630
1/1
✓ Branch 0 (56→57) taken 3 times.
3 fs << "\t\n";
631
5/5
✓ Branch 0 (57→58) taken 3 times.
✓ Branch 2 (58→59) taken 3 times.
✓ Branch 4 (59→60) taken 3 times.
✓ Branch 6 (60→61) taken 3 times.
✓ Branch 8 (61→62) taken 3 times.
3 fs << "\tother = "+moduleName+"."+className+"()\n";
632
1/1
✓ Branch 0 (66→67) taken 3 times.
3 fs << "\tother.fromBytes(stream)\n";
633
2/2
✓ Branch 0 (87→68) taken 5 times.
✓ Branch 1 (87→88) taken 3 times.
16 for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
634
4/4
✓ Branch 0 (68→69) taken 5 times.
✓ Branch 2 (71→72) taken 5 times.
✓ Branch 4 (72→73) taken 5 times.
✓ Branch 6 (73→74) taken 5 times.
10 fs << pythonAssertTestValue("other", *it, moduleName, "\t", mode.mapClass);
635 }
636
1/1
✓ Branch 0 (88→89) taken 3 times.
3 fs << "\t\n";
637
1/1
✓ Branch 0 (89→90) taken 3 times.
3 fs << "\t\n";
638 3 }
639
640 ///Call of the test function
641 /** @param[out] fs : file to be completed
642 * @param classConfig : PClassConfig to be used
643 * @param mode : mode of the generator
644 */
645 void WrapperTraitDataStream::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
646 if(!mode.enableDataStream){return;}
647
648 }
649
650 ///Add dependency in the setup.py
651 /** @param[out] fs : file to be completed
652 * @param mode : mode of the generator
653 */
654 2 void WrapperTraitDataStream::setupAddDependency(std::ofstream & fs, const GeneratorMode & mode) const{
655
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 2 times.
2 if(!mode.enableTypeStream){return;}
656 2 fs << "addWrapperDependency(listIncludeDir, listLibDir, listLib, \"phoenixdatastream-config\", [\"phoenix_data_stream\"])" << std::endl;
657 }
658
659
660