PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
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 PString & longOption, const PString & shortOption, const T defaultValue, const PString & 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 PString & longOption, const PString & shortOption, const T defaultValue,
40  OptionType::OptionType optionType, const PString & 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 
54 template<typename T>
56  OptionType::OptionType optionTypeFromDefault = getOptionTypeFromType<T>();
57  if(!isOptionTypeCompatible(optionType, optionTypeFromDefault)){
58  std::stringstream strError;
59  strError << "OptionParser::checkOptionType : Incompatible types from parameters (" << convertOptionTypeToString(optionType) << ") ad for default type ("<<convertOptionTypeToString(optionTypeFromDefault)<<")";
60  throw std::runtime_error(strError.str());
61  }
62 }
63 
64 #endif
65 
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
void addOption(const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, const PString &docString)
Add an option in the OptionParser.
VecMode p_vecMode
Vector of all the defined mode in the OptionParser.
Definition: OptionParser.h:78
void checkOptionType(OptionType::OptionType optionType)
Check the given option type.
Describe the value of an option passed to a program.
Definition: OptionValue.h:16
void setDefaultValue(const T &value)
Set the value in the OptionValue.
void setType(OptionType::OptionType type)
Set the type of the OptionValue.
Describes an option passed to a program.
Definition: Option.h:14
Extends the std::string.
Definition: PString.h:16