#include <eoParser.h>
Public Member Functions | |
eoParser (unsigned _argc, char **_argv, std::string _programDescription="", std::string _lFileParamName="param-file", char _shortHand= 'p') | |
Constructor a complete constructor that reads the command line an optionally reads a configuration file. | |
void | processParam (eoParam ¶m, std::string section="") |
Processes the parameter and puts it in the appropriate section for readability. | |
void | readFrom (std::istream &is) |
Read object. | |
void | printOn (std::ostream &os) const |
Write object. | |
std::string | className (void) const |
className for readibility | |
bool | userNeedsHelp (void) |
true if the user made an error or asked for help | |
void | printHelp (std::ostream &os) |
Prints an automatic help in the specified output using the information provided by parameters. | |
std::string | ProgramName () |
virtual bool | isItThere (eoParam &_param) const |
Has param been entered by user? | |
eoParam * | getParamWithLongName (const std::string &_name) const |
get a handle on a param from its longName | |
template<class ValueType> | |
eoValueParam< ValueType > & | getORcreateParam (ValueType _defaultValue, std::string _longName, std::string _description, char _shortHand=0, std::string _section="", bool _required=false) |
Get or create parameter. | |
template<class ValueType> | |
eoValueParam< ValueType > & | setORcreateParam (ValueType _defaultValue, std::string _longName, std::string _description, char _shortHand=0, std::string _section="", bool _required=false) |
Set parameter value or create parameter. | |
void | setStopOnUnknownParam (bool _b) |
accessors to the stopOnUnknownParam value | |
bool | getStopOnUnknownParam () |
void | setPrefix (const std::string &_prefix) |
Prefix handling. | |
void | resetPrefix () |
std::string | getPrefix () |
Private Types | |
typedef std::multimap < std::string, eoParam * > | MultiMapType |
typedef std::map< char, std::string > | ShortNameMapType |
typedef std::map< std::string, std::string > | LongNameMapType |
Private Member Functions | |
void | doRegisterParam (eoParam ¶m) const |
std::pair< bool, std::string > | getValue (eoParam &_param) const |
void | updateParameters () const |
Private Attributes | |
MultiMapType | params |
std::string | programName |
std::string | programDescription |
ShortNameMapType | shortNameMap |
LongNameMapType | longNameMap |
eoValueParam< bool > | needHelp |
eoValueParam< bool > | stopOnUnknownParam |
std::vector< std::string > | messages |
std::string | prefix |
Definition at line 100 of file eoParser.h.
eoParser::eoParser | ( | unsigned | _argc, | |
char ** | _argv, | |||
std::string | _programDescription = "" , |
|||
std::string | _lFileParamName = "param-file" , |
|||
char | _shortHand = 'p' | |||
) |
Constructor a complete constructor that reads the command line an optionally reads a configuration file.
myEo --param-file=param.rc will then load using the parameter file param.rc
_argc | command line arguments count | |
_argv | command line parameters | |
_programDescription | Description of the work the program does | |
_lFileParamName | Name of the parameter specifying the configuration file (--param-file) | |
_shortHand | Single charachter shorthand for specifying the configuration file |
void eoParser::readFrom | ( | std::istream & | _is | ) | [virtual] |
Read object.
_is | A std::istream. |
runtime_std::exception | If a valid object can't be read. |
Implements eoPersistent.
void eoParser::printOn | ( | std::ostream & | _os | ) | const [virtual] |
Write object.
It's called printOn since it prints the object on a stream.
_os | A std::ostream. |
Implements eoPrintable.
virtual bool eoParser::isItThere | ( | eoParam & | _param | ) | const [inline, virtual] |
Has param been entered by user?
Checks if _param has been actually entered by the user
Implements eoParameterLoader.
Definition at line 148 of file eoParser.h.
Referenced by setORcreateParam().
eoParam * eoParser::getParamWithLongName | ( | const std::string & | _name | ) | const |
get a handle on a param from its longName
if not found, returns 0 (null pointer :-)
Not very clean (requires hard-coding of the long name twice!) but very useful in many occasions...
Definition at line 105 of file eoParser.cpp.
Referenced by getORcreateParam().
eoValueParam<ValueType>& eoParser::getORcreateParam | ( | ValueType | _defaultValue, | |
std::string | _longName, | |||
std::string | _description, | |||
char | _shortHand = 0 , |
|||
std::string | _section = "" , |
|||
bool | _required = false | |||
) | [inline] |
Get or create parameter.
It seems finally that the easiest use of the above method is through the following, whose interface is similar to that of the widely-used createParam.
For some (probably very stupid) reason, I failed to put it in the .cpp. Any hint???
Definition at line 173 of file eoParser.h.
References eoParameterLoader::createParam(), and getParamWithLongName().
Referenced by eoEsMutationInit::TauBeta(), eoEsMutationInit::TauGlb(), and eoEsMutationInit::TauLcl().
eoValueParam<ValueType>& eoParser::setORcreateParam | ( | ValueType | _defaultValue, | |
std::string | _longName, | |||
std::string | _description, | |||
char | _shortHand = 0 , |
|||
std::string | _section = "" , |
|||
bool | _required = false | |||
) | [inline] |
Set parameter value or create parameter.
This makes sure that the specified parameter has the given value. If the parameter does not exist yet, it is created.
This requires that operator<< is defined for ValueType.
_defaultValue | Default value. | |
_longName | Long name of the argument. | |
_description | Description of the parameter. | |
_shortName | Short name of the argument (Optional) | |
_section | Name of the section where the parameter belongs. | |
_required | Is the parameter mandatory? |
Definition at line 212 of file eoParser.h.
References eoParameterLoader::createParam(), isItThere(), and eoValueParam< ValueType >::setValue().