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 | 180 | VecValue * getLastVecValue(VecValue & vecVal, size_t depth){ | |
16 | 180 | VecVecValue & vecChildren = vecVal.getVecChild(); | |
17 |
6/6✓ Branch 0 (4→5) taken 146 times.
✓ Branch 1 (4→6) taken 34 times.
✓ Branch 2 (5→6) taken 55 times.
✓ Branch 3 (5→7) taken 91 times.
✓ Branch 4 (8→9) taken 89 times.
✓ Branch 5 (8→10) taken 91 times.
|
180 | if(vecChildren.size() == 0lu || depth == 0lu){return &vecVal;} |
18 | 91 | 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 | 89 | VecValue * getParentVecValue(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation){ | |
28 |
2/2✓ Branch 0 (3→4) taken 9 times.
✓ Branch 1 (3→6) taken 80 times.
|
89 | if(vecIndentation.size() == 0lu){ |
29 |
1/1✓ Branch 0 (4→5) taken 9 times.
|
9 | return getLastVecValue(vecAllVal); |
30 | } | ||
31 | 80 | size_t depth(0lu); | |
32 | 80 | std::vector<size_t>::const_iterator it(vecIndentation.begin()); | |
33 | 80 | bool isCurrentLower(true); | |
34 |
6/6✓ Branch 0 (15→16) taken 171 times.
✓ Branch 1 (15→25) taken 55 times.
✓ Branch 2 (23→24) taken 146 times.
✓ Branch 3 (23→25) taken 25 times.
✓ Branch 4 (26→8) taken 146 times.
✓ Branch 5 (26→27) taken 80 times.
|
397 | while(isCurrentLower && it != vecIndentation.end()){ |
35 | 146 | isCurrentLower = *it < currentIndentation; | |
36 |
2/2✓ Branch 0 (10→11) taken 91 times.
✓ Branch 1 (10→12) taken 55 times.
|
146 | if(isCurrentLower){ |
37 | 91 | ++depth; | |
38 | } | ||
39 | ++it; | ||
40 | } | ||
41 |
1/1✓ Branch 0 (27→28) taken 80 times.
|
80 | VecValue * out = getLastVecValue(vecAllVal, depth); |
42 | 80 | 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 | 72 | void getVecParentPtr(std::vector<VecValue*> & vecParentPtr, VecValue & vecAllVal){ | |
50 |
1/1✓ Branch 0 (2→3) taken 72 times.
|
72 | vecParentPtr.push_back(&vecAllVal); |
51 |
2/2✓ Branch 0 (5→6) taken 50 times.
✓ Branch 1 (5→9) taken 22 times.
|
72 | if(vecAllVal.getVecChild().size() != 0lu){ |
52 | 50 | getVecParentPtr(vecParentPtr, vecAllVal.getVecChild().back()); | |
53 | } | ||
54 | 72 | } | |
55 | |||
56 | ///Get the parent pointer vector | ||
57 | /** @param vecAllVal : Main VecValue | ||
58 | * @return vector of pointer of all parent chain | ||
59 | */ | ||
60 | 22 | std::vector<VecValue*> getVecParentPtr(VecValue & vecAllVal){ | |
61 | 22 | std::vector<VecValue*> vecParentPtr; | |
62 |
1/1✓ Branch 0 (3→4) taken 22 times.
|
22 | getVecParentPtr(vecParentPtr, vecAllVal); |
63 | 22 | 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 | 22 | 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 22 times.
|
22 | if(vecIndentation.size() == 0lu){ |
75 | ✗ | return getLastVecValue(vecAllVal); | |
76 | } | ||
77 |
1/1✓ Branch 0 (6→7) taken 22 times.
|
22 | size_t childIndentation(child.getIndentation()); |
78 | 22 | VecValue * out = NULL; | |
79 |
1/1✓ Branch 0 (7→8) taken 22 times.
|
22 | std::vector<VecValue*> vecParentPtr = getVecParentPtr(vecAllVal); |
80 | 22 | std::vector<VecValue*>::const_reverse_iterator itParent(vecParentPtr.rbegin()); | |
81 | 22 | bool isCurrentGreater(true); | |
82 |
5/6✓ Branch 0 (38→39) taken 50 times.
✓ Branch 1 (38→43) taken 22 times.
✓ Branch 2 (41→42) taken 50 times.
✗ Branch 3 (41→43) not taken.
✓ Branch 4 (44→11) taken 50 times.
✓ Branch 5 (44→45) taken 22 times.
|
72 | while(isCurrentGreater && itParent != vecParentPtr.rend()){ |
83 |
7/8✓ Branch 0 (12→13) taken 50 times.
✓ Branch 2 (13→14) taken 34 times.
✓ Branch 3 (13→17) taken 16 times.
✓ Branch 4 (14→15) taken 34 times.
✓ Branch 6 (15→16) taken 34 times.
✗ Branch 7 (15→17) not taken.
✓ Branch 8 (18→19) taken 34 times.
✓ Branch 9 (18→22) taken 16 times.
|
50 | if((*itParent)->getType() == VecValueType::KEY && child.getType() == VecValueType::LIST_ITEM){ |
84 |
1/1✓ Branch 0 (20→21) taken 34 times.
|
34 | 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 16 times.
✓ Branch 2 (24→25) taken 6 times.
✓ Branch 3 (24→31) taken 10 times.
✓ Branch 4 (26→27) taken 6 times.
✗ Branch 6 (27→28) not taken.
✓ Branch 7 (27→31) taken 6 times.
✗ Branch 8 (32→33) not taken.
✓ Branch 9 (32→36) taken 16 times.
|
16 | 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 | 50 | out = *itParent; | |
97 | 50 | ++itParent; | |
98 | } | ||
99 | 22 | return out; | |
100 | 22 | } | |
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 | 91 | VecValue * addChildToParentVecValue(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ | |
111 | 91 | VecValue * parent = NULL; | |
112 |
2/2✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→4) taken 89 times.
|
91 | if(isCompactMode){ |
113 | 2 | parent = &mainVecValue; | |
114 | }else{ | ||
115 |
1/2✓ Branch 0 (4→5) taken 89 times.
✗ Branch 1 (4→7) not taken.
|
89 | if(currentIndentation != -1lu){ |
116 | 89 | parent = getParentVecValue(mainVecValue, vecIndentation, currentIndentation); | |
117 | }else{ | ||
118 | ✗ | parent = getLastVecValue(mainVecValue); | |
119 | } | ||
120 | } | ||
121 | 91 | parent->getVecChild().push_back(child); | |
122 | 91 | 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 | 22 | VecValue * addChildToParentVecValueAddListItem(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ | |
134 | 22 | VecValue * parent = NULL; | |
135 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 22 times.
|
22 | if(isCompactMode){ |
136 | ✗ | parent = &mainVecValue; | |
137 | }else{ | ||
138 |
1/2✓ Branch 0 (4→5) taken 22 times.
✗ Branch 1 (4→7) not taken.
|
22 | if(currentIndentation != -1lu){ |
139 | 22 | parent = getParentVecValueListItem(mainVecValue, vecIndentation, currentIndentation, child); | |
140 | }else{ | ||
141 | ✗ | parent = getLastVecValue(mainVecValue); | |
142 | } | ||
143 | } | ||
144 | 22 | parent->getVecChild().push_back(child); | |
145 | 22 | 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 | |||
193 |