multi_switch_arg.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef TCLAP_MULTI_SWITCH_ARG_H
16 #define TCLAP_MULTI_SWITCH_ARG_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "switch_arg.hpp"
22 
23 namespace ecl {
24 
29 class MultiSwitchArg : public SwitchArg
30 {
31  protected:
32 
36  int _value;
37 
38 
39  public:
40 
54  MultiSwitchArg(const std::string& flag,
55  const std::string& name,
56  const std::string& desc,
57  int init = 0,
58  Visitor* v = NULL);
59 
60 
75  MultiSwitchArg(const std::string& flag,
76  const std::string& name,
77  const std::string& desc,
78  CmdLineInterface& parser,
79  int init = 0,
80  Visitor* v = NULL);
81 
82 
91  virtual bool processArg(int* i, std::vector<std::string>& args);
92 
96  int getValue();
97 
101  std::string shortID(const std::string& val) const;
102 
106  std::string longID(const std::string& val) const;
107 };
108 
110 //BEGIN MultiSwitchArg.cpp
112 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
113  const std::string& name,
114  const std::string& desc,
115  int init,
116  Visitor* v )
117 : SwitchArg(flag, name, desc, false, v),
118 _value( init )
119 { }
120 
121 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
122  const std::string& name,
123  const std::string& desc,
124  CmdLineInterface& parser,
125  int init,
126  Visitor* v )
127 : SwitchArg(flag, name, desc, false, v),
128 _value( init )
129 {
130  parser.add( this );
131 }
132 
133 inline int MultiSwitchArg::getValue() { return _value; }
134 
135 inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
136 {
137  if ( _ignoreable && Arg::ignoreRest() )
138  return false;
139 
140  if ( argMatches( args[*i] ))
141  {
142  // so the isSet() method will work
143  _alreadySet = true;
144 
145  // Matched argument: increment value.
146  ++_value;
147 
149 
150  return true;
151  }
152  else if ( combinedSwitchesMatch( args[*i] ) )
153  {
154  // so the isSet() method will work
155  _alreadySet = true;
156 
157  // Matched argument: increment value.
158  ++_value;
159 
160  // Check for more in argument and increment value.
161  while ( combinedSwitchesMatch( args[*i] ) )
162  ++_value;
163 
165 
166  return false;
167  }
168  else
169  return false;
170 }
171 
172 inline std::string MultiSwitchArg::shortID(const std::string& val) const
173 {
174  std::string id = Arg::shortID() + " ... " + val;
175 
176  return id;
177 }
178 
179 inline std::string MultiSwitchArg::longID(const std::string& val) const
180 {
181  std::string id = Arg::longID() + " (accepted multiple times) " + val;
182 
183  return id;
184 }
185 
187 //END MultiSwitchArg.cpp
189 
190 }; // namespace ecl
191 
192 #endif
virtual bool argMatches(const std::string &s) const
Definition: arg.hpp:484
bool _alreadySet
Definition: arg.hpp:101
static bool ignoreRest()
Definition: arg.hpp:169
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 std::string longID(const std::string &valueId="val") const
Definition: arg.hpp:417
bool _ignoreable
Definition: arg.hpp:114
MultiSwitchArg(const std::string &flag, const std::string &name, const std::string &desc, int init=0, Visitor *v=NULL)
std::string shortID(const std::string &val) const
bool combinedSwitchesMatch(std::string &combined)
Definition: switch_arg.hpp:131
virtual void add(Arg &a)=0
virtual bool processArg(int *i, std::vector< std::string > &args)
virtual std::string shortID(const std::string &valueId="val") const
Definition: arg.hpp:396
void _checkWithVisitor() const
Definition: arg.hpp:505
std::string longID(const std::string &val) const
TCLAP command line argument parser classes.


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:23