tclap: UnlabeledMultiArg.h Source File

tclap 1.2.5

UnlabeledMultiArg.h
Go to the documentation of this file.
1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3
4 /******************************************************************************
5 *
6 * file: UnlabeledMultiArg.h
7 *
8 * Copyright (c) 2003, Michael E. Smoot.
9 * Copyright (c) 2017, Google LLC
10 * All rights reserved.
11 *
12 * See the file COPYING in the top directory of this distribution for
13 * more information.
14 *
15 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 *****************************************************************************/
24
25
26 #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
27 #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
28
29 #include <string>
30 #include <vector>
31
32 #include <tclap/MultiArg.h>
33 #include <tclap/OptionalUnlabeledTracker.h>
34
35 namespace TCLAP {
36
42 template<class T>
43 class UnlabeledMultiArg : public MultiArg<T>
44 {
45
46 // If compiler has two stage name lookup (as gcc >= 3.4 does)
47 // this is required to prevent undef. symbols
48 using MultiArg<T>::_ignoreable;
49 using MultiArg<T>::_hasBlanks;
50 using MultiArg<T>::_extractValue;
51 using MultiArg<T>::_typeDesc;
52 using MultiArg<T>::_name;
53 using MultiArg<T>::_description;
54 using MultiArg<T>::_alreadySet;
55 using MultiArg<T>::toString;
56
57 public:
58
76 UnlabeledMultiArg( const std::string& name,
77 const std::string& desc,
78 bool req,
79 const std::string& typeDesc,
80 bool ignoreable = false,
81 Visitor* v = NULL );
100 UnlabeledMultiArg( const std::string& name,
101 const std::string& desc,
102 bool req,
103 const std::string& typeDesc,
104 CmdLineInterface& parser,
105 bool ignoreable = false,
106 Visitor* v = NULL );
107
123 UnlabeledMultiArg( const std::string& name,
124 const std::string& desc,
125 bool req,
126 Constraint<T>* constraint,
127 bool ignoreable = false,
128 Visitor* v = NULL );
129
146 UnlabeledMultiArg( const std::string& name,
147 const std::string& desc,
148 bool req,
149 Constraint<T>* constraint,
150 CmdLineInterface& parser,
151 bool ignoreable = false,
152 Visitor* v = NULL );
153
162 virtual bool processArg(int* i, std::vector<std::string>& args);
163
168 virtual std::string shortID(const std::string& val="val") const;
169
174 virtual std::string longID(const std::string& val="val") const;
175
180 virtual bool operator==(const Arg& a) const;
181
186 virtual void addToList( std::list<Arg*>& argList ) const;
187 };
188
189 template<class T>
190 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
191 const std::string& desc,
192 bool req,
193 const std::string& typeDesc,
194 bool ignoreable,
195 Visitor* v)
196 : MultiArg<T>("", name, desc, req, typeDesc, v)
197 {
198 _ignoreable = ignoreable;
199 OptionalUnlabeledTracker::check(true, toString());
200 }
201
202 template<class T>
203 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
204 const std::string& desc,
205 bool req,
206 const std::string& typeDesc,
207 CmdLineInterface& parser,
208 bool ignoreable,
209 Visitor* v)
210 : MultiArg<T>("", name, desc, req, typeDesc, v)
211 {
212 _ignoreable = ignoreable;
213 OptionalUnlabeledTracker::check(true, toString());
214 parser.add( this );
215 }
216
217
218 template<class T>
219 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
220 const std::string& desc,
221 bool req,
222 Constraint<T>* constraint,
223 bool ignoreable,
224 Visitor* v)
225 : MultiArg<T>("", name, desc, req, constraint, v)
226 {
227 _ignoreable = ignoreable;
228 OptionalUnlabeledTracker::check(true, toString());
229 }
230
231 template<class T>
232 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
233 const std::string& desc,
234 bool req,
235 Constraint<T>* constraint,
236 CmdLineInterface& parser,
237 bool ignoreable,
238 Visitor* v)
239 : MultiArg<T>("", name, desc, req, constraint, v)
240 {
241 _ignoreable = ignoreable;
242 OptionalUnlabeledTracker::check(true, toString());
243 parser.add( this );
244 }
245
246
247 template<class T>
248 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
249 {
250
251 if ( _hasBlanks( args[*i] ) )
252 return false;
253
254 // never ignore an unlabeled multi arg
255
256
257 // always take the first value, regardless of the start string
258 _extractValue( args[(*i)] );
259
260 /*
261 // continue taking args until we hit the end or a start string
262 while ( (unsigned int)(*i)+1 < args.size() &&
263 args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
264 args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
265 _extractValue( args[++(*i)] );
266 */
267
268 _alreadySet = true;
269
270 return true;
271 }
272
273 template<class T>
274 std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
275 {
276 static_cast<void>(val); // Ignore input, don't warn
277 return std::string("<") + _typeDesc + "> ...";
278 }
279
280 template<class T>
281 std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
282 {
283 static_cast<void>(val); // Ignore input, don't warn
284 return std::string("<") + _typeDesc + "> (accepted multiple times)";
285 }
286
287 template<class T>
288 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
289 {
290 if ( _name == a.getName() || _description == a.getDescription() )
291 return true;
292 else
293 return false;
294 }
295
296 template<class T>
297 void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
298 {
299 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
300 }
301
302 }
303
304 #endif
MultiArg.h
OptionalUnlabeledTracker.h
TCLAP::Arg
A virtual base class that defines the essential data for all arguments.
Definition: Arg.h:56
TCLAP::Arg::_ignoreable
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition: Arg.h:141
TCLAP::Arg::getName
const std::string & getName() const
Returns the argument name.
Definition: Arg.h:560
TCLAP::Arg::getDescription
std::string getDescription() const
Returns the argument description.
Definition: Arg.h:545
TCLAP::Arg::toString
virtual std::string toString() const
Returns a simple string representation of the argument.
Definition: Arg.h:590
TCLAP::CmdLineInterface
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: CmdLineInterface.h:47
TCLAP::CmdLineInterface::add
virtual void add(Arg &a)=0
Adds an argument to the list of arguments to be parsed.
TCLAP::Constraint
The interface that defines the interaction between the Arg and Constraint.
Definition: Constraint.h:43
TCLAP::MultiArg
An argument that allows multiple values of type T to be specified.
Definition: MultiArg.h:43
TCLAP::OptionalUnlabeledTracker::check
static void check(bool req, const std::string &argName)
Definition: OptionalUnlabeledTracker.h:50
TCLAP::UnlabeledMultiArg
Just like a MultiArg, except that the arguments are unlabeled.
Definition: UnlabeledMultiArg.h:44
TCLAP::UnlabeledMultiArg::addToList
virtual void addToList(std::list< Arg * > &argList) const
Pushes this to back of list rather than front.
Definition: UnlabeledMultiArg.h:297
TCLAP::UnlabeledMultiArg::shortID
virtual std::string shortID(const std::string &val="val") const
Returns the a short id string.
Definition: UnlabeledMultiArg.h:274
TCLAP::UnlabeledMultiArg::UnlabeledMultiArg
UnlabeledMultiArg(const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
Constructor.
Definition: UnlabeledMultiArg.h:190
TCLAP::UnlabeledMultiArg::longID
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
Definition: UnlabeledMultiArg.h:281
TCLAP::UnlabeledMultiArg::operator==
virtual bool operator==(const Arg &a) const
Operator ==.
Definition: UnlabeledMultiArg.h:288
TCLAP::UnlabeledMultiArg::processArg
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
Definition: UnlabeledMultiArg.h:248
TCLAP::Visitor
A base class that defines the interface for visitors.
Definition: Visitor.h:35
TCLAP
Definition: Arg.h:48