PhoenixFileParser  1.5.1
Set of tools to ease file parsing
Loading...
Searching...
No Matches
phoenix_get_string.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
8
10
13bool phoenix_convertBoolType(const PString & strConfig){
14 PString config(strConfig.toLower());
15 return config == "true" || strConfig == "1" || config == "yes";
16}
17
19
24template<>
25bool phoenix_load_value_from_config<bool>(const DicoValue & dico, const PString & varName, bool defaultValue){
26 const DicoValue * param = dico.getMap(varName);
27 if(param == NULL){
28 return defaultValue;
29 }else{
30 return phoenix_convertBoolType(param->getString());
31 }
32}
33
35
41template<>
42bool phoenix_load_value_from_dico<bool>(bool & value, const DicoValue & dico, const PString & varName){
43 const DicoValue * param = dico.getMap(varName);
44 if(param == NULL){
45 return false;
46 }else{
47 value = phoenix_convertBoolType(param->getString());
48 return true;
49 }
50}
51
53
58template<>
59bool phoenix_save_value_to_dico<bool>(DicoValue & dico, const bool & value, const PString & varName){
60 std::string strValue("false");
61 if(value){
62 strValue = "true";
63 }
64 return phoenix_save_value_to_dico(dico, strValue, varName);
65}
66
68
72void phoenix_get_vecstring(PVecString & vecValue, const DicoValue & dico, const PString & varName){
73 const DicoValue * param = dico.getMap(varName);
74 if(param == NULL){
75 return;
76 }
77 const VecDicoValue & vecChildValue = param->getVecChild();
78 for(VecDicoValue::const_iterator it(vecChildValue.begin()); it != vecChildValue.end(); ++it){
79 vecValue.push_back(it->getString());
80 }
81}
82
84
88PVecString phoenix_get_vecstring(const DicoValue & dico, const PString & varName){
89 PVecString out;
90 phoenix_get_vecstring(out, dico, varName);
91 return out;
92}
93
94
96
101PString phoenix_get_string(const DicoValue & dico, const PString & varName, const PString & defaultValue){
102 const DicoValue * param = dico.getMap(varName);
103 if(param == NULL){
104 return defaultValue;
105 }else{
106 return param->getString();
107 }
108}
109
111
117PString phoenix_get_string(const DicoValue & dico, const PString & varName, const PString & defaultValue, const PString & defaultValue2){
118 const DicoValue * param = dico.getMap(varName);
119 if(param == NULL){
120 if(defaultValue != ""){
121 return defaultValue;
122 }else{
123 return defaultValue2;
124 }
125 }else{
126 return param->getString();
127 }
128}
129
131
135PString 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
146
151template<>
152bool phoenix_get_value(const ConfigNode & dico, const PString & varName, const bool & defaultValue){
153 const ConfigNode * param = dico.getChild(varName);
154 if(param == NULL){
155 return defaultValue;
156 }else{
157 return phoenix_convertBoolType(param->getString());
158 }
159}
160
162
167PString phoenix_get_string(const ConfigNode & dico, const PString & varName, const PString & defaultValue){
168 const ConfigNode * param = dico.getChild(varName);
169 if(param == NULL){
170 return defaultValue;
171 }else{
172 return param->getString();
173 }
174}
175
177
183PString phoenix_get_string(const ConfigNode & dico, const PString & varName, const PString & defaultValue, const PString & defaultValue2){
184 const ConfigNode * param = dico.getChild(varName);
185 if(param == NULL){
186 if(defaultValue != ""){
187 return defaultValue;
188 }else{
189 return defaultValue2;
190 }
191 }else{
192 return param->getString();
193 }
194}
195
197
201void phoenix_get_vecstring(PVecString & vecValue, const ConfigNode & dico, const PString & varName){
202 const ConfigNode * param = dico.getChild(varName);
203 if(param == NULL){
204 return;
205 }
206 const VecConfigNode & vecChildValue = param->getVecChild();
207 for(VecConfigNode::const_iterator it(vecChildValue.begin()); it != vecChildValue.end(); ++it){
208 vecValue.push_back((*it)->getString());
209 }
210}
211
213
217PVecString phoenix_get_vecstring(const ConfigNode & dico, const PString & varName){
218 PVecString out;
219 phoenix_get_vecstring(out, dico, varName);
220 return out;
221}
222
223
std::vector< ConfigNode * > VecConfigNode
Definition ConfigNode.h:74
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition DicoValue.h:80
Configuration of values.
Definition ConfigNode.h:18
PString getString() const
Get string value without " or ' at the beginning of the end.
const std::vector< ConfigNode * > & getVecChild() const
Gets the vecChild of the ConfigNode.
ConfigNode * getChild(const PString &name)
Get the child of the given name.
Dictionnary of values.
Definition DicoValue.h:17
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
PString getString() const
Get a string value without the first and/or last quote or double quote in there are some.
bool phoenix_get_value(const ConfigNode &dico, const PString &varName, const bool &defaultValue)
Get the string from a ConfigNode (specialisation for bool)
PString phoenix_get_string(const DicoValue &dico, const PString &varName, const PString &defaultValue)
Get the string from a dictionnary.
bool phoenix_load_value_from_dico< bool >(bool &value, const DicoValue &dico, const PString &varName)
Get bool value from a dictionnary (specialization for bool)
bool phoenix_convertBoolType(const PString &strConfig)
Convert the configuration of the cleaning type into a bool.
bool phoenix_save_value_to_dico< bool >(DicoValue &dico, const bool &value, const PString &varName)
Save the value to a dictionnary (specialization for bool)
bool phoenix_load_value_from_config< bool >(const DicoValue &dico, const PString &varName, bool defaultValue)
Get bool value from a dictionnary (specialization for bool)
void phoenix_get_vecstring(PVecString &vecValue, const DicoValue &dico, const PString &varName)
Load a vector of string from a dictionnary.
PString phoenix_get_nested_string(const DicoValue &dico, const PVecString &vecVarAddress)
Get a nested value in the DicoValue.
bool phoenix_save_value_to_dico(DicoValue &dico, const T &value, const PString &varName)
Save the value to a dictionnary.