Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# eoParser Class Reference

eoParser: command line parser and configuration file reader This class is persistent, so it can be stored and reloaded to restore parameter settings. More...

`#include <eoParser.h>`

Inheritance diagram for eoParser:

List of all members.

## 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 &param, 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 &param) 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

## Detailed Description

eoParser: command line parser and configuration file reader This class is persistent, so it can be stored and reloaded to restore parameter settings.

Definition at line 100 of file eoParser.h.

## Constructor & Destructor Documentation

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 Parameters:
  | _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

## Member Function Documentation

void eoParser::readFrom | ( | std::istream & | is | ) | `[virtual]`

  | Read object. Parameters:
  | _is | A std::istream.
  Exceptions:
  | 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. Parameters:
  | _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... Referenced by getORcreateParam().

template<class ValueType>
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().

template<class ValueType>
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. Parameters:
  | _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?
Returns: Corresponding parameter. Definition at line 211 of file eoParser.h. References eoParameterLoader::createParam(), isItThere(), and eoValueParam< ValueType >::setValue().

The documentation for this class was generated from the following file:

- eoParser.h