tclap 1.2.1

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 reverved.
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>
31 #include <tclap/OptionalUnlabeledTracker.h>
32
33
34 namespace TCLAP {
35
42 template<class T>
43 class UnlabeledValueArg : public ValueArg<T>
44 {
45
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;
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,
115 CmdLineInterface& parser,
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,
142 Constraint<T>* constraint,
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,
171 Constraint<T>* constraint,
172 CmdLineInterface& parser,
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
212 template<class T>
213 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
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 {
222 _ignoreable = ignoreable;
223
224 OptionalUnlabeledTracker::check(req, toString());
225
226 }
227
228 template<class T>
229 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
230 const std::string& desc,
231 bool req,
232 T val,
233 const std::string& typeDesc,
234 CmdLineInterface& parser,
235 bool ignoreable,
236 Visitor* v)
237 : ValueArg<T>("", name, desc, req, val, typeDesc, v)
238 {
239 _ignoreable = ignoreable;
240 OptionalUnlabeledTracker::check(req, toString());
241 parser.add( this );
242 }
243
247 template<class T>
248 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
249 const std::string& desc,
250 bool req,
251 T val,
252 Constraint<T>* constraint,
253 bool ignoreable,
254 Visitor* v)
255 : ValueArg<T>("", name, desc, req, val, constraint, v)
256 {
257 _ignoreable = ignoreable;
258 OptionalUnlabeledTracker::check(req, toString());
259 }
260
261 template<class T>
262 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
263 const std::string& desc,
264 bool req,
265 T val,
266 Constraint<T>* constraint,
267 CmdLineInterface& parser,
268 bool ignoreable,
269 Visitor* v)
270 : ValueArg<T>("", name, desc, req, val, constraint, v)
271 {
272 _ignoreable = ignoreable;
273 OptionalUnlabeledTracker::check(req, toString());
274 parser.add( this );
275 }
276
280 template<class T>
281 bool 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
300 template<class T>
301 std::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
310 template<class T>
311 std::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
324 template<class T>
325 bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
326 {
327 if ( _name == a.getName() || _description == a.getDescription() )
328 return true;
329 else
330 return false;
331 }
332
333 template<class T>
334 void 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
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::UnlabeledValueArg::addToList
virtual void addToList(std::list< Arg * > &argList) const
Instead of pushing to the front of list, push to the back.
Definition: UnlabeledValueArg.h:334
TCLAP::OptionalUnlabeledTracker::check
static void check(bool req, const std::string &argName)
Definition: OptionalUnlabeledTracker.h:48
TCLAP::UnlabeledValueArg::operator==
virtual bool operator==(const Arg &a) const
Overrides operator== for specific behavior.
Definition: UnlabeledValueArg.h:325
TCLAP::ValueArg
The basic labeled argument that parses a value.
Definition: ValueArg.h:43
TCLAP::Arg::getName
const std::string & getName() const
Returns the argument name.
Definition: Arg.h:569
TCLAP::UnlabeledValueArg::UnlabeledValueArg
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.
Definition: UnlabeledValueArg.h:213
TCLAP::UnlabeledValueArg::longID
virtual std::string longID(const std::string &val="val") const
Overrides longID for specific behavior.
Definition: UnlabeledValueArg.h:311
TCLAP::Constraint
The interface that defines the interaction between the Arg and Constraint.
Definition: Constraint.h:38
TCLAP::Visitor
A base class that defines the interface for visitors.
Definition: Visitor.h:31
OptionalUnlabeledTracker.h
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::UnlabeledValueArg::processArg
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
Definition: UnlabeledValueArg.h:281
TCLAP::Arg::_ignoreable
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition: Arg.h:150
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
TCLAP::UnlabeledValueArg::shortID
virtual std::string shortID(const std::string &val="val") const
Overrides shortID for specific behavior.
Definition: UnlabeledValueArg.h:301
TCLAP::UnlabeledValueArg
The basic unlabeled argument that parses a value.
Definition: UnlabeledValueArg.h:43
ValueArg.h