PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
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 
19 template<typename T>
20 T 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 
35 template<typename T>
36 bool 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 
52 template<typename T>
53 bool 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 
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 
79 
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
std::vector< DicoValue > VecDicoValue
Vector of DicoValue.
Definition: DicoValue.h:77
Dictionnary of values.
Definition: DicoValue.h:17
void setKey(const PString &key)
Sets the key of the DicoValue.
Definition: DicoValue.cpp:148
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:116
void setValue(const PString &value)
Sets the value of the DicoValue.
Definition: DicoValue.cpp:141
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
Definition: DicoValue.cpp:218
T getValue() const
Convert the value of the current DicoValue into a type.
Extends the std::string.
Definition: PString.h:16
std::string valueToString(const T &val)
Convert a type into a string.
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.