PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
OptionValue_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 __POPTIONVALUE_IMPL_H__
8 #define __POPTIONVALUE_IMPL_H__
9 
10 #include <stdexcept>
11 #include "OptionValue.h"
12 
14 
16 template<typename T>
17 void OptionValue::setDefaultValue(const T & value){
18  PString valueBinStr;
19  valueBinStr.fromValue(value);
20  PVecString vecValue;
21  vecValue.push_back(valueBinStr);
22  p_vecDefaultValue = vecValue;
23 }
24 
26 
28 template<typename T>
29 void OptionValue::setDefaultValue(const std::vector<T> & value){
30  p_vecDefaultValue = value;
31 }
32 
34 
37 template<typename T>
38 void OptionValue::getValue(T & value, bool isParsed) const{
39  checkTypeFromTemplate<T>();
40  if(isParsed){
41  if(p_vecValue.size() > 1lu){
42  std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
43  }
44  value = stringToValue<T>(p_vecValue.front());
45  }else{
46  if(p_vecDefaultValue.size() == 1lu){
47  value = stringToValue<T>(p_vecDefaultValue.front());
48  }else{
49  std::runtime_error("OptionValue::getValue : several value but only one value in parameter");
50  }
51  }
52 }
53 
55 
58 template<typename T>
59 void OptionValue::getValue(std::vector<T> & vecValue, bool isParsed) const{
60  checkTypeFromTemplate<T>();
61  if(isParsed){
62  for(PVecString::const_iterator it(p_vecValue.begin()); it != p_vecValue.end(); ++it){
63  vecValue.push_back(stringToValue<T>(*it));
64  }
65  }else{
66  for(PVecString::const_iterator it(p_vecDefaultValue.begin()); it != p_vecDefaultValue.end(); ++it){
67  vecValue.push_back(stringToValue<T>(*it));
68  }
69  }
70 }
71 
73 
75 template<typename T>
77  OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
78  if(!isOptionTypeCompatible(p_type, optionTypeFromDefault)){
79  std::stringstream strError;
80  strError << "OptionValue::checkTypeFromTemplate : Incompatible types from parameters (" << convertOptionTypeToString(p_type) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
81  throw std::runtime_error(strError.str());
82  }
83 }
84 
85 #endif
86 
87 
PString convertOptionTypeToString(OptionType::OptionType type)
Convert the OptionType into PString.
Definition: OptionType.cpp:69
bool isOptionTypeCompatible(OptionType::OptionType typeFromParam, OptionType::OptionType typeFromType)
Say if two types are compatible.
Definition: OptionType.cpp:54
std::vector< PString > PVecString
Definition: PString.h:96
const PVecString & getValue() const
Get the vector of values.
PVecString p_vecDefaultValue
Default value of the OptionValue.
Definition: OptionValue.h:75
void setDefaultValue(const T &value)
Set the value in the OptionValue.
OptionType::OptionType p_type
Type of the OptionValue.
Definition: OptionValue.h:71
void checkTypeFromTemplate() const
Check the type from the template.
PVecString p_vecValue
Vector of the values of the OptionValue.
Definition: OptionValue.h:73
Extends the std::string.
Definition: PString.h:16
PString & fromValue(const T &other)
Convert a value to a PString.
Definition: PString_impl.h:36