G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsCmdLine.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 #include <gsIO/gsOptionList.h>
18 
19 namespace gismo
20 {
21 
22 // Forward declaration
23 class gsCmdLinePrivate;
24 
56 class GISMO_EXPORT gsCmdLine : public gsOptionList //TODO: better name: gsCmdOptionList
57 {
58  typedef index_t intVal_t;
59 
60 public:
77  gsCmdLine(const std::string& message,
78  const char delimiter = ' ',
79  bool helpAndVersion = true);
80 
94  void addInt(const std::string& flag,
95  const std::string& name,
96  const std::string& desc,
97  intVal_t & value); //TODO: rename as argInt
98 
100  void addNewInt(const std::string& flag,
101  const std::string& name,
102  const std::string& desc,
103  intVal_t value) //TODO: rename as addInt
104  {
105  gsOptionList::addInt(name, desc, value); //add new option
106  addInt(flag, name, desc, getIntRef(name) ); //bind cmd arg
107  }
108 
109  // Third (inherited) version: add int option which is NOT a
110  // command-line argument
111  using gsOptionList::addInt;
112 
125  void addMultiInt(const std::string & flag,
126  const std::string & name,
127  const std::string & desc,
128  std::vector<intVal_t>& value);
129 
130  //using gsOptionList::addMultiInt;
131 
145  void addReal(const std::string& flag,
146  const std::string& name,
147  const std::string& desc,
148  real_t & value);
149 
150  //using gsOptionList::addReal;
151 
164  void addMultiReal(const std::string & flag,
165  const std::string & name,
166  const std::string & desc,
167  std::vector<real_t>& value);
168 
169  //using gsOptionList::addMultiReal;
170 
184  void addString(const std::string& flag,
185  const std::string& name,
186  const std::string& desc,
187  std::string & value);
188 
189  //using gsOptionList::addString;
190 
203  void addMultiString(const std::string & flag,
204  const std::string & name,
205  const std::string & desc,
206  std::vector<std::string>& value);
207 
208  //using gsOptionList::addMultiString;
209 
224  void addSwitch(const std::string& flag,
225  const std::string& name,
226  const std::string& desc,
227  bool & value);
228 
233  void addSwitch(const std::string& name,
234  const std::string& desc,
235  bool & value)
236  {
237  gsOptionList::addSwitch(name, desc, value); //add new option
238  addSwitch("",name,desc,value);
239  }
240 
251  void addPlainString(const std::string& name,
252  const std::string& desc,
253  std::string & value);
254 
265  void getValues(int argc, char *argv[]);
266 
268  static void printVersion();
269 
271  std::string& getMessage();
272 
277  bool valid(int argc, char *argv[]) const;
278 
280  void setExceptionHandling(const bool state);
281 
283  bool getExceptionHandling() const;
284 
285  // Destructor
286  ~gsCmdLine();
287 
288 private:
292  void updateOptionList();
293 
294 private:
295 
296  gsCmdLinePrivate * my;
297 
298 }; // class gsCmdLine
299 
300 #ifdef GISMO_WITH_PYBIND11
301 
305  void pybind11_init_gsCmdLine(pybind11::module &m);
306 
307 #endif // GISMO_WITH_PYBIND11
308 
309 namespace internal
310 {
311 
312 template<>
313 class GISMO_EXPORT gsXml<gsCmdLine> : public gsXml<gsOptionList> { };
314 
315 }
316 
317 } // namespace gismo
void addNewInt(const std::string &flag, const std::string &name, const std::string &desc, intVal_t value)
Second version: unbinded integer command-line argument.
Definition: gsCmdLine.h:100
#define index_t
Definition: gsConfig.h:32
Class for command-line argument parsing.
Definition: gsCmdLine.h:56
void addInt(const std::string &label, const std::string &desc, const index_t &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:201
Provides a list of labeled parameters/options that can be set and accessed easily.
Provides forward declarations of types and structs.
void addSwitch(const std::string &name, const std::string &desc, bool &value)
Register a switch option for the command line without flag.
Definition: gsCmdLine.h:233
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
void addSwitch(const std::string &label, const std::string &desc, const bool &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:235