| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : LGPL-3.0-only | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include <sstream> | ||
| 8 | #include "phoenix_color.h" | ||
| 9 | #include "openFileStream.h" | ||
| 10 | #include "header_generator.h" | ||
| 11 | #include "cmakelist_generator.h" | ||
| 12 | #include "type_utils.h" | ||
| 13 | #include "generator_class_cpp.h" | ||
| 14 | |||
| 15 | ///Check if the given class owns at least one pointer attribute | ||
| 16 | /** @param classConfig : PClassConfig to be checked | ||
| 17 | * @return true if the class has a pointer attribute, false otherwise | ||
| 18 | */ | ||
| 19 | 26 | bool class_hasPointerAttribute(const PClassConfig & classConfig){ | |
| 20 | 26 | const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute()); | |
| 21 |
2/2✓ Branch 0 (20→4) taken 67 times.
✓ Branch 1 (20→21) taken 23 times.
|
180 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 22 |
4/4✓ Branch 0 (6→7) taken 67 times.
✓ Branch 2 (7→8) taken 67 times.
✓ Branch 4 (8→9) taken 3 times.
✓ Branch 5 (8→10) taken 64 times.
|
67 | if(getIsPointerType(it->getType())){return true;} |
| 23 | } | ||
| 24 | 23 | return false; | |
| 25 | } | ||
| 26 | |||
| 27 | ///Get the template call in the class declaration | ||
| 28 | /** @param listTemplate : list of template def | ||
| 29 | * @return template definition in the class declaration (< T, U, .... >) | ||
| 30 | */ | ||
| 31 | 21 | PString class_getClassDefTemplate(const PVecString & listTemplate){ | |
| 32 |
3/3✓ Branch 0 (3→4) taken 19 times.
✓ Branch 1 (3→6) taken 2 times.
✓ Branch 2 (4→5) taken 19 times.
|
21 | if(listTemplate.size() == 0LU){return "";} |
| 33 |
2/2✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
|
2 | PString defTemplate("<"), comma(""); |
| 34 |
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){ |
| 35 |
1/1✓ Branch 0 (11→12) taken 3 times.
|
6 | PVecString vecPart = it->split(' '); |
| 36 |
1/2✓ Branch 0 (13→14) taken 3 times.
✗ Branch 1 (13→19) not taken.
|
3 | if(vecPart.size() != 0LU){ |
| 37 |
2/2✓ Branch 0 (15→16) taken 3 times.
✓ Branch 2 (16→17) taken 3 times.
|
3 | defTemplate += comma + vecPart.back(); |
| 38 |
1/1✓ Branch 0 (18→19) taken 3 times.
|
3 | comma = ", "; |
| 39 | } | ||
| 40 | 3 | } | |
| 41 |
1/1✓ Branch 0 (31→32) taken 2 times.
|
2 | defTemplate += ">"; |
| 42 | 2 | return defTemplate; | |
| 43 | 2 | } | |
| 44 | |||
| 45 | ///Get the template definition in the class declaration | ||
| 46 | /** @param listTemplate : list of template def | ||
| 47 | * @return template definition in the class declaration (template< .... >) | ||
| 48 | */ | ||
| 49 | 19 | PString class_getClassDeclTempalteDef(const PVecString & listTemplate){ | |
| 50 |
2/3✓ Branch 0 (3→4) taken 19 times.
✗ Branch 1 (3→6) not taken.
✓ Branch 2 (4→5) taken 19 times.
|
19 | if(listTemplate.size() == 0LU){return "";} |
| 51 | ✗ | PString templateDef("template<"); | |
| 52 | ✗ | PString comma(""); | |
| 53 | ✗ | for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){ | |
| 54 | ✗ | templateDef += comma; | |
| 55 | ✗ | templateDef += *it; | |
| 56 | ✗ | comma = ", "; | |
| 57 | } | ||
| 58 | ✗ | templateDef += ">\n"; | |
| 59 | ✗ | return templateDef; | |
| 60 | ✗ | } | |
| 61 | |||
| 62 | ///Get the in-class default member initialiser of an attribute (eg "{0}"), or an empty PString if the attribute doesn't need one | ||
| 63 | /** @param attr : attribute to be checked | ||
| 64 | * @return in-class default member initialiser of the attribute, or an empty PString if none is needed | ||
| 65 | */ | ||
| 66 | 21 | PString class_getAttributeDefaultInit(const PClassAttribute & attr){ | |
| 67 |
6/6✓ Branch 0 (2→3) taken 21 times.
✓ Branch 2 (3→4) taken 21 times.
✓ Branch 4 (4→5) taken 2 times.
✓ Branch 5 (4→8) taken 19 times.
✓ Branch 6 (5→6) taken 2 times.
✓ Branch 8 (6→7) taken 2 times.
|
21 | if(attr.getDefaultValue() != ""){return attr.getDefaultValue();} |
| 68 |
2/2✓ Branch 0 (8→9) taken 19 times.
✓ Branch 2 (9→10) taken 19 times.
|
19 | PString varType(attr.getType()); |
| 69 |
4/4✓ Branch 0 (10→11) taken 19 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 3 (11→14) taken 18 times.
✓ Branch 4 (12→13) taken 1 times.
|
19 | if(getIsPointerType(varType)){return "{NULL}";} //raw pointer : not implicitly null-initialised, needs an explicit NSDMI |
| 70 |
1/1✓ Branch 0 (14→15) taken 18 times.
|
18 | PString defaultValue(getDefaultValueTypeInCpp(varType)); |
| 71 |
6/6✓ Branch 0 (15→16) taken 18 times.
✓ Branch 2 (16→17) taken 16 times.
✓ Branch 3 (16→24) taken 2 times.
✓ Branch 4 (17→18) taken 16 times.
✓ Branch 6 (18→19) taken 16 times.
✓ Branch 8 (19→20) taken 16 times.
|
34 | if(defaultValue != ""){return "{" + defaultValue + "}";} |
| 72 |
1/1✓ Branch 0 (24→25) taken 2 times.
|
2 | return ""; |
| 73 | 19 | } | |
| 74 | |||
| 75 | ///Check if the vector of PClassAttribute has default value | ||
| 76 | /** @param vecAttr : vector of attribute to be checked | ||
| 77 | * @return true if there is at least one default value, false if there is none | ||
| 78 | */ | ||
| 79 | 3 | bool generator_checkDefaultValueExist(const std::vector<PClassAttribute> & vecAttr){ | |
| 80 | 3 | bool hasDefaultValue = false; | |
| 81 |
5/6✓ Branch 0 (17→18) taken 6 times.
✓ Branch 1 (17→20) taken 3 times.
✓ Branch 2 (18→19) taken 6 times.
✗ Branch 3 (18→20) not taken.
✓ Branch 4 (21→3) taken 6 times.
✓ Branch 5 (21→22) taken 3 times.
|
18 | for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end() && !hasDefaultValue; ++it){ |
| 82 |
2/2✓ Branch 0 (5→6) taken 6 times.
✓ Branch 2 (6→7) taken 6 times.
|
6 | hasDefaultValue |= it->getDefaultValue() != ""; |
| 83 | } | ||
| 84 | 3 | return hasDefaultValue; | |
| 85 | } | ||
| 86 | |||
| 87 | ///Saves the destructor, copy constructor/assignment and move constructor/assignment of a class owning at least one raw pointer attribute | ||
| 88 | /** A class with a raw pointer attribute cannot rely on the compiler-generated (`=default`) special members : the default copy/move would only | ||
| 89 | * copy the pointer value (shallow copy), leading to double-delete once the hand-written destructor frees it. Per the rule of five, all five | ||
| 90 | * special members (destructor, copy ctor/assign, move ctor/assign) are generated by hand for these classes. | ||
| 91 | * @param[out] fs : header file name | ||
| 92 | * @param classConfig : PClassConfig we vant to save | ||
| 93 | * @param defTemplate : extra template definition for the class name space | ||
| 94 | * @param templateDeclaration : basic template declaration before each method (template< ... >) | ||
| 95 | */ | ||
| 96 | 8 | void class_savePointerOwnershipSpecialMembersImpl(std::ofstream & fs, const PClassConfig & classConfig, const PString & defTemplate, const PString & templateDeclaration){ | |
| 97 |
3/3✓ Branch 0 (2→3) taken 8 times.
✓ Branch 2 (3→4) taken 7 times.
✓ Branch 3 (3→5) taken 1 times.
|
8 | if(!class_hasPointerAttribute(classConfig)){return;} |
| 98 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | PString name(classConfig.getName()); |
| 99 |
1/1✓ Branch 0 (7→8) taken 1 times.
|
1 | const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute()); |
| 100 | |||
| 101 | ///Destructor | ||
| 102 |
3/3✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
|
1 | fs << "///Destructor of class " << name << std::endl; |
| 103 |
1/1✓ Branch 0 (11→12) taken 1 times.
|
1 | fs << templateDeclaration; |
| 104 |
6/6✓ Branch 0 (12→13) taken 1 times.
✓ Branch 2 (13→14) taken 1 times.
✓ Branch 4 (14→15) taken 1 times.
✓ Branch 6 (15→16) taken 1 times.
✓ Branch 8 (16→17) taken 1 times.
✓ Branch 10 (17→18) taken 1 times.
|
1 | fs << name << defTemplate << "::~" << name << "(){" << std::endl; |
| 105 |
2/2✓ Branch 0 (41→19) taken 3 times.
✓ Branch 1 (41→42) taken 1 times.
|
8 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 106 |
4/4✓ Branch 0 (21→22) taken 3 times.
✓ Branch 2 (22→23) taken 3 times.
✓ Branch 4 (23→24) taken 1 times.
✓ Branch 5 (23→31) taken 2 times.
|
3 | if(getIsPointerType(it->getType())){ |
| 107 |
5/5✓ Branch 0 (24→25) taken 1 times.
✓ Branch 2 (27→28) taken 1 times.
✓ Branch 4 (28→29) taken 1 times.
✓ Branch 6 (29→30) taken 1 times.
✓ Branch 8 (30→31) taken 1 times.
|
2 | fs << "\tdelete p_" << it->getName() << ";" << std::endl; |
| 108 | } | ||
| 109 | } | ||
| 110 |
3/3✓ Branch 0 (42→43) taken 1 times.
✓ Branch 2 (43→44) taken 1 times.
✓ Branch 4 (44→45) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 111 | |||
| 112 | ///Copy constructor | ||
| 113 |
3/3✓ Branch 0 (45→46) taken 1 times.
✓ Branch 2 (46→47) taken 1 times.
✓ Branch 4 (47→48) taken 1 times.
|
1 | fs << "///Copy constructor of class " << name << std::endl; |
| 114 |
4/4✓ Branch 0 (48→49) taken 1 times.
✓ Branch 2 (49→50) taken 1 times.
✓ Branch 4 (50→51) taken 1 times.
✓ Branch 6 (51→52) taken 1 times.
|
1 | fs << "/**\t@param other : " << name << " we want to copy" << std::endl; |
| 115 |
2/2✓ Branch 0 (52→53) taken 1 times.
✓ Branch 2 (53→54) taken 1 times.
|
1 | fs << "*/" << std::endl; |
| 116 |
1/1✓ Branch 0 (54→55) taken 1 times.
|
1 | fs << templateDeclaration; |
| 117 |
8/8✓ Branch 0 (55→56) taken 1 times.
✓ Branch 2 (56→57) taken 1 times.
✓ Branch 4 (57→58) taken 1 times.
✓ Branch 6 (58→59) taken 1 times.
✓ Branch 8 (59→60) taken 1 times.
✓ Branch 10 (60→61) taken 1 times.
✓ Branch 12 (61→62) taken 1 times.
✓ Branch 14 (62→63) taken 1 times.
|
1 | fs << name << defTemplate << "::" << name << "(const " << name << defTemplate << " & other)"; |
| 118 |
1/1✓ Branch 0 (63→64) taken 1 times.
|
1 | PString initListComma(" : "); |
| 119 |
2/2✓ Branch 0 (88→65) taken 3 times.
✓ Branch 1 (88→89) taken 1 times.
|
8 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 120 |
4/4✓ Branch 0 (67→68) taken 3 times.
✓ Branch 2 (68→69) taken 3 times.
✓ Branch 4 (69→70) taken 1 times.
✓ Branch 5 (69→78) taken 2 times.
|
3 | if(getIsPointerType(it->getType())){ |
| 121 |
5/5✓ Branch 0 (70→71) taken 1 times.
✓ Branch 2 (71→72) taken 1 times.
✓ Branch 4 (74→75) taken 1 times.
✓ Branch 6 (75→76) taken 1 times.
✓ Branch 8 (76→77) taken 1 times.
|
2 | fs << initListComma << "p_" << it->getName() << "(NULL)"; |
| 122 |
1/1✓ Branch 0 (77→78) taken 1 times.
|
1 | initListComma = ", "; |
| 123 | } | ||
| 124 | } | ||
| 125 |
2/2✓ Branch 0 (89→90) taken 1 times.
✓ Branch 2 (90→91) taken 1 times.
|
1 | fs << "{" << std::endl; |
| 126 |
4/4✓ Branch 0 (91→92) taken 1 times.
✓ Branch 2 (92→93) taken 1 times.
✓ Branch 4 (93→94) taken 1 times.
✓ Branch 6 (94→95) taken 1 times.
|
1 | fs << "\tcopy" << name << "(other);" << std::endl; |
| 127 |
3/3✓ Branch 0 (95→96) taken 1 times.
✓ Branch 2 (96→97) taken 1 times.
✓ Branch 4 (97→98) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 128 | |||
| 129 | ///Copy assignment operator | ||
| 130 |
3/3✓ Branch 0 (98→99) taken 1 times.
✓ Branch 2 (99→100) taken 1 times.
✓ Branch 4 (100→101) taken 1 times.
|
1 | fs << "///Copy assignment operator of class " << name << std::endl; |
| 131 |
4/4✓ Branch 0 (101→102) taken 1 times.
✓ Branch 2 (102→103) taken 1 times.
✓ Branch 4 (103→104) taken 1 times.
✓ Branch 6 (104→105) taken 1 times.
|
1 | fs << "/**\t@param other : " << name << " we want to copy" << std::endl; |
| 132 |
3/3✓ Branch 0 (105→106) taken 1 times.
✓ Branch 2 (106→107) taken 1 times.
✓ Branch 4 (107→108) taken 1 times.
|
1 | fs << " * \t@return copied class " << name << std::endl; |
| 133 |
2/2✓ Branch 0 (108→109) taken 1 times.
✓ Branch 2 (109→110) taken 1 times.
|
1 | fs << "*/" << std::endl; |
| 134 |
1/1✓ Branch 0 (110→111) taken 1 times.
|
1 | fs << templateDeclaration; |
| 135 |
10/10✓ Branch 0 (111→112) taken 1 times.
✓ Branch 2 (112→113) taken 1 times.
✓ Branch 4 (113→114) taken 1 times.
✓ Branch 6 (114→115) taken 1 times.
✓ Branch 8 (115→116) taken 1 times.
✓ Branch 10 (116→117) taken 1 times.
✓ Branch 12 (117→118) taken 1 times.
✓ Branch 14 (118→119) taken 1 times.
✓ Branch 16 (119→120) taken 1 times.
✓ Branch 18 (120→121) taken 1 times.
|
1 | fs << name << defTemplate << " & " << name << defTemplate << "::operator = (const " << name << defTemplate << " & other){" << std::endl; |
| 136 |
4/4✓ Branch 0 (121→122) taken 1 times.
✓ Branch 2 (122→123) taken 1 times.
✓ Branch 4 (123→124) taken 1 times.
✓ Branch 6 (124→125) taken 1 times.
|
1 | fs << "\tcopy" << name << "(other);" << std::endl; |
| 137 |
2/2✓ Branch 0 (125→126) taken 1 times.
✓ Branch 2 (126→127) taken 1 times.
|
1 | fs << "\treturn *this;" << std::endl; |
| 138 |
3/3✓ Branch 0 (127→128) taken 1 times.
✓ Branch 2 (128→129) taken 1 times.
✓ Branch 4 (129→130) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 139 | |||
| 140 | ///Copy helper, reused by the copy constructor and the copy assignment operator | ||
| 141 |
3/3✓ Branch 0 (130→131) taken 1 times.
✓ Branch 2 (131→132) taken 1 times.
✓ Branch 4 (132→133) taken 1 times.
|
1 | fs << "///Copy the attributes of class " << name << std::endl; |
| 142 |
4/4✓ Branch 0 (133→134) taken 1 times.
✓ Branch 2 (134→135) taken 1 times.
✓ Branch 4 (135→136) taken 1 times.
✓ Branch 6 (136→137) taken 1 times.
|
1 | fs << "/**\t@param other : " << name << " we want to copy" << std::endl; |
| 143 |
2/2✓ Branch 0 (137→138) taken 1 times.
✓ Branch 2 (138→139) taken 1 times.
|
1 | fs << "*/" << std::endl; |
| 144 |
1/1✓ Branch 0 (139→140) taken 1 times.
|
1 | fs << templateDeclaration; |
| 145 |
10/10✓ Branch 0 (140→141) taken 1 times.
✓ Branch 2 (141→142) taken 1 times.
✓ Branch 4 (142→143) taken 1 times.
✓ Branch 6 (143→144) taken 1 times.
✓ Branch 8 (144→145) taken 1 times.
✓ Branch 10 (145→146) taken 1 times.
✓ Branch 12 (146→147) taken 1 times.
✓ Branch 14 (147→148) taken 1 times.
✓ Branch 16 (148→149) taken 1 times.
✓ Branch 18 (149→150) taken 1 times.
|
1 | fs << "void " << name << defTemplate << "::copy" << name << "(const " << name << defTemplate << " & other){" << std::endl; |
| 146 |
2/2✓ Branch 0 (150→151) taken 1 times.
✓ Branch 2 (151→152) taken 1 times.
|
1 | fs << "\tif(this == &other){return;}" << std::endl; |
| 147 |
2/2✓ Branch 0 (214→153) taken 3 times.
✓ Branch 1 (214→215) taken 1 times.
|
8 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 148 |
4/4✓ Branch 0 (155→156) taken 3 times.
✓ Branch 2 (156→157) taken 3 times.
✓ Branch 4 (157→158) taken 1 times.
✓ Branch 5 (157→192) taken 2 times.
|
3 | if(getIsPointerType(it->getType())){ |
| 149 |
3/3✓ Branch 0 (160→161) taken 1 times.
✓ Branch 2 (161→162) taken 1 times.
✓ Branch 4 (162→163) taken 1 times.
|
2 | PString pointeeType(it->getType().eraseFirstLastChar(" \n\t*")); |
| 150 |
5/5✓ Branch 0 (164→165) taken 1 times.
✓ Branch 2 (167→168) taken 1 times.
✓ Branch 4 (168→169) taken 1 times.
✓ Branch 6 (169→170) taken 1 times.
✓ Branch 8 (170→171) taken 1 times.
|
2 | fs << "\tdelete p_" << it->getName() << ";" << std::endl; |
| 151 |
13/13✓ Branch 0 (171→172) taken 1 times.
✓ Branch 2 (174→175) taken 1 times.
✓ Branch 4 (175→176) taken 1 times.
✓ Branch 6 (176→177) taken 1 times.
✓ Branch 8 (179→180) taken 1 times.
✓ Branch 10 (180→181) taken 1 times.
✓ Branch 12 (181→182) taken 1 times.
✓ Branch 14 (182→183) taken 1 times.
✓ Branch 16 (183→184) taken 1 times.
✓ Branch 18 (186→187) taken 1 times.
✓ Branch 20 (187→188) taken 1 times.
✓ Branch 22 (188→189) taken 1 times.
✓ Branch 24 (189→190) taken 1 times.
|
4 | fs << "\tp_" << it->getName() << " = other.p_" << it->getName() << " ? new " << pointeeType << "(*other.p_" << it->getName() << ") : NULL;" << std::endl; |
| 152 | 1 | }else{ | |
| 153 |
8/8✓ Branch 0 (192→193) taken 2 times.
✓ Branch 2 (195→196) taken 2 times.
✓ Branch 4 (196→197) taken 2 times.
✓ Branch 6 (197→198) taken 2 times.
✓ Branch 8 (200→201) taken 2 times.
✓ Branch 10 (201→202) taken 2 times.
✓ Branch 12 (202→203) taken 2 times.
✓ Branch 14 (203→204) taken 2 times.
|
6 | fs << "\tp_" << it->getName() << " = other.p_" << it->getName() << ";" << std::endl; |
| 154 | } | ||
| 155 | } | ||
| 156 |
3/3✓ Branch 0 (215→216) taken 1 times.
✓ Branch 2 (216→217) taken 1 times.
✓ Branch 4 (217→218) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 157 | |||
| 158 | ///Move constructor | ||
| 159 |
3/3✓ Branch 0 (218→219) taken 1 times.
✓ Branch 2 (219→220) taken 1 times.
✓ Branch 4 (220→221) taken 1 times.
|
1 | fs << "///Move constructor of class " << name << std::endl; |
| 160 |
4/4✓ Branch 0 (221→222) taken 1 times.
✓ Branch 2 (222→223) taken 1 times.
✓ Branch 4 (223→224) taken 1 times.
✓ Branch 6 (224→225) taken 1 times.
|
1 | fs << "/**\t@param other : " << name << " we want to move" << std::endl; |
| 161 |
2/2✓ Branch 0 (225→226) taken 1 times.
✓ Branch 2 (226→227) taken 1 times.
|
1 | fs << "*/" << std::endl; |
| 162 |
1/1✓ Branch 0 (227→228) taken 1 times.
|
1 | fs << templateDeclaration; |
| 163 |
8/8✓ Branch 0 (228→229) taken 1 times.
✓ Branch 2 (229→230) taken 1 times.
✓ Branch 4 (230→231) taken 1 times.
✓ Branch 6 (231→232) taken 1 times.
✓ Branch 8 (232→233) taken 1 times.
✓ Branch 10 (233→234) taken 1 times.
✓ Branch 12 (234→235) taken 1 times.
✓ Branch 14 (235→236) taken 1 times.
|
1 | fs << name << defTemplate << "::" << name << "(" << name << defTemplate << " && other) noexcept"; |
| 164 |
1/1✓ Branch 0 (236→237) taken 1 times.
|
1 | initListComma = " : "; |
| 165 |
2/2✓ Branch 0 (261→238) taken 3 times.
✓ Branch 1 (261→262) taken 1 times.
|
8 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 166 |
4/4✓ Branch 0 (240→241) taken 3 times.
✓ Branch 2 (241→242) taken 3 times.
✓ Branch 4 (242→243) taken 1 times.
✓ Branch 5 (242→251) taken 2 times.
|
3 | if(getIsPointerType(it->getType())){ |
| 167 |
5/5✓ Branch 0 (243→244) taken 1 times.
✓ Branch 2 (244→245) taken 1 times.
✓ Branch 4 (247→248) taken 1 times.
✓ Branch 6 (248→249) taken 1 times.
✓ Branch 8 (249→250) taken 1 times.
|
2 | fs << initListComma << "p_" << it->getName() << "(NULL)"; |
| 168 |
1/1✓ Branch 0 (250→251) taken 1 times.
|
1 | initListComma = ", "; |
| 169 | } | ||
| 170 | } | ||
| 171 |
2/2✓ Branch 0 (262→263) taken 1 times.
✓ Branch 2 (263→264) taken 1 times.
|
1 | fs << "{" << std::endl; |
| 172 |
4/4✓ Branch 0 (264→265) taken 1 times.
✓ Branch 2 (265→266) taken 1 times.
✓ Branch 4 (266→267) taken 1 times.
✓ Branch 6 (267→268) taken 1 times.
|
1 | fs << "\tmove" << name << "(std::move(other));" << std::endl; |
| 173 |
3/3✓ Branch 0 (268→269) taken 1 times.
✓ Branch 2 (269→270) taken 1 times.
✓ Branch 4 (270→271) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 174 | |||
| 175 | ///Move assignment operator | ||
| 176 |
3/3✓ Branch 0 (271→272) taken 1 times.
✓ Branch 2 (272→273) taken 1 times.
✓ Branch 4 (273→274) taken 1 times.
|
1 | fs << "///Move assignment operator of class " << name << std::endl; |
| 177 |
4/4✓ Branch 0 (274→275) taken 1 times.
✓ Branch 2 (275→276) taken 1 times.
✓ Branch 4 (276→277) taken 1 times.
✓ Branch 6 (277→278) taken 1 times.
|
1 | fs << "/**\t@param other : " << name << " we want to move" << std::endl; |
| 178 |
3/3✓ Branch 0 (278→279) taken 1 times.
✓ Branch 2 (279→280) taken 1 times.
✓ Branch 4 (280→281) taken 1 times.
|
1 | fs << " * \t@return moved class " << name << std::endl; |
| 179 |
2/2✓ Branch 0 (281→282) taken 1 times.
✓ Branch 2 (282→283) taken 1 times.
|
1 | fs << "*/" << std::endl; |
| 180 |
1/1✓ Branch 0 (283→284) taken 1 times.
|
1 | fs << templateDeclaration; |
| 181 |
10/10✓ Branch 0 (284→285) taken 1 times.
✓ Branch 2 (285→286) taken 1 times.
✓ Branch 4 (286→287) taken 1 times.
✓ Branch 6 (287→288) taken 1 times.
✓ Branch 8 (288→289) taken 1 times.
✓ Branch 10 (289→290) taken 1 times.
✓ Branch 12 (290→291) taken 1 times.
✓ Branch 14 (291→292) taken 1 times.
✓ Branch 16 (292→293) taken 1 times.
✓ Branch 18 (293→294) taken 1 times.
|
1 | fs << name << defTemplate << " & " << name << defTemplate << "::operator = (" << name << defTemplate << " && other) noexcept{" << std::endl; |
| 182 |
4/4✓ Branch 0 (294→295) taken 1 times.
✓ Branch 2 (295→296) taken 1 times.
✓ Branch 4 (296→297) taken 1 times.
✓ Branch 6 (297→298) taken 1 times.
|
1 | fs << "\tmove" << name << "(std::move(other));" << std::endl; |
| 183 |
2/2✓ Branch 0 (298→299) taken 1 times.
✓ Branch 2 (299→300) taken 1 times.
|
1 | fs << "\treturn *this;" << std::endl; |
| 184 |
3/3✓ Branch 0 (300→301) taken 1 times.
✓ Branch 2 (301→302) taken 1 times.
✓ Branch 4 (302→303) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 185 | |||
| 186 | ///Move helper, reused by the move constructor and the move assignment operator | ||
| 187 |
3/3✓ Branch 0 (303→304) taken 1 times.
✓ Branch 2 (304→305) taken 1 times.
✓ Branch 4 (305→306) taken 1 times.
|
1 | fs << "///Move the attributes of class " << name << std::endl; |
| 188 |
4/4✓ Branch 0 (306→307) taken 1 times.
✓ Branch 2 (307→308) taken 1 times.
✓ Branch 4 (308→309) taken 1 times.
✓ Branch 6 (309→310) taken 1 times.
|
1 | fs << "/**\t@param other : " << name << " we want to move" << std::endl; |
| 189 |
2/2✓ Branch 0 (310→311) taken 1 times.
✓ Branch 2 (311→312) taken 1 times.
|
1 | fs << "*/" << std::endl; |
| 190 |
1/1✓ Branch 0 (312→313) taken 1 times.
|
1 | fs << templateDeclaration; |
| 191 |
10/10✓ Branch 0 (313→314) taken 1 times.
✓ Branch 2 (314→315) taken 1 times.
✓ Branch 4 (315→316) taken 1 times.
✓ Branch 6 (316→317) taken 1 times.
✓ Branch 8 (317→318) taken 1 times.
✓ Branch 10 (318→319) taken 1 times.
✓ Branch 12 (319→320) taken 1 times.
✓ Branch 14 (320→321) taken 1 times.
✓ Branch 16 (321→322) taken 1 times.
✓ Branch 18 (322→323) taken 1 times.
|
1 | fs << "void " << name << defTemplate << "::move" << name << "(" << name << defTemplate << " && other){" << std::endl; |
| 192 |
2/2✓ Branch 0 (323→324) taken 1 times.
✓ Branch 2 (324→325) taken 1 times.
|
1 | fs << "\tif(this == &other){return;}" << std::endl; |
| 193 |
2/2✓ Branch 0 (379→326) taken 3 times.
✓ Branch 1 (379→380) taken 1 times.
|
8 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 194 |
4/4✓ Branch 0 (328→329) taken 3 times.
✓ Branch 2 (329→330) taken 3 times.
✓ Branch 4 (330→331) taken 1 times.
✓ Branch 5 (330→357) taken 2 times.
|
3 | if(getIsPointerType(it->getType())){ |
| 195 |
5/5✓ Branch 0 (331→332) taken 1 times.
✓ Branch 2 (334→335) taken 1 times.
✓ Branch 4 (335→336) taken 1 times.
✓ Branch 6 (336→337) taken 1 times.
✓ Branch 8 (337→338) taken 1 times.
|
2 | fs << "\tdelete p_" << it->getName() << ";" << std::endl; |
| 196 |
8/8✓ Branch 0 (338→339) taken 1 times.
✓ Branch 2 (341→342) taken 1 times.
✓ Branch 4 (342→343) taken 1 times.
✓ Branch 6 (343→344) taken 1 times.
✓ Branch 8 (346→347) taken 1 times.
✓ Branch 10 (347→348) taken 1 times.
✓ Branch 12 (348→349) taken 1 times.
✓ Branch 14 (349→350) taken 1 times.
|
3 | fs << "\tp_" << it->getName() << " = other.p_" << it->getName() << ";" << std::endl; |
| 197 |
5/5✓ Branch 0 (350→351) taken 1 times.
✓ Branch 2 (353→354) taken 1 times.
✓ Branch 4 (354→355) taken 1 times.
✓ Branch 6 (355→356) taken 1 times.
✓ Branch 8 (356→369) taken 1 times.
|
2 | fs << "\tother.p_" << it->getName() << " = NULL;" << std::endl; |
| 198 | }else{ | ||
| 199 |
8/8✓ Branch 0 (357→358) taken 2 times.
✓ Branch 2 (360→361) taken 2 times.
✓ Branch 4 (361→362) taken 2 times.
✓ Branch 6 (362→363) taken 2 times.
✓ Branch 8 (365→366) taken 2 times.
✓ Branch 10 (366→367) taken 2 times.
✓ Branch 12 (367→368) taken 2 times.
✓ Branch 14 (368→369) taken 2 times.
|
6 | fs << "\tp_" << it->getName() << " = std::move(other.p_" << it->getName() << ");" << std::endl; |
| 200 | } | ||
| 201 | } | ||
| 202 |
3/3✓ Branch 0 (380→381) taken 1 times.
✓ Branch 2 (381→382) taken 1 times.
✓ Branch 4 (382→383) taken 1 times.
|
1 | fs << "}" << std::endl << std::endl; |
| 203 | 1 | } | |
| 204 | |||
| 205 | ///Create the declaration of the given class | ||
| 206 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 207 | * @param[out] fs : file to be completed | ||
| 208 | * @param classConfig : configuration of the class to be used | ||
| 209 | * @param mode : mode of the generator | ||
| 210 | */ | ||
| 211 | 3 | void generator_enum_cpp_header(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 212 |
6/7✓ Branch 0 (2→3) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
✓ Branch 4 (4→5) taken 3 times.
✗ Branch 5 (4→8) not taken.
✓ Branch 6 (5→6) taken 3 times.
✓ Branch 8 (6→7) taken 3 times.
✓ Branch 10 (7→8) taken 3 times.
|
3 | if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl; |
| 213 |
2/2✓ Branch 0 (8→9) taken 3 times.
✓ Branch 2 (9→10) taken 3 times.
|
3 | PString name(classConfig.getName()); |
| 214 |
3/3✓ Branch 0 (10→11) taken 3 times.
✓ Branch 2 (11→12) taken 3 times.
✓ Branch 4 (12→13) taken 3 times.
|
3 | fs << "namespace " << name << " {\n"; |
| 215 |
7/8✓ Branch 0 (13→14) taken 3 times.
✓ Branch 2 (14→15) taken 3 times.
✓ Branch 4 (15→16) taken 3 times.
✗ Branch 5 (15→20) not taken.
✓ Branch 6 (16→17) taken 3 times.
✓ Branch 8 (17→18) taken 3 times.
✓ Branch 10 (18→19) taken 3 times.
✓ Branch 12 (19→20) taken 3 times.
|
3 | if(classConfig.getClassDocumentation() != ""){fs << "\t"<< classConfig.getClassDocumentation() << std::endl;} |
| 216 |
3/3✓ Branch 0 (20→21) taken 3 times.
✓ Branch 2 (21→22) taken 3 times.
✓ Branch 4 (22→23) taken 3 times.
|
3 | fs << "\tenum " << name << " {\n\t\t"; |
| 217 |
1/1✓ Branch 0 (23→24) taken 3 times.
|
3 | const std::vector<PClassAttribute> & vecAttr(classConfig.getListAttribute()); |
| 218 |
1/1✓ Branch 0 (24→25) taken 3 times.
|
3 | bool isDefaultCounterActivated = !generator_checkDefaultValueExist(vecAttr); |
| 219 |
1/1✓ Branch 0 (25→26) taken 3 times.
|
3 | PString comma(""); |
| 220 | 3 | size_t i(0LU); | |
| 221 |
2/2✓ Branch 0 (67→27) taken 6 times.
✓ Branch 1 (67→68) taken 3 times.
|
18 | for(std::vector<PClassAttribute>::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){ |
| 222 |
3/8✓ Branch 0 (29→30) taken 6 times.
✓ Branch 2 (30→31) taken 6 times.
✗ Branch 4 (31→32) not taken.
✓ Branch 5 (31→38) taken 6 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.
|
6 | if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl; |
| 223 |
3/3✓ Branch 0 (38→39) taken 6 times.
✓ Branch 2 (41→42) taken 6 times.
✓ Branch 4 (42→43) taken 6 times.
|
12 | fs << comma << it->getName(); |
| 224 |
1/2✓ Branch 0 (43→44) taken 6 times.
✗ Branch 1 (43→46) not taken.
|
6 | if(isDefaultCounterActivated){ |
| 225 |
2/2✓ Branch 0 (44→45) taken 6 times.
✓ Branch 2 (45→56) taken 6 times.
|
6 | fs << " = " << i; |
| 226 | ✗ | }else if(it->getDefaultValue() != ""){ | |
| 227 | ✗ | fs << " = " << it->getDefaultValue(); | |
| 228 | } | ||
| 229 |
1/1✓ Branch 0 (56→57) taken 6 times.
|
6 | comma = ",\n\t\t"; |
| 230 | 6 | ++i; | |
| 231 | } | ||
| 232 |
2/2✓ Branch 0 (68→69) taken 3 times.
✓ Branch 2 (69→70) taken 3 times.
|
3 | fs << "\n\t};" << std::endl; |
| 233 |
3/3✓ Branch 0 (70→71) taken 3 times.
✓ Branch 2 (71→72) taken 3 times.
✓ Branch 4 (72→73) taken 3 times.
|
3 | fs << "}" << std::endl << std::endl; |
| 234 |
1/1✓ Branch 0 (73→74) taken 3 times.
|
3 | manager.classExtraFunctionDeclaration(fs, classConfig, mode); |
| 235 |
2/2✓ Branch 0 (74→75) taken 3 times.
✓ Branch 2 (75→76) taken 3 times.
|
3 | fs << std::endl << std::endl; |
| 236 | 3 | } | |
| 237 | |||
| 238 | |||
| 239 | ///Create the declaration of the given class | ||
| 240 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 241 | * @param[out] fs : file to be completed | ||
| 242 | * @param classConfig : configuration of the class to be used | ||
| 243 | * @param mode : mode of the generator | ||
| 244 | */ | ||
| 245 | 8 | void generator_class_cpp_header(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 246 |
6/7✓ Branch 0 (2→3) taken 8 times.
✓ Branch 2 (3→4) taken 8 times.
✓ Branch 4 (4→5) taken 8 times.
✗ Branch 5 (4→8) not taken.
✓ Branch 6 (5→6) taken 8 times.
✓ Branch 8 (6→7) taken 8 times.
✓ Branch 10 (7→8) taken 8 times.
|
8 | if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl; |
| 247 |
2/2✓ Branch 0 (8→9) taken 8 times.
✓ Branch 2 (9→10) taken 8 times.
|
8 | PString name(classConfig.getName()); |
| 248 |
2/2✓ Branch 0 (10→11) taken 8 times.
✓ Branch 2 (11→12) taken 8 times.
|
8 | PString namespaceName(classConfig.getNamespace()); |
| 249 |
1/1✓ Branch 0 (12→13) taken 8 times.
|
8 | GeneratorMode classMode(mode); |
| 250 |
1/1✓ Branch 0 (13→14) taken 8 times.
|
8 | const PVecString & listTemplate = classConfig.getListTemplate(); |
| 251 |
1/1✓ Branch 0 (14→15) taken 8 times.
|
8 | PString defTemplate(class_getClassDefTemplate(listTemplate)); |
| 252 |
1/1✓ Branch 0 (15→16) taken 8 times.
|
8 | PString templateDeclaration(class_getClassDeclTempalteDef(listTemplate)); |
| 253 |
1/1✓ Branch 0 (16→17) taken 8 times.
|
8 | classMode.defTemplate = defTemplate; |
| 254 |
1/1✓ Branch 0 (17→18) taken 8 times.
|
8 | classMode.templateDeclaration = templateDeclaration; |
| 255 | |||
| 256 |
1/1✓ Branch 0 (18→19) taken 8 times.
|
8 | fs << classMode.templateDeclaration; |
| 257 |
1/1✓ Branch 0 (19→20) taken 8 times.
|
8 | fs << "class "; |
| 258 |
2/3✓ Branch 0 (20→21) taken 8 times.
✗ Branch 2 (21→22) not taken.
✓ Branch 3 (21→24) taken 8 times.
|
8 | if(namespaceName != ""){ |
| 259 | ✗ | fs << namespaceName << "::"; | |
| 260 | } | ||
| 261 |
1/1✓ Branch 0 (24→25) taken 8 times.
|
8 | fs << name; |
| 262 |
2/3✓ Branch 0 (25→26) taken 8 times.
✗ Branch 2 (27→28) not taken.
✓ Branch 3 (27→55) taken 8 times.
|
8 | if(classConfig.getListParentClass().size() != 0LU){ |
| 263 | ✗ | PVecString::const_iterator it(classConfig.getListParentClass().begin()); | |
| 264 | ✗ | fs << " : public " << *it; | |
| 265 | ✗ | if(classConfig.getListParentClass().size() > 1lu){ | |
| 266 | ✗ | while(it != classConfig.getListParentClass().end()){ | |
| 267 | ✗ | fs << ", " << *it; | |
| 268 | ++it; | ||
| 269 | } | ||
| 270 | } | ||
| 271 | } | ||
| 272 |
1/1✓ Branch 0 (55→56) taken 8 times.
|
8 | bool hasPointerAttribute(class_hasPointerAttribute(classConfig)); |
| 273 |
2/2✓ Branch 0 (56→57) taken 8 times.
✓ Branch 2 (57→58) taken 8 times.
|
8 | fs << "{" << std::endl; |
| 274 |
2/2✓ Branch 0 (58→59) taken 8 times.
✓ Branch 2 (59→60) taken 8 times.
|
8 | fs << "\tpublic:" << std::endl; |
| 275 |
4/4✓ Branch 0 (60→61) taken 8 times.
✓ Branch 2 (61→62) taken 8 times.
✓ Branch 4 (62→63) taken 8 times.
✓ Branch 6 (63→64) taken 8 times.
|
8 | fs << "\t\t" << name << "() = default;" << std::endl; |
| 276 |
2/2✓ Branch 0 (64→65) taken 1 times.
✓ Branch 1 (64→93) taken 7 times.
|
8 | if(hasPointerAttribute){ |
| 277 | //A raw pointer attribute cannot be safely copied/moved by the compiler-generated special members (shallow copy/move would double-delete) : | ||
| 278 | //DataStream has no shared_ptr/unique_ptr specialisation, so ownership is a raw pointer and all five special members must be hand-written (rule of five). | ||
| 279 |
4/4✓ Branch 0 (65→66) taken 1 times.
✓ Branch 2 (66→67) taken 1 times.
✓ Branch 4 (67→68) taken 1 times.
✓ Branch 6 (68→69) taken 1 times.
|
1 | fs << "\t\tvirtual ~" << name << "();" << std::endl; |
| 280 |
6/6✓ Branch 0 (69→70) taken 1 times.
✓ Branch 2 (70→71) taken 1 times.
✓ Branch 4 (71→72) taken 1 times.
✓ Branch 6 (72→73) taken 1 times.
✓ Branch 8 (73→74) taken 1 times.
✓ Branch 10 (74→75) taken 1 times.
|
1 | fs << "\t\t" << name << "(const " << name << " &);" << std::endl; |
| 281 |
6/6✓ Branch 0 (75→76) taken 1 times.
✓ Branch 2 (76→77) taken 1 times.
✓ Branch 4 (77→78) taken 1 times.
✓ Branch 6 (78→79) taken 1 times.
✓ Branch 8 (79→80) taken 1 times.
✓ Branch 10 (80→81) taken 1 times.
|
1 | fs << "\t\t" << name << " & operator = (const " << name << " &);" << std::endl; |
| 282 |
6/6✓ Branch 0 (81→82) taken 1 times.
✓ Branch 2 (82→83) taken 1 times.
✓ Branch 4 (83→84) taken 1 times.
✓ Branch 6 (84→85) taken 1 times.
✓ Branch 8 (85→86) taken 1 times.
✓ Branch 10 (86→87) taken 1 times.
|
1 | fs << "\t\t" << name << "(" << name << " &&) noexcept;" << std::endl; |
| 283 |
6/6✓ Branch 0 (87→88) taken 1 times.
✓ Branch 2 (88→89) taken 1 times.
✓ Branch 4 (89→90) taken 1 times.
✓ Branch 6 (90→91) taken 1 times.
✓ Branch 8 (91→92) taken 1 times.
✓ Branch 10 (92→121) taken 1 times.
|
1 | fs << "\t\t" << name << " & operator = (" << name << " &&) noexcept;" << std::endl; |
| 284 | }else{ | ||
| 285 |
4/4✓ Branch 0 (93→94) taken 7 times.
✓ Branch 2 (94→95) taken 7 times.
✓ Branch 4 (95→96) taken 7 times.
✓ Branch 6 (96→97) taken 7 times.
|
7 | fs << "\t\tvirtual ~" << name << "() = default;" << std::endl; |
| 286 | //A user-declared destructor suppresses the implicitly-declared copy/move constructor and assignment : redeclare all four as defaulted. | ||
| 287 |
6/6✓ Branch 0 (97→98) taken 7 times.
✓ Branch 2 (98→99) taken 7 times.
✓ Branch 4 (99→100) taken 7 times.
✓ Branch 6 (100→101) taken 7 times.
✓ Branch 8 (101→102) taken 7 times.
✓ Branch 10 (102→103) taken 7 times.
|
7 | fs << "\t\t" << name << "(const " << name << " &) = default;" << std::endl; |
| 288 |
6/6✓ Branch 0 (103→104) taken 7 times.
✓ Branch 2 (104→105) taken 7 times.
✓ Branch 4 (105→106) taken 7 times.
✓ Branch 6 (106→107) taken 7 times.
✓ Branch 8 (107→108) taken 7 times.
✓ Branch 10 (108→109) taken 7 times.
|
7 | fs << "\t\t" << name << " & operator = (const " << name << " &) = default;" << std::endl; |
| 289 |
6/6✓ Branch 0 (109→110) taken 7 times.
✓ Branch 2 (110→111) taken 7 times.
✓ Branch 4 (111→112) taken 7 times.
✓ Branch 6 (112→113) taken 7 times.
✓ Branch 8 (113→114) taken 7 times.
✓ Branch 10 (114→115) taken 7 times.
|
7 | fs << "\t\t" << name << "(" << name << " &&) = default;" << std::endl; |
| 290 |
6/6✓ Branch 0 (115→116) taken 7 times.
✓ Branch 2 (116→117) taken 7 times.
✓ Branch 4 (117→118) taken 7 times.
✓ Branch 6 (118→119) taken 7 times.
✓ Branch 8 (119→120) taken 7 times.
✓ Branch 10 (120→121) taken 7 times.
|
7 | fs << "\t\t" << name << " & operator = (" << name << " &&) = default;" << std::endl; |
| 291 | } | ||
| 292 | |||
| 293 |
1/1✓ Branch 0 (121→122) taken 8 times.
|
8 | manager.publicMethodDeclaration(fs, classConfig, classMode); |
| 294 | |||
| 295 | //Trait backends write to an std::ofstream& : capture their output into a string buffer first (via a buffer swap, no actual file involved) | ||
| 296 | //so the "protected:" label is only emitted when there is something to put under it, instead of leaving an empty access-specifier section. | ||
| 297 |
1/1✓ Branch 0 (122→123) taken 8 times.
|
8 | std::ostringstream protectedContentBuf; |
| 298 |
1/1✓ Branch 0 (123→124) taken 8 times.
|
8 | std::ofstream protectedCapture; |
| 299 | //basic_ofstream declares its own 0-arg rdbuf() (returning the internal filebuf), which hides the inherited basic_ios::rdbuf(streambuf*) setter : | ||
| 300 | //go through the std::ostream base to reach the setter and redirect writes into a string buffer without opening any file. | ||
| 301 |
1/1✓ Branch 0 (125→126) taken 8 times.
|
8 | static_cast<std::ostream &>(protectedCapture).rdbuf(protectedContentBuf.rdbuf()); |
| 302 |
1/1✓ Branch 0 (126→127) taken 8 times.
|
8 | manager.protectedMethodDeclaration(protectedCapture, classConfig, classMode); |
| 303 |
2/2✓ Branch 0 (127→128) taken 8 times.
✓ Branch 2 (128→129) taken 8 times.
|
8 | PString protectedContent(protectedContentBuf.str()); |
| 304 |
7/7✓ Branch 0 (130→131) taken 7 times.
✓ Branch 1 (130→133) taken 1 times.
✓ Branch 2 (131→132) taken 7 times.
✓ Branch 4 (132→133) taken 6 times.
✓ Branch 5 (132→134) taken 1 times.
✓ Branch 6 (135→136) taken 7 times.
✓ Branch 7 (135→152) taken 1 times.
|
8 | if(hasPointerAttribute || protectedContent != ""){ |
| 305 |
2/2✓ Branch 0 (136→137) taken 7 times.
✓ Branch 2 (137→138) taken 7 times.
|
7 | fs << "\tprotected:" << std::endl; |
| 306 |
2/2✓ Branch 0 (138→139) taken 1 times.
✓ Branch 1 (138→151) taken 6 times.
|
7 | if(hasPointerAttribute){ |
| 307 |
6/6✓ Branch 0 (139→140) taken 1 times.
✓ Branch 2 (140→141) taken 1 times.
✓ Branch 4 (141→142) taken 1 times.
✓ Branch 6 (142→143) taken 1 times.
✓ Branch 8 (143→144) taken 1 times.
✓ Branch 10 (144→145) taken 1 times.
|
1 | fs << "\t\tvoid copy" << name << "(const " << name << " & other);" << std::endl; |
| 308 |
6/6✓ Branch 0 (145→146) taken 1 times.
✓ Branch 2 (146→147) taken 1 times.
✓ Branch 4 (147→148) taken 1 times.
✓ Branch 6 (148→149) taken 1 times.
✓ Branch 8 (149→150) taken 1 times.
✓ Branch 10 (150→151) taken 1 times.
|
1 | fs << "\t\tvoid move" << name << "(" << name << " && other);" << std::endl; |
| 309 | } | ||
| 310 |
1/1✓ Branch 0 (151→152) taken 7 times.
|
7 | fs << protectedContent; |
| 311 | } | ||
| 312 | |||
| 313 |
2/2✓ Branch 0 (152→153) taken 8 times.
✓ Branch 2 (153→154) taken 8 times.
|
8 | fs << "\tprivate:" << std::endl; |
| 314 |
1/1✓ Branch 0 (154→155) taken 8 times.
|
8 | manager.privateMethodDeclaration(fs, classConfig, classMode); |
| 315 |
1/1✓ Branch 0 (155→156) taken 8 times.
|
8 | const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute()); |
| 316 |
2/2✓ Branch 0 (195→157) taken 21 times.
✓ Branch 1 (195→196) taken 8 times.
|
58 | for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 317 |
7/8✓ Branch 0 (159→160) taken 21 times.
✓ Branch 2 (160→161) taken 21 times.
✓ Branch 4 (161→162) taken 21 times.
✗ Branch 5 (161→168) not taken.
✓ Branch 6 (162→163) taken 21 times.
✓ Branch 8 (165→166) taken 21 times.
✓ Branch 10 (166→167) taken 21 times.
✓ Branch 12 (167→168) taken 21 times.
|
42 | if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl; |
| 318 |
1/1✓ Branch 0 (170→171) taken 21 times.
|
42 | PString defaultInit(class_getAttributeDefaultInit(*it)); |
| 319 |
9/9✓ Branch 0 (171→172) taken 21 times.
✓ Branch 2 (174→175) taken 21 times.
✓ Branch 4 (175→176) taken 21 times.
✓ Branch 6 (176→177) taken 21 times.
✓ Branch 8 (179→180) taken 21 times.
✓ Branch 10 (180→181) taken 21 times.
✓ Branch 12 (181→182) taken 21 times.
✓ Branch 14 (182→183) taken 21 times.
✓ Branch 16 (183→184) taken 21 times.
|
63 | fs << "\t\t" << it->getType() << " p_" << it->getName() << defaultInit << ";" << std::endl; |
| 320 | 21 | } | |
| 321 |
3/3✓ Branch 0 (196→197) taken 8 times.
✓ Branch 2 (197→198) taken 8 times.
✓ Branch 4 (198→199) taken 8 times.
|
8 | fs << "};" << std::endl << std::endl; |
| 322 |
1/1✓ Branch 0 (199→200) taken 8 times.
|
8 | manager.classExtraFunctionDeclaration(fs, classConfig, classMode); |
| 323 |
2/2✓ Branch 0 (200→201) taken 8 times.
✓ Branch 2 (201→202) taken 8 times.
|
8 | fs << std::endl << std::endl; |
| 324 | 8 | } | |
| 325 | |||
| 326 | ///Create the declaration of the given class | ||
| 327 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 328 | * @param headerFile : file to be saved | ||
| 329 | * @param vecClassConfig : configuration of the class to be used | ||
| 330 | * @param mode : mode of the generator | ||
| 331 | * @param vecInclude : vector of include files to be added into the header | ||
| 332 | * @param includeTemplate : extra include for the template implementation | ||
| 333 | * @return true on success, false otherwise | ||
| 334 | */ | ||
| 335 | 6 | bool generator_class_cpp_headerFile(const PTraitBackendManager & manager, const PPath & headerFile, const std::vector<PClassConfig> & vecClassConfig, const GeneratorMode & mode, | |
| 336 | const PVecPath & vecInclude, const PString & includeTemplate) | ||
| 337 | { | ||
| 338 |
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; |
| 339 |
1/1✓ Branch 0 (5→6) taken 6 times.
|
6 | std::ofstream fs; |
| 340 |
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;} |
| 341 |
1/1✓ Branch 0 (9→10) taken 6 times.
|
6 | licenceSave(fs); |
| 342 |
2/2✓ Branch 0 (10→11) taken 6 times.
✓ Branch 2 (11→12) taken 6 times.
|
6 | PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName())); |
| 343 |
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; |
| 344 |
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; |
| 345 |
2/2✓ Branch 0 (20→21) taken 6 times.
✓ Branch 2 (21→22) taken 6 times.
|
6 | fs << "#include <string>" << std::endl; |
| 346 |
1/2✗ Branch 0 (23→24) not taken.
✓ Branch 1 (23→42) taken 6 times.
|
6 | if(vecInclude.size() != 0LU){ |
| 347 | ✗ | for(PVecPath::const_iterator it(vecInclude.begin()); it != vecInclude.end(); ++it){ | |
| 348 | ✗ | fs << "#include " << *it << std::endl; | |
| 349 | } | ||
| 350 | ✗ | fs << std::endl; | |
| 351 | } | ||
| 352 |
1/1✓ Branch 0 (42→43) taken 6 times.
|
6 | manager.headerExtraInclude(fs, mode); |
| 353 |
1/1✓ Branch 0 (43→44) taken 6 times.
|
6 | fs << std::endl; |
| 354 |
2/2✓ Branch 0 (65→45) taken 10 times.
✓ Branch 1 (65→66) taken 6 times.
|
32 | for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 355 |
3/3✓ Branch 0 (47→48) taken 10 times.
✓ Branch 2 (48→49) taken 3 times.
✓ Branch 3 (48→52) taken 7 times.
|
10 | if(it->getIsEnum()){ |
| 356 |
1/1✓ Branch 0 (51→55) taken 3 times.
|
3 | generator_enum_cpp_header(manager, fs, *it, mode); |
| 357 | // saveEnumDecl(fs, *it, mode); | ||
| 358 | }else{ | ||
| 359 |
1/1✓ Branch 0 (54→55) taken 7 times.
|
7 | generator_class_cpp_header(manager, fs, *it, mode); |
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 |
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 != ""){ |
| 364 | ✗ | fs << "#include \""<<includeTemplate<<"\"" << std::endl << std::endl; | |
| 365 | } | ||
| 366 | |||
| 367 |
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; |
| 368 |
1/1✓ Branch 0 (78→79) taken 6 times.
|
6 | fs.close(); |
| 369 | 6 | return true; | |
| 370 | 6 | } | |
| 371 | |||
| 372 | ///Create the implementation of the given class | ||
| 373 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 374 | * @param[out] fs : file to be completed | ||
| 375 | * @param classConfig : configuration of the class to be used | ||
| 376 | * @param mode : mode of the generator | ||
| 377 | */ | ||
| 378 | 11 | void generator_class_cpp_source(const PTraitBackendManager & manager, std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 379 |
1/1✓ Branch 0 (2→3) taken 11 times.
|
11 | manager.classExtraFunctionImplementation(fs, classConfig, mode); |
| 380 |
1/1✓ Branch 0 (3→4) taken 11 times.
|
11 | GeneratorMode classMode(mode); |
| 381 |
1/1✓ Branch 0 (4→5) taken 11 times.
|
11 | const PVecString & listTemplate = classConfig.getListTemplate(); |
| 382 |
1/1✓ Branch 0 (5→6) taken 11 times.
|
11 | PString defTemplate(class_getClassDefTemplate(listTemplate)); |
| 383 |
1/1✓ Branch 0 (6→7) taken 11 times.
|
11 | PString templateDeclaration(class_getClassDeclTempalteDef(listTemplate)); |
| 384 |
1/1✓ Branch 0 (7→8) taken 11 times.
|
11 | classMode.defTemplate = defTemplate; |
| 385 |
1/1✓ Branch 0 (8→9) taken 11 times.
|
11 | classMode.templateDeclaration = templateDeclaration; |
| 386 |
3/3✓ Branch 0 (9→10) taken 11 times.
✓ Branch 2 (10→11) taken 8 times.
✓ Branch 3 (10→12) taken 3 times.
|
11 | if(!classConfig.getIsEnum()){ |
| 387 |
1/1✓ Branch 0 (11→12) taken 8 times.
|
8 | class_savePointerOwnershipSpecialMembersImpl(fs, classConfig, defTemplate, templateDeclaration); |
| 388 | } | ||
| 389 |
1/1✓ Branch 0 (12→13) taken 11 times.
|
11 | manager.publicMethodImplementation(fs, classConfig, classMode); |
| 390 |
1/1✓ Branch 0 (13→14) taken 11 times.
|
11 | manager.protectedMethodImplementation(fs, classConfig, classMode); |
| 391 |
1/1✓ Branch 0 (14→15) taken 11 times.
|
11 | manager.privateMethodImplementation(fs, classConfig, classMode); |
| 392 | 11 | } | |
| 393 | |||
| 394 | ///Create the implementation of the given file | ||
| 395 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 396 | * @param sourceFile : source file to be saved | ||
| 397 | * @param headerFile : header to be used with this source file | ||
| 398 | * @param vecClassConfig : vector of configuration of the classes to be used | ||
| 399 | * @param mode : mode of the generator | ||
| 400 | * @param isTemplateImpl : true to activate | ||
| 401 | * @return true on success, false otherwise | ||
| 402 | */ | ||
| 403 | 6 | bool generator_class_cpp_sourceFile(const PTraitBackendManager & manager, const PPath & sourceFile, const PPath & headerFile, | |
| 404 | const std::vector<PClassConfig> & vecClassConfig, const GeneratorMode & mode, bool isTemplateImpl) | ||
| 405 | { | ||
| 406 |
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; |
| 407 |
1/1✓ Branch 0 (10→11) taken 6 times.
|
6 | std::ofstream fs; |
| 408 |
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;} |
| 409 |
1/1✓ Branch 0 (14→15) taken 6 times.
|
6 | licenceSave(fs); |
| 410 |
1/2✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→32) taken 6 times.
|
6 | if(isTemplateImpl){ |
| 411 | ✗ | PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName() + "_IMPL")); | |
| 412 | ✗ | fs << "#ifndef " << macroDef << std::endl; | |
| 413 | ✗ | fs << "#define " << macroDef << std::endl << std::endl; | |
| 414 | ✗ | } | |
| 415 |
6/6✓ 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.
|
6 | fs << std::endl << "#include \"" << headerFile.getFileName() << "\"" << std::endl; |
| 416 | 6 | bool hasPointerAttribute(false); | |
| 417 |
5/6✓ Branch 0 (53→54) taken 10 times.
✓ Branch 1 (53→56) taken 6 times.
✓ Branch 2 (54→55) taken 10 times.
✗ Branch 3 (54→56) not taken.
✓ Branch 4 (57→40) taken 10 times.
✓ Branch 5 (57→58) taken 6 times.
|
32 | for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end() && !hasPointerAttribute; ++it){ |
| 418 |
1/1✓ Branch 0 (42→43) taken 10 times.
|
10 | hasPointerAttribute = class_hasPointerAttribute(*it); |
| 419 | } | ||
| 420 |
2/2✓ Branch 0 (58→59) taken 1 times.
✓ Branch 1 (58→61) taken 5 times.
|
6 | if(hasPointerAttribute){ |
| 421 |
2/2✓ Branch 0 (59→60) taken 1 times.
✓ Branch 2 (60→61) taken 1 times.
|
1 | fs << "#include <utility>" << std::endl; //std::move used by the hand-written move constructor/assignment |
| 422 | } | ||
| 423 |
1/1✓ Branch 0 (61→62) taken 6 times.
|
6 | fs << std::endl; |
| 424 | 6 | bool hasNamespace(false); | |
| 425 |
2/2✓ Branch 0 (91→63) taken 10 times.
✓ Branch 1 (91→92) taken 6 times.
|
32 | for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 426 |
4/8✓ Branch 0 (65→66) taken 10 times.
✓ Branch 2 (66→67) taken 10 times.
✗ Branch 4 (67→68) not taken.
✓ Branch 5 (67→70) taken 10 times.
✗ Branch 6 (68→69) not taken.
✗ Branch 7 (68→70) not taken.
✗ Branch 8 (71→72) not taken.
✓ Branch 9 (71→81) taken 10 times.
|
10 | if(it->getNamespace() != "" && !hasNamespace){ |
| 427 | ✗ | fs << "using namespace " << it->getNamespace() << ";" << std::endl << std::endl; | |
| 428 | ✗ | hasNamespace = true; | |
| 429 | } | ||
| 430 | } | ||
| 431 |
2/2✓ Branch 0 (106→93) taken 10 times.
✓ Branch 1 (106→107) taken 6 times.
|
32 | for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 432 |
1/1✓ Branch 0 (95→96) taken 10 times.
|
10 | generator_class_cpp_source(manager, fs, *it, mode); |
| 433 | } | ||
| 434 |
1/2✗ Branch 0 (107→108) not taken.
✓ Branch 1 (107→111) taken 6 times.
|
6 | if(isTemplateImpl){ |
| 435 | ✗ | fs << "#endif" << std::endl << std::endl; | |
| 436 | } | ||
| 437 |
1/1✓ Branch 0 (111→112) taken 6 times.
|
6 | fs.close(); |
| 438 | |||
| 439 | 6 | return true; | |
| 440 | 6 | } | |
| 441 | |||
| 442 | |||
| 443 | |||
| 444 | ///Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated | ||
| 445 | /** @param[out] hasSource : true if the configuration needs .cpp file | ||
| 446 | * @param[out] hasTemplate : true if the configuration needs _impl.h file | ||
| 447 | * @param vecClassConfig : class config we want to save | ||
| 448 | */ | ||
| 449 | 6 | void class_checkClassConfig(bool & hasSource, bool & hasTemplate, const std::vector<PClassConfig> & vecClassConfig){ | |
| 450 | 6 | hasSource = false; | |
| 451 | 6 | hasTemplate = false; | |
| 452 |
2/2✓ Branch 0 (17→3) taken 10 times.
✓ Branch 1 (17→18) taken 6 times.
|
32 | for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 453 |
1/1✓ Branch 0 (5→6) taken 10 times.
|
10 | bool isTemplate = it->getListTemplate().size() != 0LU; |
| 454 | 10 | hasSource |= !isTemplate; | |
| 455 | 10 | hasTemplate |= isTemplate; | |
| 456 | } | ||
| 457 | 6 | } | |
| 458 | |||
| 459 | ///Creates header and source files | ||
| 460 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 461 | * @param vecClassConfig : vector of class config we want to save | ||
| 462 | * @param baseFileName : base file name for header or source file | ||
| 463 | * @param outputSourceDir : output directory where to save sources | ||
| 464 | * @param mode : all modes of the generator (data/check/type/config stream) | ||
| 465 | * @return true on success, false otherwise | ||
| 466 | */ | ||
| 467 | 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){ | |
| 468 |
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 == ""){ |
| 469 | ✗ | std::cerr << termRed() << "generator_class_cpp : baseFileName is empty" << termDefault() << std::endl; | |
| 470 | ✗ | return false; | |
| 471 | } | ||
| 472 | 6 | bool hasSource(false), hasTemplate(false); | |
| 473 |
1/1✓ Branch 0 (13→14) taken 6 times.
|
6 | class_checkClassConfig(hasSource, hasTemplate, vecClassConfig); |
| 474 |
1/1✓ Branch 0 (14→15) taken 6 times.
|
6 | PString includeTemplate(""); |
| 475 |
1/2✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→24) taken 6 times.
|
6 | if(hasTemplate){ |
| 476 | ✗ | includeTemplate = PString(baseFileName.getFileName() + "_impl.h"); | |
| 477 | } | ||
| 478 |
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"); |
| 479 |
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)){ |
| 480 | ✗ | std::cerr << termRed() << "generator_class_cpp : cannot generate header file '"<<headerFile<<"'" << termDefault() << std::endl; | |
| 481 | ✗ | return false; | |
| 482 | } | ||
| 483 |
1/2✓ Branch 0 (44→45) taken 6 times.
✗ Branch 1 (44→81) not taken.
|
6 | if(hasSource){ |
| 484 |
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")); |
| 485 |
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)){ |
| 486 | ✗ | std::cerr << termRed() << "generator_class_cpp : cannot generate source file '"<<sourceFile<<"'" << termDefault() << std::endl; | |
| 487 | ✗ | return false; | |
| 488 | } | ||
| 489 |
1/2✓ Branch 0 (77→78) taken 6 times.
✗ Branch 1 (77→80) not taken.
|
6 | } |
| 490 |
1/2✗ Branch 0 (81→82) not taken.
✓ Branch 1 (81→118) taken 6 times.
|
6 | if(hasTemplate){ |
| 491 | ✗ | PPath implFile = outputSourceDir / PPath(baseFileName + PString("_impl.h")); | |
| 492 | ✗ | if(!generator_class_cpp_sourceFile(manager, implFile, PPath(baseFileName + PString(".h")), vecClassConfig, mode, true)){ | |
| 493 | ✗ | std::cerr << termRed() << "generator_class_cpp : cannot generate impl file '"<<implFile<<"'" << termDefault() << std::endl; | |
| 494 | ✗ | return false; | |
| 495 | } | ||
| 496 | ✗ | } | |
| 497 | 6 | return true; | |
| 498 | 6 | } | |
| 499 | |||
| 500 | |||
| 501 | ///Save the CMakeLists to be used to compile the unit test | ||
| 502 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 503 | * @param outputCurrentTestDir : current test directoru in which to create the CMakeLists.txt | ||
| 504 | * @param classConfig : class configuration to be used | ||
| 505 | * @param baseFileName : base of output file name of the generated sources | ||
| 506 | * @param mode : all modes of the generator (data/check/type/config stream) | ||
| 507 | * @return true on success, false oterhwise | ||
| 508 | */ | ||
| 509 | 9 | bool generator_class_testMain(const PTraitBackendManager & manager, const PPath & outputCurrentTestDir, const PClassConfig & classConfig, const PPath & baseFileName, const GeneratorMode & mode){ | |
| 510 |
1/1✓ Branch 0 (2→3) taken 9 times.
|
9 | std::ofstream fs; |
| 511 |
6/7✓ Branch 0 (3→4) taken 9 times.
✓ Branch 2 (4→5) taken 9 times.
✓ Branch 4 (5→6) taken 9 times.
✓ Branch 6 (6→7) taken 9 times.
✓ Branch 8 (7→8) taken 9 times.
✗ Branch 10 (12→13) not taken.
✓ Branch 11 (12→14) taken 9 times.
|
9 | if(!openFileStream(fs, PPath(outputCurrentTestDir + PString("/main.cpp")))){return false;} |
| 512 |
1/1✓ Branch 0 (14→15) taken 9 times.
|
9 | licenceSave(fs); |
| 513 | // body += licenceSaveStr() + "\n"; | ||
| 514 |
2/3✓ Branch 0 (15→16) taken 9 times.
✓ Branch 2 (16→17) taken 9 times.
✗ Branch 3 (16→23) not taken.
|
9 | if(mode.assertInclude != ""){ |
| 515 |
3/3✓ Branch 0 (17→18) taken 9 times.
✓ Branch 2 (18→19) taken 9 times.
✓ Branch 4 (19→20) taken 9 times.
|
9 | fs << "#include \"" + mode.assertInclude + "\"\n\n"; |
| 516 | } | ||
| 517 |
3/3✓ Branch 0 (23→24) taken 9 times.
✓ Branch 2 (24→25) taken 9 times.
✓ Branch 4 (25→26) taken 9 times.
|
9 | fs << "#include \"" + baseFileName + ".h\"\n\n"; |
| 518 |
3/8✓ Branch 0 (28→29) taken 9 times.
✓ Branch 2 (29→30) taken 9 times.
✗ Branch 4 (30→31) not taken.
✓ Branch 5 (30→35) taken 9 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.
|
9 | if(classConfig.getNamespace() != ""){fs << "using namespace " << classConfig.getNamespace() << ";\n\n";} |
| 519 |
1/1✓ Branch 0 (35→36) taken 9 times.
|
9 | manager.testFunction(fs, classConfig, mode); |
| 520 |
1/1✓ Branch 0 (36→37) taken 9 times.
|
9 | fs << "int main(int argc, char ** argv){\n"; |
| 521 | //Do other test if the enableDataStream is true | ||
| 522 |
1/1✓ Branch 0 (37→38) taken 9 times.
|
9 | manager.testCallFunction(fs, classConfig, mode); |
| 523 |
1/1✓ Branch 0 (38→39) taken 9 times.
|
9 | fs << "\treturn 0;\n"; |
| 524 |
1/1✓ Branch 0 (39→40) taken 9 times.
|
9 | fs << "}\n"; |
| 525 |
1/1✓ Branch 0 (40→41) taken 9 times.
|
9 | fs.close(); |
| 526 | 9 | return true; | |
| 527 | 9 | } | |
| 528 | |||
| 529 | ///Save the CMakeLists to be used to compile the unit test | ||
| 530 | /** @param outputCurrentTestDir : current test directory in which to create the CMakeLists.txt | ||
| 531 | * @param classConfig : class configuration to be used | ||
| 532 | * @param projectName : configuration of the project | ||
| 533 | * @param mode : all modes of the generator (data/check/type/config stream) | ||
| 534 | * @return true on success, false oterhwise | ||
| 535 | */ | ||
| 536 | 9 | bool generator_class_testCMakeLists( const PPath & outputCurrentTestDir, const PClassConfig & classConfig, const PString & projectName, const GeneratorMode & mode){ | |
| 537 |
5/5✓ Branch 0 (2→3) taken 9 times.
✓ Branch 2 (3→4) taken 9 times.
✓ Branch 4 (4→5) taken 9 times.
✓ Branch 6 (5→6) taken 9 times.
✓ Branch 8 (6→7) taken 9 times.
|
9 | PString body(""), testName("test_class_" + classConfig.getName().toLowerUnderscore()); |
| 538 |
2/2✓ Branch 0 (9→10) taken 9 times.
✓ Branch 2 (10→11) taken 9 times.
|
9 | body += getCMakeListsHeader(); |
| 539 |
3/3✓ Branch 0 (12→13) taken 9 times.
✓ Branch 2 (13→14) taken 9 times.
✓ Branch 4 (14→15) taken 9 times.
|
9 | body += "add_executable("+testName+" main.cpp)\n"; |
| 540 |
6/6✓ Branch 0 (17→18) taken 9 times.
✓ Branch 2 (18→19) taken 9 times.
✓ Branch 4 (19→20) taken 9 times.
✓ Branch 6 (20→21) taken 9 times.
✓ Branch 8 (21→22) taken 9 times.
✓ Branch 10 (22→23) taken 9 times.
|
9 | body += "target_link_libraries("+testName+" ${"+projectName.toUpper()+"_TEST_DEPENDENCIES})\n"; |
| 541 |
1/1✓ Branch 0 (28→29) taken 9 times.
|
9 | body += "\n"; |
| 542 |
4/4✓ Branch 0 (29→30) taken 9 times.
✓ Branch 2 (30→31) taken 9 times.
✓ Branch 4 (31→32) taken 9 times.
✓ Branch 6 (32→33) taken 9 times.
|
9 | body += "add_test(NAME "+testName.firstToUpper()+"\n"; |
| 543 |
3/3✓ Branch 0 (36→37) taken 9 times.
✓ Branch 2 (37→38) taken 9 times.
✓ Branch 4 (38→39) taken 9 times.
|
9 | body += "\tCOMMAND ${CMAKE_CURRENT_BINARY_DIR}/"+testName+"\n"; |
| 544 |
1/1✓ Branch 0 (41→42) taken 9 times.
|
9 | body += "\tWORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}\n"; |
| 545 |
1/1✓ Branch 0 (42→43) taken 9 times.
|
9 | body += ")\n\n\n"; |
| 546 |
5/5✓ Branch 0 (43→44) taken 9 times.
✓ Branch 2 (44→45) taken 9 times.
✓ Branch 4 (45→46) taken 9 times.
✓ Branch 6 (46→47) taken 9 times.
✓ Branch 8 (47→48) taken 9 times.
|
18 | return PPath(outputCurrentTestDir + PString("/CMakeLists.txt")).saveFileContent(body); |
| 547 | 9 | } | |
| 548 | |||
| 549 | ///Save the unit test of the generated PClassConfig | ||
| 550 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 551 | * @param outputTestDir : output directory where to put the genreated test (typically ../TESTS if the program is called from ./src) | ||
| 552 | * @param classConfig : class configuration to be used | ||
| 553 | * @param projectName : configuration of the project | ||
| 554 | * @param baseFileName : base of output file name of the generated sources | ||
| 555 | * @param mode : all modes of the generator (data/check/type/config stream) | ||
| 556 | * @return true on success, false oterhwise | ||
| 557 | */ | ||
| 558 | 9 | bool generator_class_test(const PTraitBackendManager & manager, const PPath & outputTestDir, const PClassConfig & classConfig, const PString & projectName, const PPath & baseFileName, const GeneratorMode & mode){ | |
| 559 |
2/2✓ Branch 0 (2→3) taken 9 times.
✓ Branch 2 (3→4) taken 9 times.
|
9 | PString name(classConfig.getName()); |
| 560 |
6/6✓ Branch 0 (4→5) taken 9 times.
✓ Branch 2 (5→6) taken 9 times.
✓ Branch 4 (6→7) taken 9 times.
✓ Branch 6 (7→8) taken 9 times.
✓ Branch 8 (8→9) taken 9 times.
✓ Branch 10 (9→10) taken 9 times.
|
9 | PPath outputCurrentTestDir(outputTestDir + PString("/TEST_") + name.toUpper()); |
| 561 |
2/7✓ Branch 0 (15→16) taken 9 times.
✗ Branch 2 (16→17) not taken.
✓ Branch 3 (16→22) taken 9 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.
|
9 | if(!outputCurrentTestDir.createDirectory()){std::cerr << "generator_class_test : cannot create TEST directory '"<<outputCurrentTestDir<<"'" << std::endl;return false;} |
| 562 | |||
| 563 | 9 | bool b(true); | |
| 564 |
1/1✓ Branch 0 (22→23) taken 9 times.
|
9 | b &= generator_class_testCMakeLists(outputCurrentTestDir, classConfig, projectName, mode); |
| 565 |
1/1✓ Branch 0 (23→24) taken 9 times.
|
9 | b &= generator_class_testMain(manager, outputCurrentTestDir, classConfig, baseFileName, mode); |
| 566 | 9 | return b; | |
| 567 | 9 | } | |
| 568 | |||
| 569 | ///Save the unit test of the generated PClassConfig | ||
| 570 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 571 | * @param outputTestDir : output directory where to put the generated test (typically ../TESTS if the program is called from ./src) | ||
| 572 | * @param vecClassConfig : vector of class configuration to be used | ||
| 573 | * @param projectName : configuration of the project | ||
| 574 | * @param baseFileName : base of output file name of the generated sources | ||
| 575 | * @param mode : all modes of the generator (data/check/type/config stream) | ||
| 576 | * @return true on success, false oterhwise | ||
| 577 | */ | ||
| 578 | 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){ | |
| 579 |
1/1✓ Branch 0 (2→3) taken 5 times.
|
5 | PString cmakeListBody; |
| 580 |
2/2✓ Branch 0 (3→4) taken 5 times.
✓ Branch 2 (4→5) taken 5 times.
|
5 | cmakeListBody += getCMakeListsHeader(); |
| 581 | 5 | bool b(true); | |
| 582 |
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"; |
| 583 |
2/2✓ Branch 0 (38→15) taken 9 times.
✓ Branch 1 (38→39) taken 5 times.
|
28 | for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 584 |
5/5✓ Branch 0 (17→18) taken 9 times.
✓ Branch 2 (18→19) taken 9 times.
✓ Branch 4 (19→20) taken 9 times.
✓ Branch 6 (20→21) taken 9 times.
✓ Branch 8 (21→22) taken 9 times.
|
9 | cmakeListBody += "add_subdirectory(TEST_" + it->getName().toUpper() + ")\n"; |
| 585 |
1/1✓ Branch 0 (27→28) taken 9 times.
|
9 | b &= generator_class_test(manager, outputTestDir, *it, projectName, baseFileName, mode); |
| 586 | } | ||
| 587 |
1/1✓ Branch 0 (39→40) taken 5 times.
|
5 | cmakeListBody += "\n\n"; |
| 588 |
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")); |
| 589 |
1/1✓ Branch 0 (45→46) taken 5 times.
|
5 | b &= cmakelist.saveFileContent(cmakeListBody); |
| 590 | 5 | return b; | |
| 591 | 5 | } | |
| 592 | |||
| 593 | ///Generate the full sources and related unit tests from configuration | ||
| 594 | /** @param manager : PTraitBackendManager which handles all trait backend | ||
| 595 | * @param projectParam : description of classes and how and where to generate sources and test | ||
| 596 | * @return true on success, false otherwise | ||
| 597 | */ | ||
| 598 | 3 | bool generator_class_full(const PTraitBackendManager & manager, const ProjectParam & projectParam){ | |
| 599 | 3 | bool b(true); | |
| 600 |
1/1✓ Branch 0 (2→3) taken 3 times.
|
3 | b &= projectParam.outputSourceDir.createDirectory(); |
| 601 |
1/1✓ Branch 0 (3→4) taken 3 times.
|
3 | b &= projectParam.outputTestDir.createDirectory(); |
| 602 |
1/1✓ Branch 0 (4→5) taken 3 times.
|
3 | PString cmakeListBody; |
| 603 |
2/2✓ Branch 0 (5→6) taken 3 times.
✓ Branch 2 (6→7) taken 3 times.
|
3 | cmakeListBody += getCMakeListsHeader(); |
| 604 | 3 | const PVecDataConfig & vecDataConfig = projectParam.vecDataConfig; | |
| 605 |
2/2✓ Branch 0 (77→10) taken 5 times.
✓ Branch 1 (77→78) taken 3 times.
|
11 | for(const PDataConfig & config : vecDataConfig){ |
| 606 |
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(); |
| 607 |
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())){ |
| 608 | ✗ | std::cerr << termRed() << "generator_class_full : cannot generate C++ sources at '"<<projectParam.outputSourceDir<<"'" << termDefault() << std::endl; | |
| 609 | ✗ | b = false; //best effort strategy | |
| 610 | } | ||
| 611 |
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()); |
| 612 |
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"; |
| 613 |
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)){ |
| 614 | ✗ | std::cerr << termRed() << "generator_class_full : cannot generate C++ tests at '"<<projectParam.outputTestDir<<"'" << termDefault() << std::endl; | |
| 615 | ✗ | b = false; //best effort strategy | |
| 616 | } | ||
| 617 | 5 | } | |
| 618 |
1/1✓ Branch 0 (78→79) taken 3 times.
|
3 | cmakeListBody += "\n\n"; |
| 619 |
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")); |
| 620 |
1/1✓ Branch 0 (84→85) taken 3 times.
|
3 | b &= cmakelist.saveFileContent(cmakeListBody); |
| 621 | 3 | return b; | |
| 622 | 3 | } | |
| 623 | |||
| 624 | |||
| 625 | |||
| 626 | |||
| 627 |