Directory: | ./ |
---|---|
File: | tmp_project/PhoenixFileParser/src/phoenix_get_string.cpp |
Date: | 2025-03-14 12:18:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 44 | 44 | 100.0% |
Branches: | 30 | 31 | 96.8% |
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 1 taken 13 times.
|
13 | PString config(strConfig.toLower()); |
15 |
6/6✓ Branch 1 taken 7 times.
✓ Branch 2 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 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 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(param == NULL){ |
28 | 1 | return defaultValue; | |
29 | }else{ | ||
30 |
1/1✓ Branch 2 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 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if(param == NULL){ |
45 | 1 | return false; | |
46 | }else{ | ||
47 |
1/1✓ Branch 2 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 2 taken 2 times.
|
2 | std::string strValue("false"); |
61 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if(value){ |
62 |
1/1✓ Branch 1 taken 2 times.
|
2 | strValue = "true"; |
63 | } | ||
64 |
1/1✓ Branch 1 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 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(param == NULL){ |
75 | 1 | return; | |
76 | } | ||
77 | 1 | const VecDicoValue & vecChildValue = param->getVecChild(); | |
78 |
2/2✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | for(VecDicoValue::const_iterator it(vecChildValue.begin()); it != vecChildValue.end(); ++it){ |
79 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 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 1 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 | 3 | PString phoenix_get_string(const DicoValue & dico, const PString & varName, const PString & defaultValue){ | |
102 | 3 | const DicoValue * param = dico.getMap(varName); | |
103 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if(param == NULL){ |
104 | 2 | 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 | 6 | PString phoenix_get_string(const DicoValue & dico, const PString & varName, const PString & defaultValue, const PString & defaultValue2){ | |
118 | 6 | const DicoValue * param = dico.getMap(varName); | |
119 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | if(param == NULL){ |
120 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
|
4 | if(defaultValue != ""){ |
121 | 2 | return defaultValue; | |
122 | }else{ | ||
123 | 2 | return defaultValue2; | |
124 | } | ||
125 | }else{ | ||
126 | 2 | return param->getString(); | |
127 | } | ||
128 | } | ||
129 | |||
130 | |||
131 | |||
132 |