GCC Code Coverage Report


Directory: ./
File: src/phoenix_get_string.cpp
Date: 2025-09-08 16:55:04
Exec Total Coverage
Lines: 44 53 83.0%
Functions: 8 9 88.9%
Branches: 35 46 76.1%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "phoenix_get_string.h"
8
9 ///Convert the configuration of the cleaning type into a bool
10 /** @param strConfig : configuration string
11 * @return corresponding value
12 */
13 13 bool phoenix_convertBoolType(const PString & strConfig){
14
1/1
✓ Branch 0 (2→3) taken 13 times.
13 PString config(strConfig.toLower());
15
9/9
✓ Branch 0 (3→4) taken 13 times.
✓ Branch 2 (4→5) taken 7 times.
✓ Branch 3 (4→9) taken 6 times.
✓ Branch 4 (5→6) taken 7 times.
✓ Branch 6 (6→7) taken 6 times.
✓ Branch 7 (6→9) taken 1 times.
✓ Branch 8 (7→8) taken 6 times.
✓ Branch 10 (8→9) taken 2 times.
✓ Branch 11 (8→10) taken 4 times.
26 return config == "true" || strConfig == "1" || config == "yes";
16 13 }
17
18 ///Get bool value from a dictionnary (specialization for bool)
19 /** @param dico : dictionnary to be used
20 * @param varName : name of the variable to be used
21 * @param defaultValue : default value
22 * @return loaded value or default value
23 */
24 template<>
25 2 bool phoenix_load_value_from_config<bool>(const DicoValue & dico, const PString & varName, bool defaultValue){
26 2 const DicoValue * param = dico.getMap(varName);
27
2/2
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→5) taken 1 times.
2 if(param == NULL){
28 1 return defaultValue;
29 }else{
30
2/2
✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
1 return phoenix_convertBoolType(param->getString());
31 }
32 }
33
34 ///Get bool value from a dictionnary (specialization for bool)
35 /** @param[out] value : value to be loaded
36 * @param dico : dictionnary to be used
37 * @param varName : name of the variable to be used
38 * @param defaultValue : default value
39 * @return loaded value or default value
40 */
41 template<>
42 4 bool phoenix_load_value_from_dico<bool>(bool & value, const DicoValue & dico, const PString & varName){
43 4 const DicoValue * param = dico.getMap(varName);
44
2/2
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→5) taken 3 times.
4 if(param == NULL){
45 1 return false;
46 }else{
47
2/2
✓ Branch 0 (5→6) taken 3 times.
✓ Branch 2 (6→7) taken 3 times.
3 value = phoenix_convertBoolType(param->getString());
48 3 return true;
49 }
50 }
51
52 ///Save the value to a dictionnary (specialization for bool)
53 /** @param[out] dico : dictionnary to be updated
54 * @param value : value to be saved
55 * @param varName : name of the variable to be used
56 * @return true if the value was saved, false otherwise (return is always true)
57 */
58 template<>
59 2 bool phoenix_save_value_to_dico<bool>(DicoValue & dico, const bool & value, const PString & varName){
60
1/1
✓ Branch 0 (4→5) taken 2 times.
2 std::string strValue("false");
61
1/2
✓ Branch 0 (6→7) taken 2 times.
✗ Branch 1 (6→8) not taken.
2 if(value){
62
1/1
✓ Branch 0 (7→8) taken 2 times.
2 strValue = "true";
63 }
64
1/1
✓ Branch 0 (8→9) taken 2 times.
4 return phoenix_save_value_to_dico(dico, strValue, varName);
65 2 }
66
67 ///Load a vector of string from a dictionnary
68 /** @param[out] vecValue : loaded vector of values
69 * @param dico : dictionnary to be used
70 * @param varName : name of the variable to be used
71 */
72 2 void phoenix_get_vecstring(PVecString & vecValue, const DicoValue & dico, const PString & varName){
73 2 const DicoValue * param = dico.getMap(varName);
74
2/2
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→5) taken 1 times.
2 if(param == NULL){
75 1 return;
76 }
77 1 const VecDicoValue & vecChildValue = param->getVecChild();
78
2/2
✓ Branch 0 (22→7) taken 1 times.
✓ Branch 1 (22→23) taken 1 times.
4 for(VecDicoValue::const_iterator it(vecChildValue.begin()); it != vecChildValue.end(); ++it){
79
2/2
✓ Branch 0 (9→10) taken 1 times.
✓ Branch 2 (10→11) taken 1 times.
1 vecValue.push_back(it->getString());
80 }
81 }
82
83 ///Load a vector of string from a dictionnary
84 /** @param dico : dictionnary to be used
85 * @param varName : name of the variable to be used
86 * @return loaded vector of values
87 */
88 2 PVecString phoenix_get_vecstring(const DicoValue & dico, const PString & varName){
89 2 PVecString out;
90
1/1
✓ Branch 0 (3→4) taken 2 times.
2 phoenix_get_vecstring(out, dico, varName);
91 2 return out;
92 }
93
94
95 ///Get the string from a dictionnary
96 /** @param dico : dictionnary to be used
97 * @param varName : name of the variable to be used
98 * @param defaultValue : default value
99 * @return loaded string or default value
100 */
101 2 PString phoenix_get_string(const DicoValue & dico, const PString & varName, const PString & defaultValue){
102 2 const DicoValue * param = dico.getMap(varName);
103
2/2
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→5) taken 1 times.
2 if(param == NULL){
104 1 return defaultValue;
105 }else{
106 1 return param->getString();
107 }
108 }
109
110 ///Get the string from a dictionnary
111 /** @param dico : dictionnary to be used
112 * @param varName : name of the variable to be used
113 * @param defaultValue : default value
114 * @param defaultValue2 : default value to be used if the first defaultValue is empty
115 * @return loaded string or default value
116 */
117 3 PString phoenix_get_string(const DicoValue & dico, const PString & varName, const PString & defaultValue, const PString & defaultValue2){
118 3 const DicoValue * param = dico.getMap(varName);
119
2/2
✓ Branch 0 (3→4) taken 2 times.
✓ Branch 1 (3→8) taken 1 times.
3 if(param == NULL){
120
2/2
✓ Branch 0 (5→6) taken 1 times.
✓ Branch 1 (5→7) taken 1 times.
2 if(defaultValue != ""){
121 1 return defaultValue;
122 }else{
123 1 return defaultValue2;
124 }
125 }else{
126 1 return param->getString();
127 }
128 }
129
130 ///Get a nested value in the DicoValue
131 /** @param dico : dictionnary to be used
132 * @param vecVarAddress : vector of names to get the value
133 * @return loaded string or default value
134 */
135 PString phoenix_get_nested_string(const DicoValue & dico, const PVecString & vecVarAddress){
136 if(vecVarAddress.size() == 0lu){return "";}
137 const DicoValue * tmpDico = dico.getMap(vecVarAddress);
138 PString outputValue;
139 if(tmpDico != NULL){ //We get all keys until the end of the vector
140 outputValue = tmpDico->getString();
141 }
142 return outputValue;
143 }
144
145
146
147