GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 |
504 |
VecValue * getLastVecValue(VecValue & vecVal, size_t depth){ |
|
16 |
504 |
VecVecValue & vecChildren = vecVal.getVecChild(); |
|
17 |
✓✓✓✓ ✓✓ |
504 |
if(vecChildren.size() == 0lu || depth == 0lu){return &vecVal;} |
18 |
233 |
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 |
271 |
VecValue * getParentVecValue(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation){ |
|
28 |
✓✓ | 271 |
if(vecIndentation.size() == 0lu){ |
29 |
✓ | 18 |
return getLastVecValue(vecAllVal); |
30 |
} |
||
31 |
253 |
size_t depth(0lu); |
|
32 |
253 |
std::vector<size_t>::const_iterator it(vecIndentation.begin()); |
|
33 |
253 |
bool isCurrentLower(true); |
|
34 |
✓✓✓✓ ✓✓ |
681 |
while(isCurrentLower && it != vecIndentation.end()){ |
35 |
428 |
isCurrentLower = *it < currentIndentation; |
|
36 |
✓✓ | 428 |
if(isCurrentLower){ |
37 |
233 |
++depth; |
|
38 |
} |
||
39 |
428 |
++it; |
|
40 |
} |
||
41 |
✓ | 253 |
VecValue * out = getLastVecValue(vecAllVal, depth); |
42 |
253 |
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 |
82 |
void getVecParentPtr(std::vector<VecValue*> & vecParentPtr, VecValue & vecAllVal){ |
|
50 |
✓ | 82 |
vecParentPtr.push_back(&vecAllVal); |
51 |
✓✓ | 82 |
if(vecAllVal.getVecChild().size() != 0lu){ |
52 |
56 |
getVecParentPtr(vecParentPtr, vecAllVal.getVecChild().back()); |
|
53 |
} |
||
54 |
82 |
} |
|
55 |
|||
56 |
///Get the parent pointer vector |
||
57 |
/** @param vecAllVal : Main VecValue |
||
58 |
* @return vector of pointer of all parent chain |
||
59 |
*/ |
||
60 |
26 |
std::vector<VecValue*> getVecParentPtr(VecValue & vecAllVal){ |
|
61 |
26 |
std::vector<VecValue*> vecParentPtr; |
|
62 |
✓ | 26 |
getVecParentPtr(vecParentPtr, vecAllVal); |
63 |
26 |
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 |
26 |
VecValue * getParentVecValueListItem(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation, const VecValue & child){ |
|
74 |
✗✓ | 26 |
if(vecIndentation.size() == 0lu){ |
75 |
return getLastVecValue(vecAllVal); |
||
76 |
} |
||
77 |
✓ | 26 |
size_t childIndentation(child.getIndentation()); |
78 |
26 |
VecValue * out = NULL; |
|
79 |
✓ | 26 |
std::vector<VecValue*> vecParentPtr = getVecParentPtr(vecAllVal); |
80 |
✓ | 26 |
std::vector<VecValue*>::const_reverse_iterator itParent(vecParentPtr.rbegin()); |
81 |
26 |
bool isCurrentGreater(true); |
|
82 |
✓✓✓✓ ✗✓✓ |
82 |
while(isCurrentGreater && itParent != vecParentPtr.rend()){ |
83 |
✓✓✓✓ ✓✗✓✓ |
56 |
if((*itParent)->getType() == VecValueType::KEY && child.getType() == VecValueType::LIST_ITEM){ |
84 |
✓ | 38 |
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 |
✓✓✓✓ ✗✓✗✓ |
18 |
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 |
56 |
out = *itParent; |
|
97 |
56 |
++itParent; |
|
98 |
} |
||
99 |
26 |
return out; |
|
100 |
} |
||
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 |
273 |
VecValue * addChildToParentVecValue(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ |
|
111 |
273 |
VecValue * parent = NULL; |
|
112 |
✓✓ | 273 |
if(isCompactMode){ |
113 |
2 |
parent = &mainVecValue; |
|
114 |
}else{ |
||
115 |
✓✗ | 271 |
if(currentIndentation != -1lu){ |
116 |
271 |
parent = getParentVecValue(mainVecValue, vecIndentation, currentIndentation); |
|
117 |
}else{ |
||
118 |
parent = getLastVecValue(mainVecValue); |
||
119 |
} |
||
120 |
} |
||
121 |
273 |
parent->getVecChild().push_back(child); |
|
122 |
273 |
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 |
26 |
VecValue * addChildToParentVecValueAddListItem(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){ |
|
134 |
26 |
VecValue * parent = NULL; |
|
135 |
✗✓ | 26 |
if(isCompactMode){ |
136 |
parent = &mainVecValue; |
||
137 |
}else{ |
||
138 |
✓✗ | 26 |
if(currentIndentation != -1lu){ |
139 |
26 |
parent = getParentVecValueListItem(mainVecValue, vecIndentation, currentIndentation, child); |
|
140 |
}else{ |
||
141 |
parent = getLastVecValue(mainVecValue); |
||
142 |
} |
||
143 |
} |
||
144 |
26 |
parent->getVecChild().push_back(child); |
|
145 |
26 |
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 |
345 |
void vecValueToDicoValue(DicoValue & dicoValue, const VecValue & vecVal, bool isMainValue){ |
|
154 |
✓✓ | 690 |
std::string key(vecVal.getKey()); |
155 |
✓ | 345 |
const VecVecValue & vecChildren = vecVal.getVecChild(); |
156 |
✓✓ | 345 |
if(vecChildren.size() == 0lu){ |
157 |
✓✓ | 488 |
std::string value(vecVal.getValue()); |
158 |
✓✓ | 244 |
if(key == ""){ //The vecVal is a value only |
159 |
✓ | 84 |
DicoValue subDico; |
160 |
✓ | 42 |
subDico.setValue(value); |
161 |
✓✓ | 42 |
dicoValue.getVecChild().push_back(subDico); |
162 |
}else{ //The vecVal is a key-value |
||
163 |
✓ | 404 |
DicoValue subDico; |
164 |
✓ | 202 |
subDico.setKey(key); |
165 |
✓ | 202 |
subDico.setValue(value); |
166 |
✓✓✓ | 202 |
dicoValue.getMapChild()[key] = subDico; |
167 |
} |
||
168 |
}else{ |
||
169 |
✓✓ | 101 |
if(key != ""){ |
170 |
✓ | 142 |
DicoValue subDico; |
171 |
✓✓ | 71 |
subDico.setKey(vecVal.getKey()); |
172 |
✓✓ | 254 |
for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
173 |
✓ | 183 |
vecValueToDicoValue(subDico, *it, false); |
174 |
} |
||
175 |
✓✓✓ | 71 |
dicoValue.getMapChild()[key] = subDico; |
176 |
}else{ |
||
177 |
✓✓ | 30 |
if(isMainValue){ |
178 |
✓✓ | 150 |
for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
179 |
✓ | 132 |
vecValueToDicoValue(dicoValue, *it, false); |
180 |
} |
||
181 |
}else{ |
||
182 |
✓ | 24 |
DicoValue dashValue; |
183 |
✓✓ | 24 |
for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){ |
184 |
✓ | 12 |
vecValueToDicoValue(dashValue, *it, false); |
185 |
} |
||
186 |
✓✓ | 12 |
dicoValue.getVecChild().push_back(dashValue); |
187 |
} |
||
188 |
} |
||
189 |
} |
||
190 |
345 |
} |
|
191 |
|||
192 |
Generated by: GCOVR (Version 4.2) |