2
/******************************************************************************
4
* file: UnlabeledValueArg.h
6
* Copyright (c) 2003, Michael E. Smoot .
7
* Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
10
* See the file COPYING in the top directory of this distribution for
13
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
* DEALINGS IN THE SOFTWARE.
21
*****************************************************************************/
24
#ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H
25
#define TCLAP_UNLABELED_VALUE_ARGUMENT_H
30
#include <tclap/ValueArg.h>
31
#include <tclap/OptionalUnlabeledTracker.h>
37
* The basic unlabeled argument that parses a value.
38
* This is a template class, which means the type T defines the type
39
* that a given object will attempt to parse when an UnlabeledValueArg
40
* is reached in the list of args that the CmdLine iterates over.
43
class UnlabeledValueArg : public ValueArg<T>
46
// If compiler has two stage name lookup (as gcc >= 3.4 does)
47
// this is requried to prevent undef. symbols
48
using ValueArg<T>::_ignoreable;
49
using ValueArg<T>::_hasBlanks;
50
using ValueArg<T>::_extractValue;
51
using ValueArg<T>::_typeDesc;
52
using ValueArg<T>::_name;
53
using ValueArg<T>::_description;
54
using ValueArg<T>::_alreadySet;
55
using ValueArg<T>::toString;
60
* UnlabeledValueArg constructor.
61
* \param name - A one word name for the argument. Note that this is used for
62
* identification, not as a long flag.
63
* \param desc - A description of what the argument is for or
65
* \param req - Whether the argument is required on the command
67
* \param value - The default value assigned to this argument if it
68
* is not present on the command line.
69
* \param typeDesc - A short, human readable description of the
70
* type that this object expects. This is used in the generation
71
* of the USAGE statement. The goal is to be helpful to the end user
73
* \param ignoreable - Allows you to specify that this argument can be
74
* ignored if the '--' flag is set. This defaults to false (cannot
75
* be ignored) and should generally stay that way unless you have
76
* some special need for certain arguments to be ignored.
77
* \param v - Optional Vistor. You should leave this blank unless
78
* you have a very good reason.
80
UnlabeledValueArg( const std::string& name,
81
const std::string& desc,
84
const std::string& typeDesc,
85
bool ignoreable = false,
89
* UnlabeledValueArg constructor.
90
* \param name - A one word name for the argument. Note that this is used for
91
* identification, not as a long flag.
92
* \param desc - A description of what the argument is for or
94
* \param req - Whether the argument is required on the command
96
* \param value - The default value assigned to this argument if it
97
* is not present on the command line.
98
* \param typeDesc - A short, human readable description of the
99
* type that this object expects. This is used in the generation
100
* of the USAGE statement. The goal is to be helpful to the end user
102
* \param parser - A CmdLine parser object to add this Arg to
103
* \param ignoreable - Allows you to specify that this argument can be
104
* ignored if the '--' flag is set. This defaults to false (cannot
105
* be ignored) and should generally stay that way unless you have
106
* some special need for certain arguments to be ignored.
107
* \param v - Optional Vistor. You should leave this blank unless
108
* you have a very good reason.
110
UnlabeledValueArg( const std::string& name,
111
const std::string& desc,
114
const std::string& typeDesc,
115
CmdLineInterface& parser,
116
bool ignoreable = false,
120
* UnlabeledValueArg constructor.
121
* \param name - A one word name for the argument. Note that this is used for
122
* identification, not as a long flag.
123
* \param desc - A description of what the argument is for or
125
* \param req - Whether the argument is required on the command
127
* \param value - The default value assigned to this argument if it
128
* is not present on the command line.
129
* \param constraint - A pointer to a Constraint object used
130
* to constrain this Arg.
131
* \param ignoreable - Allows you to specify that this argument can be
132
* ignored if the '--' flag is set. This defaults to false (cannot
133
* be ignored) and should generally stay that way unless you have
134
* some special need for certain arguments to be ignored.
135
* \param v - Optional Vistor. You should leave this blank unless
136
* you have a very good reason.
138
UnlabeledValueArg( const std::string& name,
139
const std::string& desc,
142
Constraint<T>* constraint,
143
bool ignoreable = false,
148
* UnlabeledValueArg constructor.
149
* \param name - A one word name for the argument. Note that this is used for
150
* identification, not as a long flag.
151
* \param desc - A description of what the argument is for or
153
* \param req - Whether the argument is required on the command
155
* \param value - The default value assigned to this argument if it
156
* is not present on the command line.
157
* \param constraint - A pointer to a Constraint object used
158
* to constrain this Arg.
159
* \param parser - A CmdLine parser object to add this Arg to
160
* \param ignoreable - Allows you to specify that this argument can be
161
* ignored if the '--' flag is set. This defaults to false (cannot
162
* be ignored) and should generally stay that way unless you have
163
* some special need for certain arguments to be ignored.
164
* \param v - Optional Vistor. You should leave this blank unless
165
* you have a very good reason.
167
UnlabeledValueArg( const std::string& name,
168
const std::string& desc,
171
Constraint<T>* constraint,
172
CmdLineInterface& parser,
173
bool ignoreable = false,
177
* Handles the processing of the argument.
178
* This re-implements the Arg version of this method to set the
179
* _value of the argument appropriately. Handling specific to
180
* unlabled arguments.
181
* \param i - Pointer the the current argument in the list.
182
* \param args - Mutable list of strings.
184
virtual bool processArg(int* i, std::vector<std::string>& args);
187
* Overrides shortID for specific behavior.
189
virtual std::string shortID(const std::string& val="val") const;
192
* Overrides longID for specific behavior.
194
virtual std::string longID(const std::string& val="val") const;
197
* Overrides operator== for specific behavior.
199
virtual bool operator==(const Arg& a ) const;
202
* Instead of pushing to the front of list, push to the back.
203
* \param argList - The list to add this to.
205
virtual void addToList( std::list<Arg*>& argList ) const;
210
* Constructor implemenation.
213
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
214
const std::string& desc,
217
const std::string& typeDesc,
220
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
222
_ignoreable = ignoreable;
224
OptionalUnlabeledTracker::check(req, toString());
229
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
230
const std::string& desc,
233
const std::string& typeDesc,
234
CmdLineInterface& parser,
237
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
239
_ignoreable = ignoreable;
240
OptionalUnlabeledTracker::check(req, toString());
245
* Constructor implemenation.
248
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
249
const std::string& desc,
252
Constraint<T>* constraint,
255
: ValueArg<T>("", name, desc, req, val, constraint, v)
257
_ignoreable = ignoreable;
258
OptionalUnlabeledTracker::check(req, toString());
262
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
263
const std::string& desc,
266
Constraint<T>* constraint,
267
CmdLineInterface& parser,
270
: ValueArg<T>("", name, desc, req, val, constraint, v)
272
_ignoreable = ignoreable;
273
OptionalUnlabeledTracker::check(req, toString());
278
* Implementation of processArg().
281
bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
287
if ( _hasBlanks( args[*i] ) )
290
// never ignore an unlabeled arg
292
_extractValue( args[*i] );
298
* Overriding shortID for specific output.
301
std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
303
static_cast<void>(val); // Ignore input, don't warn
304
return std::string("<") + _typeDesc + ">";
308
* Overriding longID for specific output.
311
std::string UnlabeledValueArg<T>::longID(const std::string& val) const
313
static_cast<void>(val); // Ignore input, don't warn
315
// Ideally we would like to be able to use RTTI to return the name
316
// of the type required for this argument. However, g++ at least,
317
// doesn't appear to return terribly useful "names" of the types.
318
return std::string("<") + _typeDesc + ">";
322
* Overriding operator== for specific behavior.
325
bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
327
if ( _name == a.getName() || _description == a.getDescription() )
334
void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
336
argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );