Directory: | ./ |
---|---|
File: | tmp_project/PhoenixFileParser/src/phoenix_get_string_impl.h |
Date: | 2025-03-14 11:45:13 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 18 | 18 | 100.0% |
Branches: | 12 | 12 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #ifndef __PHOENIX_GET_STRING_IMPL_H__ | ||
8 | #define __PHOENIX_GET_STRING_IMPL_H__ | ||
9 | |||
10 | #include "convertToString.h" | ||
11 | #include "phoenix_get_string.h" | ||
12 | |||
13 | ///Get the value from a dictionnary | ||
14 | /** @param dico : dictionnary to be used | ||
15 | * @param varName : name of the variable to be used | ||
16 | * @param defaultValue : default value | ||
17 | * @return loaded value or default value | ||
18 | */ | ||
19 | template<typename T> | ||
20 | 2 | T phoenix_load_value_from_config(const DicoValue & dico, const PString & varName, T defaultValue){ | |
21 | 2 | const DicoValue * param = dico.getMap(varName); | |
22 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(param == NULL){ |
23 | 1 | return defaultValue; | |
24 | }else{ | ||
25 | 1 | return param->getValue<T>(); | |
26 | } | ||
27 | } | ||
28 | |||
29 | ///Get the value from a dictionnary | ||
30 | /** @param[out] value : value to be loaded | ||
31 | * @param dico : dictionnary to be used | ||
32 | * @param varName : name of the variable to be used | ||
33 | * @return true if the value was loaded, false otherwise | ||
34 | */ | ||
35 | template<typename T> | ||
36 | 2 | bool phoenix_load_value_from_dico(T & value, const DicoValue & dico, const PString & varName){ | |
37 | 2 | const DicoValue * param = dico.getMap(varName); | |
38 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(param == NULL){ |
39 | 1 | return false; | |
40 | }else{ | ||
41 | 1 | value = param->getValue<T>(); | |
42 | 1 | return true; | |
43 | } | ||
44 | } | ||
45 | |||
46 | ///Save the value to a dictionnary | ||
47 | /** @param[out] dico : dictionnary to be updated | ||
48 | * @param value : value to be saved | ||
49 | * @param varName : name of the variable to be used | ||
50 | * @return true if the value was saved, false otherwise (return is always true) | ||
51 | */ | ||
52 | template<typename T> | ||
53 | 2 | bool phoenix_save_value_to_dico(DicoValue & dico, const T & value, const PString & varName){ | |
54 |
1/1✓ Branch 1 taken 2 times.
|
2 | DicoValue param; |
55 |
1/1✓ Branch 1 taken 2 times.
|
2 | param.setKey(varName); |
56 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | param.setValue(valueToString(value)); |
57 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | dico.getMapChild()[varName] = param; |
58 | 2 | return true; | |
59 | 2 | } | |
60 | |||
61 | ///Load a vector of value from a dictionnary | ||
62 | /** @param[out] vecValue : loaded vector of values | ||
63 | * @param dico : dictionnary to be used | ||
64 | * @param varName : name of the variable to be used | ||
65 | */ | ||
66 | template<typename T> | ||
67 | void phoenix_load_vecValue_from_config(std::vector<T> & vecValue, const DicoValue & dico, const PString & varName){ | ||
68 | const DicoValue * param = dico.getMap(varName); | ||
69 | if(param == NULL){ | ||
70 | return; | ||
71 | } | ||
72 | const VecDicoValue & vecChildValue = param->getVecChild(); | ||
73 | for(VecDicoValue::const_iterator it(vecChildValue.begin()); it != vecChildValue.end(); ++it){ | ||
74 | vecValue.push_back(it->getValue<T>()); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | ///Load a vector of value from a dictionnary | ||
79 | /** @param dico : dictionnary to be used | ||
80 | * @param varName : name of the variable to be used | ||
81 | * @return loaded vector of values | ||
82 | */ | ||
83 | template<typename T> | ||
84 | std::vector<T> phoenix_load_vecValue_from_config(const DicoValue & dico, const PString & varName){ | ||
85 | std::vector<T> out; | ||
86 | phoenix_load_vecValue_from_config(out, dico, varName); | ||
87 | return out; | ||
88 | } | ||
89 | |||
90 | #endif | ||
91 |