OpenASIP 2.2
Loading...
Searching...
No Matches
CmdLineOptionParser.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file CmdLineOptionParser.hh
26 *
27 * Declaration of CmdLineOptionParser classes.
28 *
29 * @author Jussi Nykänen 2003 (nykanen-no.spam-cs.tut.fi)
30 * @author Jari Mäntyneva 2006 (jari.mantyneva-no.spam-tut.fi)
31 * @author Henry Linjamäki 2017 (henry.linjamaki-no.spam-tut.fi)
32 * @note reviewed 3 December 2003 by jn, kl, ao
33 */
34
35#ifndef TTA_CMD_LINE_OPTION_PARSER_HH
36#define TTA_CMD_LINE_OPTION_PARSER_HH
37
38#include <string>
39#include <vector>
40#include "Exception.hh"
41
42class OptionValue;
43
44//////////////////////////////////////////////////////////////////////////////
45// CmdLineOptionParser
46//////////////////////////////////////////////////////////////////////////////
47
48/**
49 * Abstract base class for modeling command line options and their built-in
50 * mini-parser.
51 *
52 * All option types have a set of properties that identify the option: name,
53 * description and short name (alias). Possible concrete types of options
54 * are: Boolean, real, integer, and character string.
55 */
57public:
58
60 std::string name,
61 std::string desc,
62 std::string alias,
63 bool hidden = false);
64 virtual ~CmdLineOptionParser();
65
66 virtual OptionValue* copy() const = 0;
67
68 std::string longName() const;
69 std::string shortName() const;
70 std::string description() const;
71
72 /// Pure virtual function that parses the value of option.
73 virtual bool parseValue(std::string arguments, std::string prefix) = 0;
74
75 bool isHidden() { return hidden_; }
76 bool isDefined();
77
78 virtual int integer(int index = 0) const;
79 virtual unsigned unsignedInteger(int index = 0) const;
80 virtual std::string String(int index = 0) const;
81 virtual double real() const;
82 virtual bool isFlagOn() const;
83 virtual bool isFlagOff() const;
84 virtual int listSize() const;
85
86protected:
87 void setDefined();
88
89private:
90
91 /// Copying not allowed.
93 /// Assignment not allowed.
95
96 /// The full name of an option.
97 std::string longName_;
98 /// The optional alias (shorter name).
99 std::string shortName_;
100 /// The description of option.
101 std::string desc_;
102 /// The hidden flag. If set, no entry is printed in the normal help text
103 bool hidden_ = false;
104
105 /// Is the value of this option set in the parsed command line?
107};
108
109
110//////////////////////////////////////////////////////////////////////////////
111// IntegerCmdLineOptionParser
112//////////////////////////////////////////////////////////////////////////////
113
114/**
115 * Models an option that has an integer value.
116 */
118public:
120 std::string name,
121 std::string desc,
122 std::string alias = "");
124
125 virtual OptionValue* copy() const;
126
127 virtual bool parseValue(std::string arguments, std::string prefix);
128 virtual int integer(int index = 0) const;
129
130private:
131 /// Copying not allowed.
133 /// Assignment not allowed.
135
136 /// The value of option.
138};
139
140//////////////////////////////////////////////////////////////////////////////
141// UnsignedIntegerCmdLineOptionParser
142//////////////////////////////////////////////////////////////////////////////
143
144/**
145 * Models an option that has an unsigned integer value.
146 */
148public:
150 std::string name,
151 std::string desc,
152 std::string alias = "");
154
155 virtual OptionValue* copy() const;
156
157 virtual bool parseValue(std::string arguments, std::string prefix);
158 virtual unsigned unsignedInteger(int index = 0) const;
159
160private:
161 /// Copying not allowed.
164 /// Assignment not allowed.
167
168 /// The value of option.
169 unsigned value_;
170};
171
172
173//////////////////////////////////////////////////////////////////////////////
174// StringCmdLineOptionParser
175//////////////////////////////////////////////////////////////////////////////
176
177/**
178 * CmdLineOptionParser that has a string as a value.
179 */
181public:
183 std::string name,
184 std::string desc,
185 std::string alias = "");
187
188 virtual OptionValue* copy() const;
189
190 virtual bool parseValue(std::string arguments, std::string prefix);
191 virtual std::string String(int index = 0) const;
192
193private:
194 /// Copying not allowed.
196 /// Assignment not allowed.
198
199 /// The value of the option.
200 std::string value_;
201};
202
203//////////////////////////////////////////////////////////////////////////////
204// OptionalStringCmdLineOptionParser
205//////////////////////////////////////////////////////////////////////////////
206
207/**
208 * CmdLineOptionParser that acts as flag with optional string value.
209 */
211public:
213 std::string name,
214 std::string desc,
215 std::string alias = "");
217
218 virtual OptionValue* copy() const;
219
220 virtual bool parseValue(std::string arguments, std::string prefix);
221 virtual std::string String(int index = 0) const;
222 virtual bool isFlagOn() const;
223 virtual bool isFlagOff() const;
224
225private:
226 /// Copying not allowed.
229 /// Assignment not allowed.
232
233 /// The value of the option.
234 std::string value_;
235 /// The flag status.
236 bool flag_;
237};
238
239//////////////////////////////////////////////////////////////////////////////
240// RealCmdLineOptionParser
241//////////////////////////////////////////////////////////////////////////////
242
243/**
244 * CmdLineOptionParser that has a real value.
245 */
247public:
249 std::string name,
250 std::string desc,
251 std::string alias = "");
252 virtual ~RealCmdLineOptionParser();
253
254 virtual OptionValue* copy() const;
255
256 virtual bool parseValue(std::string arguments, std::string prefix);
257 virtual double real() const;
258
259private:
260 /// Copying not allowed.
262 /// Assignment not allowed.
264
265 /// The value of the option.
266 double value_;
267};
268
269//////////////////////////////////////////////////////////////////////////////
270// BoolCmdLineOptionParser
271//////////////////////////////////////////////////////////////////////////////
272
273/**
274 * CmdLineOptionParser that has a boolean value.
275 *
276 * This option is also called 'flag'.
277 */
279public:
281 std::string name,
282 std::string desc,
283 std::string alias = "",
284 bool hidden = false);
285 virtual ~BoolCmdLineOptionParser();
286
287 virtual OptionValue* copy() const;
288
289 virtual bool parseValue(std::string arguments, std::string prefix);
290 virtual bool isFlagOn() const;
291 virtual bool isFlagOff() const;
292
293private:
294 /// Copying not allowed.
296 /// Assignment not allowed.
298
299 /// The value of option.
300 bool value_;
301};
302
303//////////////////////////////////////////////////////////////////////////////
304// IntegerListCmdLineOptionParser
305//////////////////////////////////////////////////////////////////////////////
306
307/**
308 * CmdLineOptionParser that has a list of integers as value.
309 */
311public:
313 std::string name,
314 std::string desc,
315 std::string alias = "");
317
318 virtual OptionValue* copy() const;
319
320 virtual bool parseValue(std::string arguments, std::string prefix);
321
322 virtual int integer(int index = 0) const;
323 virtual int listSize() const;
324
325private:
326 /// Copying not allowed.
328 /// Assignment not allowed.
331
332 /// The values in integer list.
333 std::vector<int> values_;
334};
335
336
337//////////////////////////////////////////////////////////////////////////////
338// StringListCmdLineOptionParser
339//////////////////////////////////////////////////////////////////////////////
340
341/**
342 * CmdLineOptionParser that has a list of strings as value.
343 */
345public:
347 std::string name,
348 std::string desc,
349 std::string alias = "");
351
352 virtual OptionValue* copy() const;
353
354 virtual bool parseValue(std::string arguments, std::string prefix);
355
356 virtual std::string String(int index = 0) const;
357 virtual int listSize() const;
358
359private:
360 /// Copying not allowed.
362 /// Assignment not allowed.
365
366 /// The values in string list.
367 std::vector<std::string> values_;
368};
369
371
372#endif
virtual bool isFlagOn() const
bool value_
The value of option.
virtual OptionValue * copy() const
virtual bool parseValue(std::string arguments, std::string prefix)
BoolCmdLineOptionParser(const BoolCmdLineOptionParser &)
Copying not allowed.
BoolCmdLineOptionParser & operator=(const BoolCmdLineOptionParser &)
Assignment not allowed.
virtual bool isFlagOff() const
virtual OptionValue * copy() const =0
bool hidden_
The hidden flag. If set, no entry is printed in the normal help text.
bool defined_
Is the value of this option set in the parsed command line?
virtual int integer(int index=0) const
virtual int listSize() const
virtual bool isFlagOff() const
virtual bool isFlagOn() const
std::string longName() const
virtual double real() const
std::string shortName() const
CmdLineOptionParser & operator=(const CmdLineOptionParser &)
Assignment not allowed.
std::string longName_
The full name of an option.
std::string shortName_
The optional alias (shorter name).
virtual std::string String(int index=0) const
std::string desc_
The description of option.
std::string description() const
virtual bool parseValue(std::string arguments, std::string prefix)=0
Pure virtual function that parses the value of option.
virtual unsigned unsignedInteger(int index=0) const
CmdLineOptionParser(const CmdLineOptionParser &)
Copying not allowed.
virtual bool parseValue(std::string arguments, std::string prefix)
IntegerCmdLineOptionParser(const IntegerCmdLineOptionParser &)
Copying not allowed.
virtual int integer(int index=0) const
virtual OptionValue * copy() const
int value_
The value of option.
IntegerCmdLineOptionParser & operator=(const IntegerCmdLineOptionParser &)
Assignment not allowed.
IntegerListCmdLineOptionParser(const IntegerListCmdLineOptionParser &)
Copying not allowed.
std::vector< int > values_
The values in integer list.
virtual OptionValue * copy() const
IntegerListCmdLineOptionParser & operator=(const IntegerListCmdLineOptionParser &)
Assignment not allowed.
virtual int integer(int index=0) const
virtual bool parseValue(std::string arguments, std::string prefix)
OptionalStringCmdLineOptionParser & operator=(const OptionalStringCmdLineOptionParser &)
Assignment not allowed.
OptionalStringCmdLineOptionParser(const OptionalStringCmdLineOptionParser &)
Copying not allowed.
std::string value_
The value of the option.
virtual bool parseValue(std::string arguments, std::string prefix)
virtual OptionValue * copy() const
virtual std::string String(int index=0) const
RealCmdLineOptionParser & operator=(const RealCmdLineOptionParser &)
Assignment not allowed.
virtual OptionValue * copy() const
virtual double real() const
RealCmdLineOptionParser(const RealCmdLineOptionParser &)
Copying not allowed.
double value_
The value of the option.
virtual bool parseValue(std::string arguments, std::string prefix)
virtual std::string String(int index=0) const
virtual OptionValue * copy() const
StringCmdLineOptionParser(const StringCmdLineOptionParser &)
Copying not allowed.
std::string value_
The value of the option.
StringCmdLineOptionParser & operator=(const StringCmdLineOptionParser &)
Assignment not allowed.
virtual bool parseValue(std::string arguments, std::string prefix)
virtual OptionValue * copy() const
StringListCmdLineOptionParser(const StringListCmdLineOptionParser &)
Copying not allowed.
std::vector< std::string > values_
The values in string list.
StringListCmdLineOptionParser & operator=(const StringListCmdLineOptionParser &)
Assignment not allowed.
virtual bool parseValue(std::string arguments, std::string prefix)
virtual std::string String(int index=0) const
unsigned value_
The value of option.
virtual OptionValue * copy() const
virtual bool parseValue(std::string arguments, std::string prefix)
virtual unsigned unsignedInteger(int index=0) const
UnsignedIntegerCmdLineOptionParser(const UnsignedIntegerCmdLineOptionParser &)
Copying not allowed.
UnsignedIntegerCmdLineOptionParser & operator=(const UnsignedIntegerCmdLineOptionParser &)
Assignment not allowed.