PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
OptionParser_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 __POPTIONPARSER_IMPL_H__
8 #define __POPTIONPARSER_IMPL_H__
9 
10 #include <sstream>
11 #include "OptionParser.h"
12 
14 
20 template<typename T>
21 void OptionParser::addOption(const std::string & longOption, const std::string & shortOption, const T defaultValue, const std::string & docString){
22  OptionType::OptionType optionType = getOptionTypeFromType<T>();
23  OptionValue value;
24  value.setType(optionType);
25  value.setDefaultValue(defaultValue);
26  Option option(longOption, shortOption, value, false, docString);
27  p_vecMode.back().addOption(option);
28 }
29 
31 
38 template<typename T>
39 void OptionParser::addOption(const std::string & longOption, const std::string & shortOption, const T defaultValue,
40  OptionType::OptionType optionType, const std::string & docString)
41 {
42  checkOptionType<T>(optionType);
43  OptionValue value;
44  value.setType(optionType);
45  value.setDefaultValue(defaultValue);
46  Option option(longOption, shortOption, value, false, docString);
47  p_vecMode.back().addOption(option);
48 }
49 
51 
57 template<typename T>
58 void OptionParser::addOption(const std::string & longOption, const std::string & shortOption, const std::vector<T> & defaultValue, const std::string & docString){
59  OptionType::OptionType optionType = getOptionTypeFromType<T>();
60  OptionValue valueVec;
61  valueVec.setType(optionType);
62  valueVec.setDefaultValue(defaultValue);
63  Option option(longOption, shortOption, valueVec, false, docString);
64  p_vecMode.back().addOption(option);
65 }
66 
68 
74 template<typename T>
75 void OptionParser::addOption(const std::string & longOption, const std::string & shortOption, const std::list<T> & defaultValue, const std::string & docString){
76  OptionType::OptionType optionType = getOptionTypeFromType<T>();
77  OptionValue valueList;
78  valueList.setType(optionType);
79  valueList.setDefaultValue(defaultValue);
80  Option option(longOption, shortOption, valueList, false, docString);
81  p_vecMode.back().addOption(option);
82 }
83 
85 
92 template<typename T>
93 void OptionParser::addOption(const std::string & longOption, const std::string & shortOption, const std::vector<T> & defaultValue,
94  OptionType::OptionType optionType, const std::string & docString)
95 {
96  checkOptionType<T>(optionType);
97  OptionValue valueVec;
98  valueVec.setDefaultValue(defaultValue);
99  valueVec.setType(optionType);
100  Option option(longOption, shortOption, valueVec, false, docString);
101  p_vecMode.back().addOption(option);
102 }
103 
105 
112 template<typename T>
113 void OptionParser::addOption(const std::string & longOption, const std::string & shortOption, const std::list<T> & defaultValue,
114  OptionType::OptionType optionType, const std::string & docString)
115 {
116  checkOptionType<T>(optionType);
117  OptionValue valueList;
118  valueList.setDefaultValue(defaultValue);
119  valueList.setType(optionType);
120  Option option(longOption, shortOption, valueList, false, docString);
121  p_vecMode.back().addOption(option);
122 }
123 
125 
128 template<typename T>
130  OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
131  if(!isOptionTypeCompatible(optionType, optionTypeFromDefault)){
132  std::stringstream strError;
133  strError << "OptionParser::checkOptionType : Incompatible types from parameters (" << convertOptionTypeToString(optionType) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
134  throw std::runtime_error(strError.str());
135  }
136 }
137 
138 #endif
139 
convertOptionTypeToString
std::string convertOptionTypeToString(OptionType::OptionType type)
Convert the OptionType into string.
Definition: OptionType.cpp:69
OptionParser::p_vecMode
VecMode p_vecMode
Vector of all the defined mode in the OptionParser.
Definition: OptionParser.h:92
OptionValue::setType
void setType(OptionType::OptionType type)
Set the type of the OptionValue.
Definition: OptionValue.cpp:105
OptionParser::checkOptionType
void checkOptionType(OptionType::OptionType optionType)
Check the given option type.
Definition: OptionParser_impl.h:129
OptionValue::setDefaultValue
void setDefaultValue(const T &value)
Set the value in the OptionValue.
Definition: OptionValue_impl.h:17
isOptionTypeCompatible
bool isOptionTypeCompatible(OptionType::OptionType typeFromParam, OptionType::OptionType typeFromType)
Say if two types are compatible.
Definition: OptionType.cpp:54
OptionParser::addOption
void addOption(const std::string &longOption, const std::string &shortOption, OptionType::OptionType optionType, bool isRequired, const std::string &docString)
Add an option in the OptionParser.
Definition: OptionParser.cpp:76
Option
Definition: Option.h:13
OptionType::OptionType
OptionType
Definition: OptionType.h:19
OptionValue
Describe the value of an option passed to a program.
Definition: OptionValue.h:20
OptionParser.h