| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | |||
| 8 | #include "vec_value_utils.h" | ||
| 9 | |||
| 10 | ///Get the last VecValue added at the specified depth | ||
| 11 | /** @param vecVal : VecValue to be used | ||
| 12 | * @param depth : depth of the last VecValue to be returned | ||
| 13 | * @return pointer to the corresponding VecValue (cannot be NULL) | ||
| 14 | */ | ||
| 15 | 366 | VecValue * getLastVecValue(VecValue & vecVal, size_t depth){ | |
| 16 | 366 | VecVecValue & vecChildren = vecVal.getVecChild(); | |
| 17 |
6/6✓ Branch 0 (4→5) taken 296 times.
✓ Branch 1 (4→6) taken 70 times.
✓ Branch 2 (5→6) taken 114 times.
✓ Branch 3 (5→7) taken 182 times.
✓ Branch 4 (8→9) taken 184 times.
✓ Branch 5 (8→10) taken 182 times.
|
366 | if(vecChildren.size() == 0lu || depth == 0lu){return &vecVal;} |
| 18 | 182 | else{return getLastVecValue(vecChildren.back(), depth - 1lu);} | |
| 19 | } | ||
| 20 | |||
| 21 | ///Get the parent VecValue by respect to its indentation | ||
| 22 | /** @param[out] vecAllVal : main VecValue | ||
| 23 | * @param vecIndentation : vector of the last indentation of the children VecValue | ||
| 24 | * @param currentIndentation : indentation of the current VecValue | ||
| 25 | * @return pointer to the corresponding VecValue (cannot be NULL) | ||
| 26 | */ | ||
| 27 | 184 | VecValue * getParentVecValue(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation){ | |
| 28 |
2/2✓ Branch 0 (3→4) taken 20 times.
✓ Branch 1 (3→6) taken 164 times.
|
184 | if(vecIndentation.size() == 0lu){ |
| 29 |
1/1✓ Branch 0 (4→5) taken 20 times.
|
20 | return getLastVecValue(vecAllVal); |
| 30 | } | ||
| 31 | 164 | size_t depth(0lu); | |
| 32 | 164 | std::vector<size_t>::const_iterator it(vecIndentation.begin()); | |
| 33 | 164 | bool isCurrentLower(true); | |
| 34 |
6/6✓ Branch 0 (15→16) taken 346 times.
✓ Branch 1 (15→25) taken 114 times.
✓ Branch 2 (23→24) taken 296 times.
✓ Branch 3 (23→25) taken 50 times.
✓ Branch 4 (26→8) taken 296 times.
✓ Branch 5 (26→27) taken 164 times.
|
806 | while(isCurrentLower && it != vecIndentation.end()){ |
| 35 | 296 | isCurrentLower = *it < currentIndentation; | |
| 36 |
2/2✓ Branch 0 (10→11) taken 182 times.
✓ Branch 1 (10→12) taken 114 times.
|
296 | if(isCurrentLower){ |
| 37 | 182 | ++depth; | |
| 38 | } | ||
| 39 | ++it; | ||
| 40 | } | ||
| 41 |
1/1✓ Branch 0 (27→28) taken 164 times.
|
164 | VecValue * out = getLastVecValue(vecAllVal, depth); |
| 42 | 164 | return out; | |
| 43 | } | ||
| 44 | |||
| 45 | ///Get the parent pointer vector | ||
| 46 | /** @param[out] vecParentPtr : vector of pointer of all parent chain | ||
| 47 | * @param vecAllVal : Main VecValue | ||
| 48 | */ | ||
| 49 | 182 | void getVecParentPtr(std::vector<VecValue*> & vecParentPtr, VecValue & vecAllVal){ | |
| 50 |
1/1✓ Branch 0 (2→3) taken 182 times.
|
182 | vecParentPtr.push_back(&vecAllVal); |
| 51 |
2/2✓ Branch 0 (5→6) taken 124 times.
✓ Branch 1 (5→9) taken 58 times.
|
182 | if(vecAllVal.getVecChild().size() != 0lu){ |
| 52 | 124 | getVecParentPtr(vecParentPtr, vecAllVal.getVecChild().back()); | |
| 53 | } | ||
| 54 | 182 | } | |
| 55 | |||
| 56 | ///Get the parent pointer vector | ||
| 57 | /** @param vecAllVal : Main VecValue | ||
| 58 | * @return vector of pointer of all parent chain | ||
| 59 | */ | ||
| 60 | 58 | std::vector<VecValue*> getVecParentPtr(VecValue & vecAllVal){ | |
| 61 | 58 | std::vector<VecValue*> vecParentPtr; | |
| 62 |
1/1✓ Branch 0 (3→4) taken 58 times.
|
58 | getVecParentPtr(vecParentPtr, vecAllVal); |
| 63 | 58 | return vecParentPtr; | |
| 64 | ✗ | } | |
| 65 | |||
| 66 | ///Get the parent VecValue by respect to its indentation | ||
| 67 | /** @param[out] vecAllVal : main VecValue | ||
| 68 | * @param vecIndentation : vector of the last indentation of the children VecValue | ||
| 69 | * @param currentIndentation : indentation of the current VecValue | ||
| 70 | * @param child : child to be added to the parent | ||
| 71 | * @return pointer to the corresponding VecValue (cannot be NULL) | ||
| 72 | */ | ||
| 73 | 58 | VecValue * getParentVecValueListItem(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation, const VecValue & child){ | |
| 74 |
1/2✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→6) taken 58 times.
|
58 | if(vecIndentation.size() == 0lu){ |
| 75 | ✗ | return getLastVecValue(vecAllVal); | |
| 76 | } | ||
| 77 |
1/1✓ Branch 0 (6→7) taken 58 times.
|
58 | size_t childIndentation(child.getIndentation()); |
| 78 | 58 | VecValue * out = NULL; | |
| 79 |
1/1✓ Branch 0 (7→8) taken 58 times.
|
58 | std::vector<VecValue*> vecParentPtr = getVecParentPtr(vecAllVal); |
| 80 | 58 | std::vector<VecValue*>::const_reverse_iterator itParent(vecParentPtr.rbegin()); | |
| 81 | 58 | bool isCurrentGreater(true); | |
| 82 |
5/6✓ Branch 0 (38→39) taken 124 times.
✓ Branch 1 (38→43) taken 58 times.
✓ Branch 2 (41→42) taken 124 times.
✗ Branch 3 (41→43) not taken.
✓ Branch 4 (44→11) taken 124 times.
✓ Branch 5 (44→45) taken 58 times.
|
182 | while(isCurrentGreater && itParent != vecParentPtr.rend()){ |
| 83 |
7/8✓ Branch 0 (12→13) taken 124 times.
✓ Branch 2 (13→14) taken 82 times.
✓ Branch 3 (13→17) taken 42 times.
✓ Branch 4 (14→15) taken 82 times.
✓ Branch 6 (15→16) taken 82 times.
✗ Branch 7 (15→17) not taken.
✓ Branch 8 (18→19) taken 82 times.
✓ Branch 9 (18→22) taken 42 times.
|
124 | if((*itParent)->getType() == VecValueType::KEY && child.getType() == VecValueType::LIST_ITEM){ |
| 84 |
1/1✓ Branch 0 (20→21) taken 82 times.
|
82 | isCurrentGreater = (*itParent)->getIndentation() > childIndentation; |
| 85 | // if(!isCurrentGreater){ | ||
| 86 | // std::cout << "getParentVecValueListItem : Parent("<<(*itParent)->getKey()<<").getType() : " << (*itParent)->getType() << ", ParentIndentation = "<<(*itParent)->getIndentation()<<", child.getType() = " << child.getType() << ", key = '"<<child.getKey()<<"', value = '"<<child.getValue()<<"', childIndentation = "<<childIndentation << std::endl; | ||
| 87 | // } | ||
| 88 | }else{ | ||
| 89 |
6/8✓ Branch 0 (23→24) taken 42 times.
✓ Branch 2 (24→25) taken 18 times.
✓ Branch 3 (24→31) taken 24 times.
✓ Branch 4 (26→27) taken 18 times.
✗ Branch 6 (27→28) not taken.
✓ Branch 7 (27→31) taken 18 times.
✗ Branch 8 (32→33) not taken.
✓ Branch 9 (32→36) taken 42 times.
|
42 | if((*itParent)->getType() != VecValueType::LIST_ITEM && (*itParent)->getType() != VecValueType::VALUE && |
| 90 | ✗ | child.getType() == VecValueType::LIST_ITEM) | |
| 91 | { | ||
| 92 | ✗ | isCurrentGreater = (*itParent)->getIndentation() >= childIndentation; | |
| 93 | } | ||
| 94 | } | ||
| 95 | //If we check with a > instead a >=, we have to check if the parent of a LIST_ITEM is a KEY | ||
| 96 | 124 | out = *itParent; | |
| 97 | 124 | ++itParent; | |
| 98 | } | ||
| 99 | 58 | return out; | |
| 100 | 58 | } | |
| 101 | |||
| 102 | ///Add the given child to the main VecValue and return a pointer to the added child | ||
| 103 | /** @param[out] mainVecValue : main VecValue to be used | ||
| 104 | * @param vecIndentation : vector of the last indentation of the children VecValue | ||
| 105 | * @param isCompactMode : true if the compact mode is enabled, false otherwise | ||
| 106 | * @param child : child VecValue to be added to the main VecValue | ||
| 107 | * @param currentIndentation : indentation of the current VecValue | ||
| 108 | * @return pointer to the added child (cannot be NULL) | ||
| 109 | */ | ||
| 110 | 188 | VecValue * addChildToParentVecValue(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ | |
| 111 | 188 | VecValue * parent = NULL; | |
| 112 |
2/2✓ Branch 0 (2→3) taken 4 times.
✓ Branch 1 (2→4) taken 184 times.
|
188 | if(isCompactMode){ |
| 113 | 4 | parent = &mainVecValue; | |
| 114 | }else{ | ||
| 115 |
1/2✓ Branch 0 (4→5) taken 184 times.
✗ Branch 1 (4→7) not taken.
|
184 | if(currentIndentation != -1lu){ |
| 116 | 184 | parent = getParentVecValue(mainVecValue, vecIndentation, currentIndentation); | |
| 117 | }else{ | ||
| 118 | ✗ | parent = getLastVecValue(mainVecValue); | |
| 119 | } | ||
| 120 | } | ||
| 121 | 188 | parent->getVecChild().push_back(child); | |
| 122 | 188 | return &(parent->getVecChild().back()); | |
| 123 | } | ||
| 124 | |||
| 125 | ///Add the given child to the main VecValue and return a pointer to the added child | ||
| 126 | /** @param[out] mainVecValue : main VecValue to be used | ||
| 127 | * @param vecIndentation : vector of the last indentation of the children VecValue | ||
| 128 | * @param isCompactMode : true if the compact mode is enabled, false otherwise | ||
| 129 | * @param child : child VecValue to be added to the main VecValue | ||
| 130 | * @param currentIndentation : indentation of the current VecValue | ||
| 131 | * @return pointer to the added child (cannot be NULL) | ||
| 132 | */ | ||
| 133 | 58 | VecValue * addChildToParentVecValueAddListItem(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ | |
| 134 | 58 | VecValue * parent = NULL; | |
| 135 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 58 times.
|
58 | if(isCompactMode){ |
| 136 | ✗ | parent = &mainVecValue; | |
| 137 | }else{ | ||
| 138 |
1/2✓ Branch 0 (4→5) taken 58 times.
✗ Branch 1 (4→7) not taken.
|
58 | if(currentIndentation != -1lu){ |
| 139 | 58 | parent = getParentVecValueListItem(mainVecValue, vecIndentation, currentIndentation, child); | |
| 140 | }else{ | ||
| 141 | ✗ | parent = getLastVecValue(mainVecValue); | |
| 142 | } | ||
| 143 | } | ||
| 144 | 58 | parent->getVecChild().push_back(child); | |
| 145 | 58 | return &(parent->getVecChild().back()); | |
| 146 | } | ||
| 147 | |||
| 148 | ///Convert a VecValue into a DicoValue | ||
| 149 | /** @param[out] dicoValue : converted DicoValue | ||
| 150 | * @param vecVal : vector of value | ||
| 151 | * @param isMainValue : true if the VecValue is the main one | ||
| 152 | */ | ||
| 153 | 135 | void vecValueToDicoValue(DicoValue & dicoValue, const VecValue & vecVal, bool isMainValue){ | |
| 154 |
2/2✓ Branch 0 (2→3) taken 135 times.
✓ Branch 2 (3→4) taken 135 times.
|
135 | PString key(vecVal.getKey()); |
| 155 |
1/1✓ Branch 0 (4→5) taken 135 times.
|
135 | const VecVecValue & vecChildren = vecVal.getVecChild(); |
| 156 |
2/2✓ Branch 0 (6→7) taken 88 times.
✓ Branch 1 (6→27) taken 47 times.
|
135 | if(vecChildren.size() == 0lu){ |
| 157 |
2/2✓ Branch 0 (7→8) taken 88 times.
✓ Branch 2 (8→9) taken 88 times.
|
88 | PString value(vecVal.getValue()); |
| 158 |
3/3✓ Branch 0 (9→10) taken 88 times.
✓ Branch 2 (10→11) taken 27 times.
✓ Branch 3 (10→17) taken 61 times.
|
88 | if(key == ""){ //The vecVal is a value only |
| 159 |
1/1✓ Branch 0 (11→12) taken 27 times.
|
27 | DicoValue subDico; |
| 160 |
1/1✓ Branch 0 (12→13) taken 27 times.
|
27 | subDico.setValue(value); |
| 161 |
2/2✓ Branch 0 (13→14) taken 27 times.
✓ Branch 2 (14→15) taken 27 times.
|
27 | dicoValue.getVecChild().push_back(subDico); |
| 162 | 27 | }else{ //The vecVal is a key-value | |
| 163 |
1/1✓ Branch 0 (17→18) taken 61 times.
|
61 | DicoValue subDico; |
| 164 |
1/1✓ Branch 0 (18→19) taken 61 times.
|
61 | subDico.setKey(key); |
| 165 |
1/1✓ Branch 0 (19→20) taken 61 times.
|
61 | subDico.setValue(value); |
| 166 |
3/3✓ Branch 0 (20→21) taken 61 times.
✓ Branch 2 (21→22) taken 61 times.
✓ Branch 4 (22→23) taken 61 times.
|
61 | dicoValue.getMapChild()[key] = subDico; |
| 167 | 61 | } | |
| 168 | 88 | }else{ | |
| 169 |
3/3✓ Branch 0 (27→28) taken 47 times.
✓ Branch 2 (28→29) taken 30 times.
✓ Branch 3 (28→52) taken 17 times.
|
47 | if(key != ""){ |
| 170 |
1/1✓ Branch 0 (29→30) taken 30 times.
|
30 | DicoValue subDico; |
| 171 |
2/2✓ Branch 0 (30→31) taken 30 times.
✓ Branch 2 (31→32) taken 30 times.
|
30 | subDico.setKey(vecVal.getKey()); |
| 172 |
2/2✓ Branch 0 (46→33) taken 79 times.
✓ Branch 1 (46→47) taken 30 times.
|
218 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
| 173 |
1/1✓ Branch 0 (35→36) taken 79 times.
|
79 | vecValueToDicoValue(subDico, *it, false); |
| 174 | } | ||
| 175 |
3/3✓ Branch 0 (47→48) taken 30 times.
✓ Branch 2 (48→49) taken 30 times.
✓ Branch 4 (49→50) taken 30 times.
|
30 | dicoValue.getMapChild()[key] = subDico; |
| 176 | 30 | }else{ | |
| 177 |
2/2✓ Branch 0 (52→53) taken 9 times.
✓ Branch 1 (52→69) taken 8 times.
|
17 | if(isMainValue){ |
| 178 |
2/2✓ Branch 0 (67→54) taken 39 times.
✓ Branch 1 (67→68) taken 9 times.
|
96 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
| 179 |
1/1✓ Branch 0 (56→57) taken 39 times.
|
39 | vecValueToDicoValue(dicoValue, *it, false); |
| 180 | } | ||
| 181 | }else{ | ||
| 182 |
1/1✓ Branch 0 (69→70) taken 8 times.
|
8 | DicoValue dashValue; |
| 183 |
2/2✓ Branch 0 (84→71) taken 8 times.
✓ Branch 1 (84→85) taken 8 times.
|
32 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
| 184 |
1/1✓ Branch 0 (73→74) taken 8 times.
|
8 | vecValueToDicoValue(dashValue, *it, false); |
| 185 | } | ||
| 186 |
2/2✓ Branch 0 (85→86) taken 8 times.
✓ Branch 2 (86→87) taken 8 times.
|
8 | dicoValue.getVecChild().push_back(dashValue); |
| 187 | 8 | } | |
| 188 | } | ||
| 189 | } | ||
| 190 | 135 | } | |
| 191 | |||
| 192 | ///Convert a VecValue into a ConfigNode | ||
| 193 | /** @param[out] dicoValue : converted ConfigNode | ||
| 194 | * @param vecVal : vector of value | ||
| 195 | * @param isMainValue : true if the VecValue is the main one | ||
| 196 | */ | ||
| 197 | 157 | void vecValueToConfigNode(ConfigNode & dicoValue, const VecValue & vecVal, bool isMainValue){ | |
| 198 |
2/2✓ Branch 0 (2→3) taken 157 times.
✓ Branch 2 (3→4) taken 157 times.
|
157 | PString key(vecVal.getKey()); |
| 199 |
1/1✓ Branch 0 (4→5) taken 157 times.
|
157 | const VecVecValue & vecChildren = vecVal.getVecChild(); |
| 200 |
2/2✓ Branch 0 (6→7) taken 104 times.
✓ Branch 1 (6→16) taken 53 times.
|
157 | if(vecChildren.size() == 0lu){ |
| 201 |
2/2✓ Branch 0 (7→8) taken 104 times.
✓ Branch 2 (8→9) taken 104 times.
|
104 | PString value(vecVal.getValue()); |
| 202 |
3/3✓ Branch 0 (9→10) taken 104 times.
✓ Branch 2 (10→11) taken 41 times.
✓ Branch 3 (10→12) taken 63 times.
|
104 | if(key == ""){ //The vecVal is a value only |
| 203 |
1/1✓ Branch 0 (11→14) taken 41 times.
|
41 | dicoValue.addValue(value); |
| 204 | }else{ //The vecVal is a key-value | ||
| 205 |
1/1✓ Branch 0 (12→13) taken 63 times.
|
63 | ConfigNode * subDico = dicoValue.addChild(key); |
| 206 |
1/1✓ Branch 0 (13→14) taken 63 times.
|
63 | subDico->setValue(value); |
| 207 | } | ||
| 208 | 104 | }else{ | |
| 209 |
3/3✓ Branch 0 (16→17) taken 53 times.
✓ Branch 2 (17→18) taken 34 times.
✓ Branch 3 (17→36) taken 19 times.
|
53 | if(key != ""){ |
| 210 |
1/1✓ Branch 0 (18→19) taken 34 times.
|
34 | ConfigNode * subDico = dicoValue.addChild(key); |
| 211 |
1/2✓ Branch 0 (19→20) taken 34 times.
✗ Branch 1 (19→73) not taken.
|
34 | if(subDico != NULL){ |
| 212 |
2/2✓ Branch 0 (34→21) taken 93 times.
✓ Branch 1 (34→35) taken 34 times.
|
254 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
| 213 |
1/1✓ Branch 0 (23→24) taken 93 times.
|
93 | vecValueToConfigNode(*subDico, *it, false); |
| 214 | } | ||
| 215 | } | ||
| 216 | }else{ | ||
| 217 |
2/2✓ Branch 0 (36→37) taken 11 times.
✓ Branch 1 (36→53) taken 8 times.
|
19 | if(isMainValue){ |
| 218 |
2/2✓ Branch 0 (51→38) taken 45 times.
✓ Branch 1 (51→52) taken 11 times.
|
112 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
| 219 |
1/1✓ Branch 0 (40→41) taken 45 times.
|
45 | vecValueToConfigNode(dicoValue, *it, false); |
| 220 | } | ||
| 221 | }else{ | ||
| 222 |
1/1✓ Branch 0 (54→55) taken 8 times.
|
8 | ConfigNode * dashValue = dicoValue.addChild(); |
| 223 |
1/2✓ Branch 0 (56→57) taken 8 times.
✗ Branch 1 (56→73) not taken.
|
8 | if(dashValue != NULL){ |
| 224 |
2/2✓ Branch 0 (71→58) taken 8 times.
✓ Branch 1 (71→72) taken 8 times.
|
32 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
| 225 |
1/1✓ Branch 0 (60→61) taken 8 times.
|
8 | vecValueToConfigNode(*dashValue, *it, false); |
| 226 | } | ||
| 227 | } | ||
| 228 | } | ||
| 229 | } | ||
| 230 | } | ||
| 231 | 157 | } | |
| 232 | |||
| 233 | |||
| 234 |