tclap 1.2.2
UnlabeledMultiArg.h
Go to the documentation of this file.
1
2/******************************************************************************
3 *
4 * file: UnlabeledMultiArg.h
5 *
6 * Copyright (c) 2003, Michael E. Smoot.
7 * All rights reserved.
8 *
9 * See the file COPYING in the top directory of this distribution for
10 * more information.
11 *
12 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
19 *
20 *****************************************************************************/
21
22
23#ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
24#define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
25
26#include <string>
27#include <vector>
28
29#include <tclap/MultiArg.h>
31
32namespace TCLAP {
33
39template<class T>
40class UnlabeledMultiArg : public MultiArg<T>
41{
42
43 // If compiler has two stage name lookup (as gcc >= 3.4 does)
44 // this is required to prevent undef. symbols
49 using MultiArg<T>::_name;
52 using MultiArg<T>::toString;
53
54 public:
55
73 UnlabeledMultiArg( const std::string& name,
74 const std::string& desc,
75 bool req,
76 const std::string& typeDesc,
77 bool ignoreable = false,
78 Visitor* v = NULL );
97 UnlabeledMultiArg( const std::string& name,
98 const std::string& desc,
99 bool req,
100 const std::string& typeDesc,
102 bool ignoreable = false,
103 Visitor* v = NULL );
104
120 UnlabeledMultiArg( const std::string& name,
121 const std::string& desc,
122 bool req,
124 bool ignoreable = false,
125 Visitor* v = NULL );
126
143 UnlabeledMultiArg( const std::string& name,
144 const std::string& desc,
145 bool req,
148 bool ignoreable = false,
149 Visitor* v = NULL );
150
159 virtual bool processArg(int* i, std::vector<std::string>& args);
160
165 virtual std::string shortID(const std::string& val="val") const;
166
171 virtual std::string longID(const std::string& val="val") const;
172
177 virtual bool operator==(const Arg& a) const;
178
183 virtual void addToList( std::list<Arg*>& argList ) const;
184};
185
186template<class T>
188 const std::string& desc,
189 bool req,
190 const std::string& typeDesc,
191 bool ignoreable,
192 Visitor* v)
193: MultiArg<T>("", name, desc, req, typeDesc, v)
194{
197}
198
199template<class T>
201 const std::string& desc,
202 bool req,
203 const std::string& typeDesc,
205 bool ignoreable,
206 Visitor* v)
207: MultiArg<T>("", name, desc, req, typeDesc, v)
208{
211 parser.add( this );
212}
213
214
215template<class T>
217 const std::string& desc,
218 bool req,
220 bool ignoreable,
221 Visitor* v)
222: MultiArg<T>("", name, desc, req, constraint, v)
223{
226}
227
228template<class T>
230 const std::string& desc,
231 bool req,
234 bool ignoreable,
235 Visitor* v)
236: MultiArg<T>("", name, desc, req, constraint, v)
237{
240 parser.add( this );
241}
242
243
244template<class T>
245bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
246{
247
248 if ( _hasBlanks( args[*i] ) )
249 return false;
250
251 // never ignore an unlabeled multi arg
252
253
254 // always take the first value, regardless of the start string
255 _extractValue( args[(*i)] );
256
257 /*
258 // continue taking args until we hit the end or a start string
259 while ( (unsigned int)(*i)+1 < args.size() &&
260 args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
261 args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
262 _extractValue( args[++(*i)] );
263 */
264
265 _alreadySet = true;
266
267 return true;
268}
269
270template<class T>
271std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
272{
273 static_cast<void>(val); // Ignore input, don't warn
274 return std::string("<") + _typeDesc + "> ...";
275}
276
277template<class T>
278std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
279{
280 static_cast<void>(val); // Ignore input, don't warn
281 return std::string("<") + _typeDesc + "> (accepted multiple times)";
282}
283
284template<class T>
286{
287 if ( _name == a.getName() || _description == a.getDescription() )
288 return true;
289 else
290 return false;
291}
292
293template<class T>
294void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
295{
296 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
297}
298
299}
300
301#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
An argument that allows multiple values of type T to be specified.
Definition MultiArg.h:40
std::string _typeDesc
The description of type T to be used in the usage.
Definition MultiArg.h:56
void _extractValue(const std::string &val)
Extracts the value from the string.
Definition MultiArg.h:398
static void check(bool req, const std::string &argName)
Just like a MultiArg, except that the arguments are unlabeled.
virtual void addToList(std::list< Arg * > &argList) const
Pushes this to back of list rather than front.
virtual std::string shortID(const std::string &val="val") const
Returns the a short id string.
UnlabeledMultiArg(const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
Constructor.
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
virtual bool operator==(const Arg &a) const
Operator ==.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
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