PhoenixFileParser  1.5.1
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
91
96template<typename T>
97T phoenix_get_value(const ConfigNode & dico, const PString & varName, const T & defaultValue){
98 const ConfigNode * param = dico.getChild(varName);
99 if(param == NULL){
100 return defaultValue;
101 }else{
102 return param->getString().toValue<T>();
103 }
104}
105
107
111template<typename T>
112void phoenix_load_vecValue(std::vector<T> & vecValue, const ConfigNode & dico, const PString & varName){
113 const ConfigNode * param = dico.getChild(varName);
114 if(param == NULL){
115 return;
116 }
117 const VecConfigNode & vecChildValue = param->getVecChild();
118 for(VecConfigNode::const_iterator it(vecChildValue.begin()); it != vecChildValue.end(); ++it){
119 vecValue.push_back((*it)->getString().toValue<T>());
120 }
121}
122
124
128template<typename T>
129std::vector<T> phoenix_load_vecValue(const ConfigNode & dico, const PString & varName){
130 std::vector<T> out;
131 phoenix_load_vecValue(out, dico, varName);
132 return out;
133}
134
135#endif
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
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(std::vector< T > &vecValue, const ConfigNode &dico, const PString &varName)
Load a vector of value from a ConfigNode.
T phoenix_get_value(const ConfigNode &dico, const PString &varName, const T &defaultValue)
Get the corresponding value.
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.