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>
179 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
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;
188  OptionalUnlabeledTracker::check(true, toString());
189 }
190 
191 template<class T>
192 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
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;
202  OptionalUnlabeledTracker::check(true, toString());
203  parser.add( this );
204 }
205 
206 
207 template<class T>
208 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
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;
217  OptionalUnlabeledTracker::check(true, toString());
218 }
219 
220 template<class T>
221 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
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;
231  OptionalUnlabeledTracker::check(true, toString());
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>
279 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
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
ecl::UnlabeledMultiArg::UnlabeledMultiArg
UnlabeledMultiArg(const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
Definition: unlabeled_multi_arg.hpp:181
ecl::Arg::getName
const std::string & getName() const
Definition: arg.hpp:465
ecl::MultiArg
Definition: multi_arg.hpp:36
ecl::UnlabeledMultiArg::longID
virtual std::string longID(const std::string &val="val") const
Definition: unlabeled_multi_arg.hpp:273
ecl::Arg::getDescription
std::string getDescription() const
Definition: arg.hpp:450
ecl::CmdLineInterface::add
virtual void add(Arg &a)=0
ecl::Arg
Virtual parent for all the different argument classes.
Definition: arg.hpp:39
multi_arg.hpp
TCLAP command line argument parser classes.
ecl::UnlabeledMultiArg::operator==
virtual bool operator==(const Arg &a) const
Definition: unlabeled_multi_arg.hpp:281
optional_unlabeled_tracker.hpp
TCLAP command line argument parser classes.
ecl::OptionalUnlabeledTracker::check
static void check(bool req, const std::string &argName)
Definition: optional_unlabeled_tracker.hpp:41
ecl::Visitor
TClap class indirectly used to define the interface for visitors.
Definition: visitor.hpp:27
ecl::CmdLineInterface
Managing interface for The base class that manages the command line definition and passes along the p...
Definition: cmd_line_interface.hpp:38
ecl::UnlabeledMultiArg::addToList
virtual void addToList(std::list< Arg * > &argList) const
Definition: unlabeled_multi_arg.hpp:290
ecl::UnlabeledMultiArg::processArg
virtual bool processArg(int *i, std::vector< std::string > &args)
Definition: unlabeled_multi_arg.hpp:239
ecl::Constraint
Defines the interaction between an argument and a constraint.
Definition: constraint.hpp:36
ecl::UnlabeledMultiArg::shortID
virtual std::string shortID(const std::string &val="val") const
Definition: unlabeled_multi_arg.hpp:265
ecl


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:13