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 {
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
ecl::MultiSwitchArg::MultiSwitchArg
MultiSwitchArg(const std::string &flag, const std::string &name, const std::string &desc, int init=0, Visitor *v=NULL)
Definition: multi_switch_arg.hpp:114
ecl::Arg::_checkWithVisitor
void _checkWithVisitor() const
Definition: arg.hpp:507
ecl::Arg::shortID
virtual std::string shortID(const std::string &valueId="val") const
Definition: arg.hpp:398
ecl::MultiSwitchArg::longID
std::string longID(const std::string &val) const
Definition: multi_switch_arg.hpp:181
ecl::CmdLineInterface::add
virtual void add(Arg &a)=0
ecl::MultiSwitchArg::getValue
int getValue()
Definition: multi_switch_arg.hpp:135
ecl::Arg::argMatches
virtual bool argMatches(const std::string &s) const
Definition: arg.hpp:486
ecl::SwitchArg
Definition: switch_arg.hpp:33
ecl::MultiSwitchArg::processArg
virtual bool processArg(int *i, std::vector< std::string > &args)
Definition: multi_switch_arg.hpp:137
ecl::Arg::_alreadySet
bool _alreadySet
Definition: arg.hpp:105
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::Arg::ignoreRest
static bool ignoreRest()
Definition: arg.hpp:173
ecl::Arg::longID
virtual std::string longID(const std::string &valueId="val") const
Definition: arg.hpp:419
ecl::Arg::_ignoreable
bool _ignoreable
Definition: arg.hpp:118
switch_arg.hpp
TCLAP command line argument parser classes.
ecl::MultiSwitchArg::_value
int _value
Definition: multi_switch_arg.hpp:40
ecl::MultiSwitchArg::shortID
std::string shortID(const std::string &val) const
Definition: multi_switch_arg.hpp:174
ecl
ecl::SwitchArg::combinedSwitchesMatch
bool combinedSwitchesMatch(std::string &combined)
Definition: switch_arg.hpp:133


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