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>
204 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
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 
215  OptionalUnlabeledTracker::check(req, toString());
216 
217 }
218 
219 template<class T>
220 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
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;
231  OptionalUnlabeledTracker::check(req, toString());
232  parser.add( this );
233 }
234 
238 template<class T>
239 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
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;
249  OptionalUnlabeledTracker::check(req, toString());
250 }
251 
252 template<class T>
253 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
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;
264  OptionalUnlabeledTracker::check(req, toString());
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>
317 bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
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
value_arg.hpp
TCLAP command line argument parser classes.
ecl::UnlabeledValueArg::operator==
virtual bool operator==(const Arg &a) const
Definition: unlabeled_value_arg.hpp:319
ecl::Arg::getName
const std::string & getName() const
Definition: arg.hpp:465
ecl::UnlabeledValueArg::addToList
virtual void addToList(std::list< Arg * > &argList) const
Definition: unlabeled_value_arg.hpp:328
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
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::ValueArg
Definition: value_arg.hpp:36
ecl::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)
Definition: unlabeled_value_arg.hpp:206
ecl::Constraint
Defines the interaction between an argument and a constraint.
Definition: constraint.hpp:36
ecl::UnlabeledValueArg::processArg
virtual bool processArg(int *i, std::vector< std::string > &args)
Definition: unlabeled_value_arg.hpp:274
ecl::UnlabeledValueArg::longID
virtual std::string longID(const std::string &val="val") const
Definition: unlabeled_value_arg.hpp:305
ecl
ecl::UnlabeledValueArg::shortID
virtual std::string shortID(const std::string &val="val") const
Definition: unlabeled_value_arg.hpp:294


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