tclap 1.2.1

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 reverved.
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>
30 #include <tclap/OptionalUnlabeledTracker.h>
31
32 namespace TCLAP {
33
39 template<class T>
40 class UnlabeledMultiArg : public MultiArg<T>
41 {
42
43 // If compiler has two stage name lookup (as gcc >= 3.4 does)
44 // this is requried to prevent undef. symbols
45 using MultiArg<T>::_ignoreable;
46 using MultiArg<T>::_hasBlanks;
47 using MultiArg<T>::_extractValue;
48 using MultiArg<T>::_typeDesc;
49 using MultiArg<T>::_name;
50 using MultiArg<T>::_description;
51 using MultiArg<T>::_alreadySet;
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,
101 CmdLineInterface& parser,
102 bool ignoreable = false,
103 Visitor* v = NULL );
104
120 UnlabeledMultiArg( const std::string& name,
121 const std::string& desc,
122 bool req,
123 Constraint<T>* constraint,
124 bool ignoreable = false,
125 Visitor* v = NULL );
126
143 UnlabeledMultiArg( const std::string& name,
144 const std::string& desc,
145 bool req,
146 Constraint<T>* constraint,
147 CmdLineInterface& parser,
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
186 template<class T>
187 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
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 {
195 _ignoreable = ignoreable;
196 OptionalUnlabeledTracker::check(true, toString());
197 }
198
199 template<class T>
200 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
201 const std::string& desc,
202 bool req,
203 const std::string& typeDesc,
204 CmdLineInterface& parser,
205 bool ignoreable,
206 Visitor* v)
207 : MultiArg<T>("", name, desc, req, typeDesc, v)
208 {
209 _ignoreable = ignoreable;
210 OptionalUnlabeledTracker::check(true, toString());
211 parser.add( this );
212 }
213
214
215 template<class T>
216 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
217 const std::string& desc,
218 bool req,
219 Constraint<T>* constraint,
220 bool ignoreable,
221 Visitor* v)
222 : MultiArg<T>("", name, desc, req, constraint, v)
223 {
224 _ignoreable = ignoreable;
225 OptionalUnlabeledTracker::check(true, toString());
226 }
227
228 template<class T>
229 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
230 const std::string& desc,
231 bool req,
232 Constraint<T>* constraint,
233 CmdLineInterface& parser,
234 bool ignoreable,
235 Visitor* v)
236 : MultiArg<T>("", name, desc, req, constraint, v)
237 {
238 _ignoreable = ignoreable;
239 OptionalUnlabeledTracker::check(true, toString());
240 parser.add( this );
241 }
242
243
244 template<class T>
245 bool 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
270 template<class T>
271 std::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
277 template<class T>
278 std::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
284 template<class T>
285 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
286 {
287 if ( _name == a.getName() || _description == a.getDescription() )
288 return true;
289 else
290 return false;
291 }
292
293 template<class T>
294 void 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
TCLAP::Arg
A virtual base class that defines the essential data for all arguments.
Definition: Arg.h:64
TCLAP::Arg::getDescription
std::string getDescription() const
Returns the argument description.
Definition: Arg.h:554
TCLAP::UnlabeledMultiArg::shortID
virtual std::string shortID(const std::string &val="val") const
Returns the a short id string.
Definition: UnlabeledMultiArg.h:271
TCLAP::OptionalUnlabeledTracker::check
static void check(bool req, const std::string &argName)
Definition: OptionalUnlabeledTracker.h:48
TCLAP::MultiArg
An argument that allows multiple values of type T to be specified.
Definition: MultiArg.h:39
TCLAP::UnlabeledMultiArg::processArg
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
Definition: UnlabeledMultiArg.h:245
TCLAP::Arg::getName
const std::string & getName() const
Returns the argument name.
Definition: Arg.h:569
TCLAP::Constraint
The interface that defines the interaction between the Arg and Constraint.
Definition: Constraint.h:38
TCLAP::UnlabeledMultiArg::addToList
virtual void addToList(std::list< Arg * > &argList) const
Pushes this to back of list rather than front.
Definition: UnlabeledMultiArg.h:294
TCLAP::Visitor
A base class that defines the interface for visitors.
Definition: Visitor.h:31
OptionalUnlabeledTracker.h
TCLAP::UnlabeledMultiArg::longID
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
Definition: UnlabeledMultiArg.h:278
TCLAP::UnlabeledMultiArg
Just like a MultiArg, except that the arguments are unlabeled.
Definition: UnlabeledMultiArg.h:40
TCLAP::CmdLineInterface
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: CmdLineInterface.h:43
TCLAP::CmdLineInterface::add
virtual void add(Arg &a)=0
Adds an argument to the list of arguments to be parsed.
TCLAP::Arg::_ignoreable
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition: Arg.h:150
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:187
TCLAP::UnlabeledMultiArg::operator==
virtual bool operator==(const Arg &a) const
Opertor ==.
Definition: UnlabeledMultiArg.h:285
TCLAP
Definition: Arg.h:57
TCLAP::Arg::toString
virtual std::string toString() const
Returns a simple string representation of the argument.
Definition: Arg.h:599
MultiArg.h