GCC Code Coverage Report


Directory: ./
File: src/ConfigNode.cpp
Date: 2025-11-27 16:44:16
Exec Total Coverage
Lines: 93 115 80.9%
Functions: 26 34 76.5%
Branches: 50 70 71.4%

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 "ConfigNode.h"
9
10 ///Constructor of class ConfigNode
11
3/3
✓ Branch 0 (3→4) taken 39 times.
✓ Branch 2 (6→7) taken 39 times.
✓ Branch 4 (7→8) taken 39 times.
39 ConfigNode::ConfigNode(){
12
1/1
✓ Branch 0 (9→10) taken 39 times.
39 initialisationConfigNode();
13 39 }
14
15 ///Destructor of class ConfigNode
16 69 ConfigNode::~ConfigNode(){
17 39 clear();
18 69 }
19
20 ///Sets the value of the ConfigNode
21 /** @param value : value of the ConfigNode
22 */
23 24 void ConfigNode::setValue(const PString & value){
24 24 p_value = value;
25 24 }
26
27 ///Sets the name of the ConfigNode
28 /** @param name : name of the ConfigNode
29 */
30 30 void ConfigNode::setName(const PString & name){
31 30 p_name = name;
32 30 }
33
34 ///Sets the vecChild of the ConfigNode
35 /** @param vecChild : vecChild of the ConfigNode
36 */
37 void ConfigNode::setVecChild(const std::vector<ConfigNode*> & vecChild){
38 p_vecChild = vecChild;
39 }
40
41 ///Sets the mapChild of the ConfigNode
42 /** @param mapChild : mapChild of the ConfigNode
43 */
44 void ConfigNode::setMapChild(const std::map<PString, ConfigNode*> & mapChild){
45 p_mapChild = mapChild;
46 }
47
48 ///Sets the location of the ConfigNode
49 /** @param location : location of the ConfigNode
50 */
51 void ConfigNode::setLocation(const PLocation & location){
52 p_location = location;
53 }
54
55 ///Sets the parent of the ConfigNode
56 /** @param parent : parent of the ConfigNode
57 */
58 30 void ConfigNode::setParent(const ConfigNode* parent){
59 30 p_parent = parent;
60 30 }
61
62 ///Gets the value of the ConfigNode
63 /** @return value of the ConfigNode
64 */
65 26 const PString & ConfigNode::getValue() const{
66 26 return p_value;
67 }
68
69 ///Gets the value of the ConfigNode
70 /** @return value of the ConfigNode
71 */
72 PString & ConfigNode::getValue(){
73 return p_value;
74 }
75
76 ///Gets the name of the ConfigNode
77 /** @return name of the ConfigNode
78 */
79 18 const PString & ConfigNode::getName() const{
80 18 return p_name;
81 }
82
83 ///Gets the name of the ConfigNode
84 /** @return name of the ConfigNode
85 */
86 PString & ConfigNode::getName(){
87 return p_name;
88 }
89
90 ///Gets the vecChild of the ConfigNode
91 /** @return vecChild of the ConfigNode
92 */
93 18 const std::vector<ConfigNode*> & ConfigNode::getVecChild() const{
94 18 return p_vecChild;
95 }
96
97 ///Gets the vecChild of the ConfigNode
98 /** @return vecChild of the ConfigNode
99 */
100 1 std::vector<ConfigNode*> & ConfigNode::getVecChild(){
101 1 return p_vecChild;
102 }
103
104 ///Gets the mapChild of the ConfigNode
105 /** @return mapChild of the ConfigNode
106 */
107 18 const std::map<PString, ConfigNode*> & ConfigNode::getMapChild() const{
108 18 return p_mapChild;
109 }
110
111 ///Gets the mapChild of the ConfigNode
112 /** @return mapChild of the ConfigNode
113 */
114 std::map<PString, ConfigNode*> & ConfigNode::getMapChild(){
115 return p_mapChild;
116 }
117
118 ///Gets the location of the ConfigNode
119 /** @return location of the ConfigNode
120 */
121 7 PLocation ConfigNode::getLocation() const{
122 7 PLocation loc = p_location;
123
2/2
✓ Branch 0 (3→4) taken 7 times.
✓ Branch 2 (4→5) taken 7 times.
7 loc.setFileName(getFileName());
124 7 return loc;
125 }
126
127 ///Gets the parent of the ConfigNode
128 /** @return parent of the ConfigNode
129 */
130 5 const ConfigNode* ConfigNode::getParent() const{
131 5 return p_parent;
132 }
133
134 ///Set the fileName of the current ConfigNode
135 /** @param fileName : file name of the current ConfigNode
136 */
137 1 void ConfigNode::setFileName(const PPath & fileName){
138
1/2
✗ Branch 0 (4→5) not taken.
✓ Branch 1 (4→6) taken 1 times.
1 if(p_location.getFileName() == fileName){return;} //If we already have this file name, we return
139
1/2
✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→25) taken 1 times.
1 if(p_location.getFileName() != ""){ //These is alread a file name, so we propagate it in the children and we set it after for the new comers
140 for(std::vector<ConfigNode*>::iterator it(p_vecChild.begin()); it != p_vecChild.end(); ++it){
141 (*it)->setFileName(fileName);
142 }
143 }
144 1 p_location.setFileName(fileName);
145 }
146
147 ///Get current file name
148 /** @return current file name
149 */
150 16 const PPath & ConfigNode::getFileName() const{
151
2/2
✓ Branch 0 (4→5) taken 14 times.
✓ Branch 1 (4→8) taken 2 times.
16 if(p_location.getFileName() == ""){
152
2/2
✓ Branch 0 (5→6) taken 9 times.
✓ Branch 1 (5→8) taken 5 times.
14 if(p_parent != NULL){
153 9 return p_parent->getFileName();
154 }
155 }
156 7 return p_location.getFileName();
157 }
158
159 ///Set the line and the column of the current ConfigNode
160 /** @param location : PLocation which contains line and column of the current ConfigNode
161 */
162 51 void ConfigNode::setLineCol(const PLocation & location){
163
5/6
✓ Branch 0 (3→4) taken 27 times.
✓ Branch 1 (3→7) taken 24 times.
✓ Branch 2 (5→6) taken 27 times.
✗ Branch 3 (5→7) not taken.
✓ Branch 4 (8→9) taken 27 times.
✓ Branch 5 (8→13) taken 24 times.
51 if(p_location.getLine() == 0lu && p_location.getColumn() == 0lu){
164 27 p_location.setLine(location.getLine());
165 27 p_location.setColumn(location.getColumn());
166 }
167 51 }
168
169 ///Add a child in the current ConfigNode
170 /** @param name : name of the child
171 * @return pointer to the created child, or NULL if the child with name already exist
172 */
173 33 ConfigNode * ConfigNode::addChild(const PString & name){
174
2/2
✓ Branch 0 (2→3) taken 33 times.
✓ Branch 2 (3→4) taken 33 times.
33 PString childName = name.eraseFirstLastChar("\"'");
175
3/3
✓ Branch 0 (5→6) taken 33 times.
✓ Branch 2 (6→7) taken 26 times.
✓ Branch 3 (6→10) taken 7 times.
33 if(name != ""){
176
3/3
✓ Branch 0 (7→8) taken 26 times.
✓ Branch 2 (8→9) taken 3 times.
✓ Branch 3 (8→10) taken 23 times.
26 if(getChild(childName) != NULL){
177 3 return NULL;
178 }
179 }
180
3/6
✓ Branch 0 (10→11) taken 30 times.
✓ Branch 2 (11→12) taken 30 times.
✗ Branch 4 (12→13) not taken.
✓ Branch 5 (12→14) taken 30 times.
✗ Branch 6 (28→29) not taken.
✗ Branch 7 (28→30) not taken.
30 ConfigNode* child = new ConfigNode;
181
1/1
✓ Branch 0 (14→15) taken 30 times.
30 child->setName(name);
182
1/1
✓ Branch 0 (15→16) taken 30 times.
30 child->setParent(this);
183
1/1
✓ Branch 0 (16→17) taken 30 times.
30 p_vecChild.push_back(child);
184
3/3
✓ Branch 0 (17→18) taken 30 times.
✓ Branch 2 (18→19) taken 23 times.
✓ Branch 3 (18→21) taken 7 times.
30 if(name != ""){
185
1/1
✓ Branch 0 (19→20) taken 23 times.
23 p_mapChild[childName] = child;
186 }
187 30 return child;
188 33 }
189
190 ///Get the child of the given name
191 /** @param name : name of the child
192 * @return pointer to the corresponding child, or NULL is it does not exist
193 */
194 46 ConfigNode * ConfigNode::getChild(const PString & name){
195
1/1
✓ Branch 0 (2→3) taken 46 times.
46 std::map<PString, ConfigNode*>::iterator it(p_mapChild.find(name));
196
2/2
✓ Branch 0 (5→6) taken 20 times.
✓ Branch 1 (5→8) taken 26 times.
46 if(it != p_mapChild.end()){
197 20 return it->second;
198 }else{
199 26 return NULL;
200 }
201 }
202
203 ///Get the child of the given name
204 /** @param name : name of the child
205 * @return pointer to the corresponding child, or NULL is it does not exist
206 */
207 11 const ConfigNode * ConfigNode::getChild(const PString & name) const{
208
1/1
✓ Branch 0 (2→3) taken 11 times.
11 std::map<PString, ConfigNode*>::const_iterator it(p_mapChild.find(name));
209
2/2
✓ Branch 0 (5→6) taken 7 times.
✓ Branch 1 (5→8) taken 4 times.
11 if(it != p_mapChild.end()){
210 7 return it->second;
211 }else{
212 4 return NULL;
213 }
214 }
215
216 ///Add a value in the ConfigNode
217 /** @param value : value to be added in the ConfigNode
218 * @return pointer to the added value
219 */
220 3 ConfigNode * ConfigNode::addValue(const PString & value){
221
2/2
✓ Branch 0 (2→3) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
3 ConfigNode * child = addChild("");
222 3 child->setValue(value);
223 3 return child;
224 }
225
226 ///Get string value without " or ' at the beginning of the end
227 /** @return value without " or ' at the beginning of the end
228 */
229 15 PString ConfigNode::getString() const{
230
2/2
✓ Branch 0 (3→4) taken 15 times.
✓ Branch 2 (4→5) taken 15 times.
15 return getValue().eraseFirstLastChar("\"'");
231 }
232
233 ///Say if the current ConfigNode has a value
234 /** @return true if the current ConfigNode has a value
235 */
236 6 bool ConfigNode::hasValue() const{
237
2/4
✓ Branch 0 (3→4) taken 6 times.
✗ Branch 1 (3→7) not taken.
✓ Branch 2 (5→6) taken 6 times.
✗ Branch 3 (5→7) not taken.
6 return p_vecChild.size() == 0lu && p_mapChild.size() == 0lu;
238 }
239
240 ///Say if the current ConfigNode has a vector of children
241 /** @return true if the current ConfigNode has a vector of children
242 */
243 bool ConfigNode::hasVecChild() const{
244 return p_vecChild.size() != 0lu && p_mapChild.size() == 0lu;
245 }
246
247 ///Say if the current ConfigNode has a map of children
248 /** @return true if the current ConfigNode has a map of children
249 */
250 bool ConfigNode::hasMapChild() const{
251 return p_vecChild.size() != 0lu && p_mapChild.size() != 0lu;
252 }
253
254 ///Clear the vector of children
255 39 void ConfigNode::clear(){
256
2/2
✓ Branch 0 (17→3) taken 30 times.
✓ Branch 1 (17→18) taken 39 times.
138 for(std::vector<ConfigNode*>::iterator it(p_vecChild.begin()); it != p_vecChild.end(); ++it){
257
1/2
✓ Branch 0 (5→6) taken 30 times.
✗ Branch 1 (5→7) not taken.
30 delete *it;
258 }
259 39 p_vecChild.clear();
260 39 p_mapChild.clear();
261 39 }
262
263 ///Create an iterator of ConfigNode
264 /** @param[out] out : std::ostream to be used for the error messages
265 * @return corresponding ConfigNodeIter
266 */
267 2 ConfigNodeIter ConfigNode::iter(std::ostream & out) const{
268 2 ConfigNodeIter it(this, &out, false);
269 2 return it;
270 }
271
272 ///Create an iterator of ConfigNode
273 /** @param[out] out : std::ostream to be used for the error messages
274 * @return corresponding ConfigNodeIter
275 */
276 1 ConfigNodeIter ConfigNode::iterWrite(std::ostream & out){
277 1 ConfigNodeIter it(this, &out, true);
278 1 return it;
279 }
280
281 ///Initialisation Function of class ConfigNode
282 39 void ConfigNode::initialisationConfigNode(){
283 39 p_value = "";
284 39 p_name = "";
285 39 p_parent = NULL;
286 39 }
287
288