unlabeled_value_arg.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H
16 #define TCLAP_UNLABELED_VALUE_ARGUMENT_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "value_arg.hpp"
23 
24 
25 namespace ecl {
26 
33 template<class T>
34 class UnlabeledValueArg : public ValueArg<T>
35 {
36 
37  // If compiler has two stage name lookup (as gcc >= 3.4 does)
38  // this is requried to prevent undef. symbols
43  using ValueArg<T>::_name;
47 
48  public:
49 
71  UnlabeledValueArg( const std::string& name,
72  const std::string& desc,
73  bool req,
74  T value,
75  const std::string& typeDesc,
76  bool ignoreable = false,
77  Visitor* v = NULL);
78 
101  UnlabeledValueArg( const std::string& name,
102  const std::string& desc,
103  bool req,
104  T value,
105  const std::string& typeDesc,
106  CmdLineInterface& parser,
107  bool ignoreable = false,
108  Visitor* v = NULL );
109 
129  UnlabeledValueArg( const std::string& name,
130  const std::string& desc,
131  bool req,
132  T value,
133  Constraint<T>* constraint,
134  bool ignoreable = false,
135  Visitor* v = NULL );
136 
137 
158  UnlabeledValueArg( const std::string& name,
159  const std::string& desc,
160  bool req,
161  T value,
162  Constraint<T>* constraint,
163  CmdLineInterface& parser,
164  bool ignoreable = false,
165  Visitor* v = NULL);
166 
175  virtual bool processArg(int* i, std::vector<std::string>& args);
176 
180  virtual std::string shortID(const std::string& val="val") const;
181 
185  virtual std::string longID(const std::string& val="val") const;
186 
190  virtual bool operator==(const Arg& a ) const;
191 
196  virtual void addToList( std::list<Arg*>& argList ) const;
197 
198 };
199 
203 template<class T>
205  const std::string& desc,
206  bool req,
207  T value,
208  const std::string& typeDesc,
209  bool ignoreable,
210  Visitor* v)
211 : ValueArg<T>("", name, desc, req, value, typeDesc, v)
212 {
213  _ignoreable = ignoreable;
214 
216 
217 }
218 
219 template<class T>
221  const std::string& desc,
222  bool req,
223  T value,
224  const std::string& typeDesc,
225  CmdLineInterface& parser,
226  bool ignoreable,
227  Visitor* v)
228 : ValueArg<T>("", name, desc, req, value, typeDesc, v)
229 {
230  _ignoreable = ignoreable;
232  parser.add( this );
233 }
234 
238 template<class T>
240  const std::string& desc,
241  bool req,
242  T value,
243  Constraint<T>* constraint,
244  bool ignoreable,
245  Visitor* v)
246 : ValueArg<T>("", name, desc, req, value, constraint, v)
247 {
248  _ignoreable = ignoreable;
250 }
251 
252 template<class T>
254  const std::string& desc,
255  bool req,
256  T value,
257  Constraint<T>* constraint,
258  CmdLineInterface& parser,
259  bool ignoreable,
260  Visitor* v)
261 : ValueArg<T>("", name, desc, req, value, constraint, v)
262 {
263  _ignoreable = ignoreable;
265  parser.add( this );
266 }
267 
271 template<class T>
272 bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
273 {
274 
275  if ( _alreadySet )
276  return false;
277 
278  if ( _hasBlanks( args[*i] ) )
279  return false;
280 
281  // never ignore an unlabeled arg
282 
283  _extractValue( args[*i] );
284  _alreadySet = true;
285  return true;
286 }
287 
291 template<class T>
292 std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
293 {
294  std::string id = "<" + _typeDesc + ">";
295 
296  return id;
297 }
298 
302 template<class T>
303 std::string UnlabeledValueArg<T>::longID(const std::string& val) const
304 {
305  // Ideally we would like to be able to use RTTI to return the name
306  // of the type required for this argument. However, g++ at least,
307  // doesn't appear to return terribly useful "names" of the types.
308  std::string id = "<" + _typeDesc + ">";
309 
310  return id;
311 }
312 
316 template<class T>
318 {
319  if ( _name == a.getName() || _description == a.getDescription() )
320  return true;
321  else
322  return false;
323 }
324 
325 template<class T>
326 void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
327 {
328  argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
329 }
330 
331 }; // namespace ecl
332 
333 #endif
bool _alreadySet
Definition: arg.hpp:101
void _extractValue(const std::string &val)
Definition: value_arg.hpp:487
virtual std::string longID(const std::string &val="val") const
TClap class indirectly used to define the interface for visitors.
Definition: visitor.hpp:25
Managing interface for The base class that manages the command line definition and passes along the p...
Virtual parent for all the different argument classes.
Definition: arg.hpp:37
TCLAP command line argument parser classes.
bool _ignoreable
Definition: arg.hpp:114
const std::string & getName() const
Definition: arg.hpp:463
Defines the interaction between an argument and a constraint.
Definition: constraint.hpp:34
UnlabeledValueArg(const std::string &name, const std::string &desc, bool req, T value, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
std::string _typeDesc
Definition: value_arg.hpp:174
virtual std::string toString() const
Definition: arg.hpp:493
virtual void add(Arg &a)=0
virtual bool processArg(int *i, std::vector< std::string > &args)
std::string _name
Definition: arg.hpp:71
std::string getDescription() const
Definition: arg.hpp:448
virtual bool operator==(const Arg &a) const
bool _hasBlanks(const std::string &s) const
Definition: arg.hpp:535
virtual void addToList(std::list< Arg * > &argList) const
TCLAP command line argument parser classes.
std::string _description
Definition: arg.hpp:76
virtual std::string shortID(const std::string &val="val") const
static void check(bool req, const std::string &argName)


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:08