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 
148  _checkWithVisitor();
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 
164  _checkWithVisitor();
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
SwitchArg(const std::string &flag, const std::string &name, const std::string &desc, bool def=false, Visitor *v=NULL)
Definition: switch_arg.hpp:108
virtual std::string shortID(const std::string &valueId="val") const
Definition: arg.hpp:396
static bool ignoreRest()
std::string shortID(const std::string &val) const
MultiSwitchArg(const std::string &flag, const std::string &name, const std::string &desc, int init=0, Visitor *v=NULL)
virtual bool processArg(int *i, std::vector< std::string > &args)
virtual std::string longID(const std::string &valueId="val") const
Definition: arg.hpp:417
std::string longID(const std::string &val) const


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13