GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/FileParser/src/vec_value_utils.cpp Lines: 52 53 98.1 %
Date: 2023-10-11 10:52:07 Branches: 62 63 98.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 "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
357
VecValue * getLastVecValue(VecValue & vecVal, size_t depth){
16
357
	VecVecValue & vecChildren = vecVal.getVecChild();
17

357
	if(vecChildren.size() == 0lu || depth == 0lu){return &vecVal;}
18
162
	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
195
VecValue * getParentVecValue(VecValue & vecAllVal, const std::vector<size_t> & vecIndentation, size_t currentIndentation){
28
195
	if(vecIndentation.size() == 0lu){
29
15
		return getLastVecValue(vecAllVal);
30
	}
31
180
	size_t depth(0lu);
32
180
	std::vector<size_t>::const_iterator it(vecIndentation.begin());
33
180
	bool isCurrentLower(true);
34

480
	while(isCurrentLower && it != vecIndentation.end()){
35
300
		isCurrentLower = *it < currentIndentation;
36
300
		if(isCurrentLower){
37
162
			++depth;
38
		}
39
300
		++it;
40
	}
41
180
	VecValue * out = getLastVecValue(vecAllVal, depth);
42
180
	return out;
43
}
44
45
///Add the given child to the main VecValue and return a pointer to the added child
46
/**	@param[out] mainVecValue : main VecValue to be used
47
 * 	@param vecIndentation : vector of the last indentation of the children VecValue
48
 * 	@param isCompactMode : true if the compact mode is enabled, false otherwise
49
 * 	@param child : child VecValue to be added to the main VecValue
50
 * 	@param currentIndentation : indentation of the current VecValue
51
 * 	@return pointer to the added child (cannot be NULL)
52
*/
53
197
VecValue * addChildToParentVecValue(VecValue & mainVecValue, const std::vector<size_t> & vecIndentation, bool isCompactMode, const VecValue & child, size_t currentIndentation){
54
197
	VecValue * parent = NULL;
55
197
	if(isCompactMode){
56
2
		parent = &mainVecValue;
57
	}else{
58
195
		if(currentIndentation != -1lu){
59
195
			parent = getParentVecValue(mainVecValue, vecIndentation, currentIndentation);
60
		}else{
61
			parent = getLastVecValue(mainVecValue);
62
		}
63
	}
64
197
	parent->getVecChild().push_back(child);
65
197
	return &(parent->getVecChild().back());
66
}
67
68
///Convert a VecValue into a DicoValue
69
/**	@param[out] dicoValue : converted DicoValue
70
 * 	@param vecVal : vector of value
71
 * 	@param isMainValue : true if the VecValue is the main one
72
*/
73
234
void vecValueToDicoValue(DicoValue & dicoValue, const VecValue & vecVal, bool isMainValue){
74
468
	std::string key(vecVal.getKey());
75
234
	const VecVecValue & vecChildren = vecVal.getVecChild();
76
234
	if(vecChildren.size() == 0lu){
77
330
		std::string value(vecVal.getValue());
78
165
		if(key == ""){		//The vecVal is a value only
79
58
			DicoValue subDico;
80
29
			subDico.setValue(value);
81
29
			dicoValue.getVecChild().push_back(subDico);
82
		}else{			//The vecVal is a key-value
83
272
			DicoValue subDico;
84
136
			subDico.setKey(key);
85
136
			subDico.setValue(value);
86
136
			dicoValue.getMapChild()[key] = subDico;
87
		}
88
	}else{
89
69
		if(key != ""){
90
94
			DicoValue subDico;
91
47
			subDico.setKey(vecVal.getKey());
92
169
			for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
93
122
				vecValueToDicoValue(subDico, *it, false);
94
			}
95
47
			dicoValue.getMapChild()[key] = subDico;
96
		}else{
97
22
			if(isMainValue){
98
105
				for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
99
90
					vecValueToDicoValue(dicoValue, *it, false);
100
				}
101
			}else{
102
14
				DicoValue dashValue;
103
14
				for(VecVecValue::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
104
7
					vecValueToDicoValue(dashValue, *it, false);
105
				}
106
7
				dicoValue.getVecChild().push_back(dashValue);
107
			}
108
		}
109
	}
110
234
}
111
112