30
/** \brief The %Options %Parser searches command line parameters for options and
31
* handles their option arguments, if applicable.
30
33
class OptsParser : public SimpleParser {
36
/** \brief Vector holding the commandline parameters.
38
* This vector is filled in the constructor
31
40
vector<string> m_argv;
42
/** \brief Position of current parameter analyzed by the
32
45
unsigned int m_curarg;
47
/** \brief The increment added to m_curarg used to get to the next
48
* entry of m_argv which shall be analysed.
33
50
unsigned int m_tonext;
52
/** \brief %Option number of currently processed element of m_argv
56
/** \brief Name of current option
60
/** \brief Value of current option argument
41
enum {NOARG =-4, ERR = -3, NOOPTION = -2, UNKNOWN = -1, FINISH = 0 };
43
enum ArgType { AT_NONE = 0, AT_MANDATORY = 1, AT_OPTIONAL = 2 };
68
* Return codes for OptsParser::getOption() and OptsParser::getArgument()
71
NOARG =-4, /**< %Option has no argument */
72
ERR = -3, /**< Error when parsing option */
73
NOOPTION = -2, /**< Command line parameter is not an option */
74
UNKNOWN = -1, /**< Parameter is an unknown option */
75
FINISH = 0 /**< All options are handled */
79
* Type of argument associated to an option
82
AT_NONE = 0, /**< %Option receives no argument */
83
AT_MANDATORY = 1, /**< %Option requires an argument */
84
AT_OPTIONAL = 2 /**< %Option has optionally an argument */
88
* Type for specifying an array of options recognized by the %Option %Parser.
89
* An array of this type has to be passed to the constructor OptsParser::OptsParser()
92
int number; /**< Number associated with this option */
93
const char *shortName; /**< Short name of this option. Should ideally not contain more than one character */
94
const char *longName; /**< Long namen of this option */
95
const char *desc; /**< Description of this option **/
96
ArgType argType; /**< Type of argument for this option */
100
/** Pointer to array of available options. This value is set to the value of the
101
* parameter passed to the constructor OptsParser::OptsParser()
54
103
const Option *m_opts;
57
OptsParser (int, char **, const Option *);
58
OptsParser (const string &, const Option *);
106
/** \brief Constructor of OptsParser
108
* \param argc Number of parameters to be analyzed
109
* \param argv Parameters to be analyzed
110
* \param opts Pointer to array of options which shall be
111
* recognized by the options parser
114
OptsParser (int argc, char **argv, const Option *opts);
116
/** \brief Constructor of OptsParser
118
* \param line Reference to string with parameters to analyse
119
* The paramaters are extracted from the string by splitting it up
125
* \param opts Pointer to array of options which shall be
126
* recognized by the options parser
128
OptsParser (const string &line, const Option *);
60
int getCurrentArgNum () const;
61
int getNextArgNum () const;
131
/** Get next parameter without modification.
132
* No option parsing is done
134
* \return OptsParser::NOOPTION or OptsParser::FINISH
138
/** \brief Get next option
140
* This function processes the next parameter passed to the constructor
141
* OptsParser::OptsParser().
142
* That is, search for options and eventually process
143
* option and option arguement.
145
* \return Number of option recognized by the options parser or
146
* OptsParser::NOARG, OptsParser::ERR, OptsParser::NOOPTION,
147
* OptsParser::UNKNOWN or OptsParser::FINISH.
152
/** \brief Get result of last processed parameter
154
* The number returned by this function is identical to the number
155
* returned by the last call of OptsParser::getOption
157
* \return Number of option recognized by the options parser or
158
* OptsParser::NOARG, OptsParser::ERR, OptsParser::NOOPTION,
159
* OptsParser::UNKNOWN or OptsParser::FINISH.
63
162
int getResult () const;
164
/** \brief Get option argument of last processed parameter
166
* This function returns the argument of the option processed during
167
* OptsParser::getOption. If the option does not provide any argument
168
* the string will be empty.
170
* If OptsParser::getOption or respectively OptsParser::getResult returns with
171
* OptsParser::NOOPTION this function (OptsParser::getArgument) returns the last processed parameter,
172
* which is no option, of course.
174
* \return Argument of last processed parameter
65
176
const string &getArgument () const;
178
/** \brief Get option name of last processed parameter
180
* If the last processed parameter did not contain an option the string
181
* returned by this function is empty.
183
* \return Name of last processed parameter
66
186
const string &getOptionName () const;
188
/** \brief Get position of current argument
190
* \return Position of currently processed parameter previously passed to OptsParser::OptsParser()
193
int getCurrentArgNum () const;
195
/** \brief Get position of next argument
197
* \return Position of next parameter which will be processed by the %Options %Parser
200
int getNextArgNum () const;
68
bool revokeArgument();
71
int getShortOption (const string &);
72
int getLongOption (const string &);
73
bool processOption (const string &, unsigned int,ArgType argtype);
203
/** Search for an option in m_argv at position m_curarg
205
* \param arg Currently processed parameter
207
const Option* findOption(const string &arg, bool isLong);
209
/** Process an option found by OptsParser::findOption().
211
bool processOption (const string &arg, const Option* curOpt, bool isLong);