unlabeled_multi_arg.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
16 #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "multi_arg.hpp"
23 
24 namespace ecl {
25 
31 template<class T>
32 class UnlabeledMultiArg : public MultiArg<T>
33 {
34 
35  // If compiler has two stage name lookup (as gcc >= 3.4 does)
36  // this is requried to prevent undef. symbols
41  using MultiArg<T>::_name;
45 
46  public:
47 
65  UnlabeledMultiArg( const std::string& name,
66  const std::string& desc,
67  bool req,
68  const std::string& typeDesc,
69  bool ignoreable = false,
70  Visitor* v = NULL );
89  UnlabeledMultiArg( const std::string& name,
90  const std::string& desc,
91  bool req,
92  const std::string& typeDesc,
93  CmdLineInterface& parser,
94  bool ignoreable = false,
95  Visitor* v = NULL );
96 
112  UnlabeledMultiArg( const std::string& name,
113  const std::string& desc,
114  bool req,
115  Constraint<T>* constraint,
116  bool ignoreable = false,
117  Visitor* v = NULL );
118 
135  UnlabeledMultiArg( const std::string& name,
136  const std::string& desc,
137  bool req,
138  Constraint<T>* constraint,
139  CmdLineInterface& parser,
140  bool ignoreable = false,
141  Visitor* v = NULL );
142 
151  virtual bool processArg(int* i, std::vector<std::string>& args);
152 
157  virtual std::string shortID(const std::string& val="val") const;
158 
163  virtual std::string longID(const std::string& val="val") const;
164 
169  virtual bool operator==(const Arg& a) const;
170 
175  virtual void addToList( std::list<Arg*>& argList ) const;
176 };
177 
178 template<class T>
180  const std::string& desc,
181  bool req,
182  const std::string& typeDesc,
183  bool ignoreable,
184  Visitor* v)
185 : MultiArg<T>("", name, desc, req, typeDesc, v)
186 {
187  _ignoreable = ignoreable;
189 }
190 
191 template<class T>
193  const std::string& desc,
194  bool req,
195  const std::string& typeDesc,
196  CmdLineInterface& parser,
197  bool ignoreable,
198  Visitor* v)
199 : MultiArg<T>("", name, desc, req, typeDesc, v)
200 {
201  _ignoreable = ignoreable;
203  parser.add( this );
204 }
205 
206 
207 template<class T>
209  const std::string& desc,
210  bool req,
211  Constraint<T>* constraint,
212  bool ignoreable,
213  Visitor* v)
214 : MultiArg<T>("", name, desc, req, constraint, v)
215 {
216  _ignoreable = ignoreable;
218 }
219 
220 template<class T>
222  const std::string& desc,
223  bool req,
224  Constraint<T>* constraint,
225  CmdLineInterface& parser,
226  bool ignoreable,
227  Visitor* v)
228 : MultiArg<T>("", name, desc, req, constraint, v)
229 {
230  _ignoreable = ignoreable;
232  parser.add( this );
233 }
234 
235 
236 template<class T>
237 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
238 {
239 
240  if ( _hasBlanks( args[*i] ) )
241  return false;
242 
243  // never ignore an unlabeled multi arg
244 
245 
246  // always take the first value, regardless of the start string
247  _extractValue( args[(*i)] );
248 
249  /*
250  // continue taking args until we hit the end or a start string
251  while ( (unsigned int)(*i)+1 < args.size() &&
252  args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
253  args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
254  _extractValue( args[++(*i)] );
255  */
256 
257  _alreadySet = true;
258 
259  return true;
260 }
261 
262 template<class T>
263 std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
264 {
265  std::string id = "<" + _typeDesc + "> ...";
266 
267  return id;
268 }
269 
270 template<class T>
271 std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
272 {
273  std::string id = "<" + _typeDesc + "> (accepted multiple times)";
274 
275  return id;
276 }
277 
278 template<class T>
280 {
281  if ( _name == a.getName() || _description == a.getDescription() )
282  return true;
283  else
284  return false;
285 }
286 
287 template<class T>
288 void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
289 {
290  argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
291 }
292 
293 }; // namespace ecl
294 
295 #endif
bool _alreadySet
Definition: arg.hpp:101
virtual bool processArg(int *i, std::vector< std::string > &args)
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
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
virtual std::string shortID(const std::string &val="val") const
TCLAP command line argument parser classes.
virtual std::string toString() const
Definition: arg.hpp:493
virtual void add(Arg &a)=0
virtual bool operator==(const Arg &a) const
std::string _name
Definition: arg.hpp:71
virtual std::string longID(const std::string &val="val") const
std::string getDescription() const
Definition: arg.hpp:448
UnlabeledMultiArg(const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
std::string _typeDesc
Definition: multi_arg.hpp:171
virtual void addToList(std::list< Arg * > &argList) const
void _extractValue(const std::string &val)
Definition: multi_arg.hpp:487
bool _hasBlanks(const std::string &s) const
Definition: arg.hpp:535
TCLAP command line argument parser classes.
std::string _description
Definition: arg.hpp:76
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