Directory: | ./ |
---|---|
File: | tmp_project/PhoenixYml/src/vec_value_utils.cpp |
Date: | 2025-03-27 14:50:11 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 88 | 94 | 93.6% |
Branches: | 91 | 107 | 85.0% |
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 | 297 | VecValue * getLastVecValue(VecValue & vecVal, size_t depth){ | |
16 | 297 | VecVecValue & vecChildren = vecVal.getVecChild(); | |
17 |
6/6✓ Branch 1 taken 254 times.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 87 times.
✓ Branch 4 taken 167 times.
✓ Branch 5 taken 130 times.
✓ Branch 6 taken 167 times.
|
297 | if(vecChildren.size() == 0lu || depth == 0lu){return &vecVal;} |
18 | 167 | 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 | 130 | VecValue * getParentVecValue(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation){ | |
28 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 118 times.
|
130 | if(vecIndentation.size() == 0lu){ |
29 |
1/1✓ Branch 1 taken 12 times.
|
12 | return getLastVecValue(vecAllVal); |
30 | } | ||
31 | 118 | size_t depth(0lu); | |
32 | 118 | std::vector<size_t>::const_iterator it(vecIndentation.begin()); | |
33 | 118 | bool isCurrentLower(true); | |
34 |
6/6✓ Branch 0 taken 285 times.
✓ Branch 1 taken 87 times.
✓ Branch 4 taken 254 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 254 times.
✓ Branch 7 taken 118 times.
|
372 | while(isCurrentLower && it != vecIndentation.end()){ |
35 | 254 | isCurrentLower = *it < currentIndentation; | |
36 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 87 times.
|
254 | if(isCurrentLower){ |
37 | 167 | ++depth; | |
38 | } | ||
39 | 254 | ++it; | |
40 | } | ||
41 |
1/1✓ Branch 1 taken 118 times.
|
118 | VecValue * out = getLastVecValue(vecAllVal, depth); |
42 | 118 | 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 | 90 | void getVecParentPtr(std::vector<VecValue*> & vecParentPtr, VecValue & vecAllVal){ | |
50 |
1/1✓ Branch 1 taken 90 times.
|
90 | vecParentPtr.push_back(&vecAllVal); |
51 |
2/2✓ Branch 2 taken 62 times.
✓ Branch 3 taken 28 times.
|
90 | if(vecAllVal.getVecChild().size() != 0lu){ |
52 | 62 | getVecParentPtr(vecParentPtr, vecAllVal.getVecChild().back()); | |
53 | } | ||
54 | 90 | } | |
55 | |||
56 | ///Get the parent pointer vector | ||
57 | /** @param vecAllVal : Main VecValue | ||
58 | * @return vector of pointer of all parent chain | ||
59 | */ | ||
60 | 28 | std::vector<VecValue*> getVecParentPtr(VecValue & vecAllVal){ | |
61 | 28 | std::vector<VecValue*> vecParentPtr; | |
62 |
1/1✓ Branch 1 taken 28 times.
|
28 | getVecParentPtr(vecParentPtr, vecAllVal); |
63 | 28 | 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 | 28 | VecValue * getParentVecValueListItem(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation, const VecValue & child){ | |
74 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
|
28 | if(vecIndentation.size() == 0lu){ |
75 | ✗ | return getLastVecValue(vecAllVal); | |
76 | } | ||
77 |
1/1✓ Branch 1 taken 28 times.
|
28 | size_t childIndentation(child.getIndentation()); |
78 | 28 | VecValue * out = NULL; | |
79 |
1/1✓ Branch 1 taken 28 times.
|
28 | std::vector<VecValue*> vecParentPtr = getVecParentPtr(vecAllVal); |
80 | 28 | std::vector<VecValue*>::const_reverse_iterator itParent(vecParentPtr.rbegin()); | |
81 | 28 | bool isCurrentGreater(true); | |
82 |
6/7✓ Branch 0 taken 62 times.
✓ Branch 1 taken 28 times.
✓ Branch 4 taken 62 times.
✓ Branch 6 taken 62 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 62 times.
✓ Branch 9 taken 28 times.
|
90 | while(isCurrentGreater && itParent != vecParentPtr.rend()){ |
83 |
7/8✓ Branch 2 taken 62 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 19 times.
✓ Branch 7 taken 43 times.
✓ Branch 9 taken 43 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 43 times.
✓ Branch 12 taken 19 times.
|
62 | if((*itParent)->getType() == VecValueType::KEY && child.getType() == VecValueType::LIST_ITEM){ |
84 |
1/1✓ Branch 2 taken 43 times.
|
43 | 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 2 taken 19 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 13 times.
✓ Branch 8 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 19 times.
|
19 | 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 | 62 | out = *itParent; | |
97 | 62 | ++itParent; | |
98 | } | ||
99 | 28 | return out; | |
100 | 28 | } | |
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 | 132 | VecValue * addChildToParentVecValue(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ | |
111 | 132 | VecValue * parent = NULL; | |
112 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 130 times.
|
132 | if(isCompactMode){ |
113 | 2 | parent = &mainVecValue; | |
114 | }else{ | ||
115 |
1/2✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
|
130 | if(currentIndentation != -1lu){ |
116 | 130 | parent = getParentVecValue(mainVecValue, vecIndentation, currentIndentation); | |
117 | }else{ | ||
118 | ✗ | parent = getLastVecValue(mainVecValue); | |
119 | } | ||
120 | } | ||
121 | 132 | parent->getVecChild().push_back(child); | |
122 | 132 | 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 | 28 | VecValue * addChildToParentVecValueAddListItem(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ | |
134 | 28 | VecValue * parent = NULL; | |
135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if(isCompactMode){ |
136 | ✗ | parent = &mainVecValue; | |
137 | }else{ | ||
138 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if(currentIndentation != -1lu){ |
139 | 28 | parent = getParentVecValueListItem(mainVecValue, vecIndentation, currentIndentation, child); | |
140 | }else{ | ||
141 | ✗ | parent = getLastVecValue(mainVecValue); | |
142 | } | ||
143 | } | ||
144 | 28 | parent->getVecChild().push_back(child); | |
145 | 28 | 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 | 185 | void vecValueToDicoValue(DicoValue & dicoValue, const VecValue & vecVal, bool isMainValue){ | |
154 |
2/2✓ Branch 1 taken 185 times.
✓ Branch 4 taken 185 times.
|
185 | PString key(vecVal.getKey()); |
155 |
1/1✓ Branch 1 taken 185 times.
|
185 | const VecVecValue & vecChildren = vecVal.getVecChild(); |
156 |
2/2✓ Branch 1 taken 126 times.
✓ Branch 2 taken 59 times.
|
185 | if(vecChildren.size() == 0lu){ |
157 |
2/2✓ Branch 1 taken 126 times.
✓ Branch 4 taken 126 times.
|
126 | PString value(vecVal.getValue()); |
158 |
2/2✓ Branch 1 taken 27 times.
✓ Branch 2 taken 99 times.
|
126 | if(key == ""){ //The vecVal is a value only |
159 |
1/1✓ Branch 1 taken 27 times.
|
27 | DicoValue subDico; |
160 |
1/1✓ Branch 1 taken 27 times.
|
27 | subDico.setValue(value); |
161 |
2/2✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
|
27 | dicoValue.getVecChild().push_back(subDico); |
162 | 27 | }else{ //The vecVal is a key-value | |
163 |
1/1✓ Branch 1 taken 99 times.
|
99 | DicoValue subDico; |
164 |
1/1✓ Branch 1 taken 99 times.
|
99 | subDico.setKey(key); |
165 |
1/1✓ Branch 1 taken 99 times.
|
99 | subDico.setValue(value); |
166 |
3/3✓ Branch 1 taken 99 times.
✓ Branch 4 taken 99 times.
✓ Branch 7 taken 99 times.
|
99 | dicoValue.getMapChild()[key] = subDico; |
167 | 99 | } | |
168 | 126 | }else{ | |
169 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 2 taken 26 times.
|
59 | if(key != ""){ |
170 |
1/1✓ Branch 1 taken 33 times.
|
33 | DicoValue subDico; |
171 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
|
33 | subDico.setKey(vecVal.getKey()); |
172 |
2/2✓ Branch 4 taken 85 times.
✓ Branch 5 taken 33 times.
|
118 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
173 |
1/1✓ Branch 2 taken 85 times.
|
85 | vecValueToDicoValue(subDico, *it, false); |
174 | } | ||
175 |
3/3✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
✓ Branch 7 taken 33 times.
|
33 | dicoValue.getMapChild()[key] = subDico; |
176 | 33 | }else{ | |
177 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 14 times.
|
26 | if(isMainValue){ |
178 |
2/2✓ Branch 4 taken 42 times.
✓ Branch 5 taken 12 times.
|
54 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
179 |
1/1✓ Branch 2 taken 42 times.
|
42 | vecValueToDicoValue(dicoValue, *it, false); |
180 | } | ||
181 | }else{ | ||
182 |
1/1✓ Branch 1 taken 14 times.
|
14 | DicoValue dashValue; |
183 |
2/2✓ Branch 4 taken 46 times.
✓ Branch 5 taken 14 times.
|
60 | for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
184 |
1/1✓ Branch 2 taken 46 times.
|
46 | vecValueToDicoValue(dashValue, *it, false); |
185 | } | ||
186 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | dicoValue.getVecChild().push_back(dashValue); |
187 | 14 | } | |
188 | } | ||
189 | } | ||
190 | 185 | } | |
191 | |||
192 | |||
193 |