tclap 1.2.2
UnlabeledValueArg.h
Go to the documentation of this file.
1
2/******************************************************************************
3 *
4 * file: UnlabeledValueArg.h
5 *
6 * Copyright (c) 2003, Michael E. Smoot .
7 * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
8 * All rights reserved.
9 *
10 * See the file COPYING in the top directory of this distribution for
11 * more information.
12 *
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.
20 *
21 *****************************************************************************/
22
23
24#ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H
25#define TCLAP_UNLABELED_VALUE_ARGUMENT_H
26
27#include <string>
28#include <vector>
29
30#include <tclap/ValueArg.h>
32
33
34namespace TCLAP {
35
42template<class T>
43class UnlabeledValueArg : public ValueArg<T>
44{
45
46 // If compiler has two stage name lookup (as gcc >= 3.4 does)
47 // this is required to prevent undef. symbols
52 using ValueArg<T>::_name;
55 using ValueArg<T>::toString;
56
57 public:
58
80 UnlabeledValueArg( const std::string& name,
81 const std::string& desc,
82 bool req,
83 T value,
84 const std::string& typeDesc,
85 bool ignoreable = false,
86 Visitor* v = NULL);
87
110 UnlabeledValueArg( const std::string& name,
111 const std::string& desc,
112 bool req,
113 T value,
114 const std::string& typeDesc,
116 bool ignoreable = false,
117 Visitor* v = NULL );
118
138 UnlabeledValueArg( const std::string& name,
139 const std::string& desc,
140 bool req,
141 T value,
143 bool ignoreable = false,
144 Visitor* v = NULL );
145
146
167 UnlabeledValueArg( const std::string& name,
168 const std::string& desc,
169 bool req,
170 T value,
173 bool ignoreable = false,
174 Visitor* v = NULL);
175
184 virtual bool processArg(int* i, std::vector<std::string>& args);
185
189 virtual std::string shortID(const std::string& val="val") const;
190
194 virtual std::string longID(const std::string& val="val") const;
195
199 virtual bool operator==(const Arg& a ) const;
200
205 virtual void addToList( std::list<Arg*>& argList ) const;
206
207};
208
212template<class T>
214 const std::string& desc,
215 bool req,
216 T val,
217 const std::string& typeDesc,
218 bool ignoreable,
219 Visitor* v)
220: ValueArg<T>("", name, desc, req, val, typeDesc, v)
221{
223
225
226}
227
228template<class T>
230 const std::string& desc,
231 bool req,
232 T val,
233 const std::string& typeDesc,
235 bool ignoreable,
236 Visitor* v)
237: ValueArg<T>("", name, desc, req, val, typeDesc, v)
238{
241 parser.add( this );
242}
243
247template<class T>
249 const std::string& desc,
250 bool req,
251 T val,
253 bool ignoreable,
254 Visitor* v)
255: ValueArg<T>("", name, desc, req, val, constraint, v)
256{
259}
260
261template<class T>
263 const std::string& desc,
264 bool req,
265 T val,
268 bool ignoreable,
269 Visitor* v)
270: ValueArg<T>("", name, desc, req, val, constraint, v)
271{
274 parser.add( this );
275}
276
280template<class T>
281bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
282{
283
284 if ( _alreadySet )
285 return false;
286
287 if ( _hasBlanks( args[*i] ) )
288 return false;
289
290 // never ignore an unlabeled arg
291
292 _extractValue( args[*i] );
293 _alreadySet = true;
294 return true;
295}
296
300template<class T>
301std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
302{
303 static_cast<void>(val); // Ignore input, don't warn
304 return std::string("<") + _typeDesc + ">";
305}
306
310template<class T>
311std::string UnlabeledValueArg<T>::longID(const std::string& val) const
312{
313 static_cast<void>(val); // Ignore input, don't warn
314
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 + ">";
319}
320
324template<class T>
326{
327 if ( _name == a.getName() || _description == a.getDescription() )
328 return true;
329 else
330 return false;
331}
332
333template<class T>
334void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
335{
336 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
337}
338
339}
340#endif
A virtual base class that defines the essential data for all arguments.
Definition Arg.h:66
bool _hasBlanks(const std::string &s) const
Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
Definition Arg.h:642
bool _alreadySet
Indicates whether the argument has been set.
Definition Arg.h:138
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition Arg.h:151
std::string _description
Description of the argument.
Definition Arg.h:113
std::string _name
A single word namd identifying the argument.
Definition Arg.h:108
virtual std::string toString() const
Returns a simple string representation of the argument.
Definition Arg.h:600
The base class that manages the command line definition and passes along the parsing to the appropria...
The interface that defines the interaction between the Arg and Constraint.
Definition Constraint.h:39
static void check(bool req, const std::string &argName)
The basic unlabeled argument that parses a value.
virtual std::string longID(const std::string &val="val") const
Overrides longID for specific behavior.
virtual std::string shortID(const std::string &val="val") const
Overrides shortID for specific behavior.
virtual void addToList(std::list< Arg * > &argList) const
Instead of pushing to the front of list, push to the back.
UnlabeledValueArg(const std::string &name, const std::string &desc, bool req, T value, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
UnlabeledValueArg constructor.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
virtual bool operator==(const Arg &a) const
Overrides operator== for specific behavior.
The basic labeled argument that parses a value.
Definition ValueArg.h:44
std::string _typeDesc
A human readable description of the type to be parsed.
Definition ValueArg.h:67
void _extractValue(const std::string &val)
Extracts the value from the string.
Definition ValueArg.h:400
A base class that defines the interface for visitors.
Definition Visitor.h:32
Definition Arg.h:58
void DelPtr(T ptr)
Definition CmdLine.h:53