PhoenixFileParser  1.0.0
Set of tools to ease file parsing
Loading...
Searching...
No Matches
phoenix_get_string_impl.h
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
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
14
19template<typename T>
20T phoenix_load_value_from_config(const DicoValue & dico, const PString & varName, T defaultValue){
21 const DicoValue * param = dico.getMap(varName);
22 if(param == NULL){
23 return defaultValue;
24 }else{
25 return param->getValue<T>();
26 }
27}
28
30
35template<typename T>
36bool phoenix_load_value_from_dico(T & value, const DicoValue & dico, const PString & varName){
37 const DicoValue * param = dico.getMap(varName);
38 if(param == NULL){
39 return false;
40 }else{
41 value = param->getValue<T>();
42 return true;
43 }
44}
45
47
52template<typename T>
53bool phoenix_save_value_to_dico(DicoValue & dico, const T & value, const PString & varName){
54 DicoValue param;
55 param.setKey(varName);
56 param.setValue(valueToString(value));
57 dico.getMapChild()[varName] = param;
58 return true;
59}
60
62
66template<typename T>
67void 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
79
83template<typename T>
84std::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
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition DicoValue.h:80
Dictionnary of values.
Definition DicoValue.h:17
void setKey(const PString &key)
Sets the key of the DicoValue.
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.
void setValue(const PString &value)
Sets the value of the DicoValue.
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
T getValue() const
Convert the value of the current DicoValue into a type.
bool phoenix_load_value_from_dico(T &value, const DicoValue &dico, const PString &varName)
Get the value from a dictionnary.
T phoenix_load_value_from_config(const DicoValue &dico, const PString &varName, T defaultValue)
Get the value from a dictionnary.
void phoenix_load_vecValue_from_config(std::vector< T > &vecValue, const DicoValue &dico, const PString &varName)
Load a vector of value from a dictionnary.
bool phoenix_save_value_to_dico(DicoValue &dico, const T &value, const PString &varName)
Save the value to a dictionnary.