~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/src/common/OptsParser.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
namespace Puma {
28
28
 
29
29
 
 
30
/** \brief The %Options %Parser searches command line parameters for options and
 
31
 *  handles their option arguments, if applicable.
 
32
 */
30
33
class OptsParser : public SimpleParser {
 
34
  
 
35
  
 
36
  /** \brief Vector holding the commandline parameters. 
 
37
   *  
 
38
   *  This vector is filled in the constructor
 
39
   */
31
40
  vector<string> m_argv;
 
41
 
 
42
  /** \brief Position of current parameter analyzed by the 
 
43
   *  options parser.
 
44
   */
32
45
  unsigned int m_curarg;
 
46
  
 
47
  /** \brief The increment added to m_curarg used to get to the next 
 
48
   *  entry of m_argv which shall be analysed.
 
49
   */
33
50
  unsigned int m_tonext;
 
51
  
 
52
  /** \brief %Option number of currently processed element of m_argv
 
53
   */
34
54
  int m_number;
 
55
  
 
56
  /** \brief Name of current option
 
57
   */
 
58
  string m_opt;
35
59
 
 
60
  /** \brief Value of current option argument
 
61
   */
36
62
  string m_arg;
37
 
  string m_opt;
 
63
  
38
64
   
39
65
public:
40
66
  
41
 
  enum {NOARG =-4, ERR = -3, NOOPTION = -2, UNKNOWN = -1, FINISH = 0 };
42
 
  
43
 
  enum ArgType { AT_NONE = 0, AT_MANDATORY = 1, AT_OPTIONAL = 2 };
44
 
  
 
67
  /** \enum
 
68
   *  Return codes for OptsParser::getOption() and OptsParser::getArgument()
 
69
   */
 
70
  enum {
 
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 */
 
76
  };
 
77
  
 
78
  /** \enum
 
79
   *  Type of argument associated to an option  
 
80
   */
 
81
  enum ArgType { 
 
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 */
 
85
  };
 
86
  
 
87
  /** \struct
 
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()
 
90
   */
45
91
  struct Option {
46
 
    int number;
47
 
    char key; 
48
 
    const char *name;
49
 
    const char *desc;
50
 
    ArgType args;
 
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 */
51
97
  };
52
98
 
53
99
private:
 
100
  /** Pointer to array of available options. This value is set to the value of the 
 
101
   * parameter passed to the constructor OptsParser::OptsParser()
 
102
   */
54
103
  const Option *m_opts;
55
104
   
56
105
public:
57
 
  OptsParser (int, char **, const Option *);
58
 
  OptsParser (const string &, const Option *);
 
106
  /** \brief Constructor of OptsParser
 
107
   *  
 
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
 
112
   *
 
113
   */
 
114
  OptsParser (int argc, char **argv, const Option *opts);
 
115
  
 
116
  /** \brief Constructor of OptsParser
 
117
   *  
 
118
   *  \param line Reference to string with parameters to analyse
 
119
   *              The paramaters are extracted from the string by splitting it up 
 
120
   *              into tokens at:
 
121
   *               - space character
 
122
   *               - tabs 
 
123
   *               - newline
 
124
   *               - carriage return
 
125
   *  \param opts Pointer to array of options which shall be 
 
126
   *              recognized by the options parser
 
127
   */
 
128
  OptsParser (const string &line, const Option *);
59
129
 
60
 
  int getCurrentArgNum () const;
61
 
  int getNextArgNum () const;
 
130
  
 
131
  /** Get next parameter without modification. 
 
132
   * No option parsing is done
 
133
   *
 
134
   * \return OptsParser::NOOPTION or OptsParser::FINISH 
 
135
   */
 
136
  int getRawOption ();
 
137
  
 
138
  /** \brief Get next option
 
139
   *
 
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. 
 
144
   *
 
145
   * \return Number of option recognized by the options parser or
 
146
   *         OptsParser::NOARG, OptsParser::ERR, OptsParser::NOOPTION,
 
147
   *         OptsParser::UNKNOWN or OptsParser::FINISH.
 
148
   *
 
149
   */
62
150
  int getOption ();
 
151
  
 
152
  /** \brief Get result of last processed parameter
 
153
   *
 
154
   *  The number returned by this function is identical to the number 
 
155
   *  returned by the last call of OptsParser::getOption
 
156
   *   
 
157
   * \return Number of option recognized by the options parser or
 
158
   *         OptsParser::NOARG, OptsParser::ERR, OptsParser::NOOPTION,
 
159
   *         OptsParser::UNKNOWN or OptsParser::FINISH.
 
160
   *
 
161
   */
63
162
  int getResult () const;
64
163
  
 
164
  /** \brief Get option argument of last processed parameter
 
165
   *
 
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.
 
169
   *
 
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.
 
173
   *
 
174
   *  \return Argument of last processed parameter
 
175
   */
65
176
  const string &getArgument () const;
 
177
  
 
178
  /** \brief Get option name of last processed parameter
 
179
   *
 
180
   *  If the last processed parameter did not contain an option the string 
 
181
   *  returned by this function is empty.
 
182
   *
 
183
   *  \return Name of last processed parameter
 
184
   *
 
185
   */
66
186
  const string &getOptionName () const;
 
187
  
 
188
  /** \brief Get position of current argument
 
189
   *
 
190
   *  \return Position of currently processed parameter previously passed to OptsParser::OptsParser()
 
191
   *
 
192
   */
 
193
  int getCurrentArgNum () const;
 
194
  
 
195
  /** \brief Get position of next argument
 
196
   *
 
197
   *  \return Position of next parameter which will be processed by the %Options %Parser
 
198
   *
 
199
   */
 
200
  int getNextArgNum () const;
67
201
 
68
 
  bool revokeArgument();
69
 
   
70
202
private:
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
 
204
   *
 
205
   *  \param arg Currently processed parameter 
 
206
   */
 
207
  const Option*  findOption(const string &arg, bool isLong);
 
208
  
 
209
  /** Process an option found by OptsParser::findOption(). 
 
210
   */
 
211
  bool processOption  (const string &arg, const Option* curOpt, bool isLong);
74
212
};
75
213
 
76
214