STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmdline.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/common/cmdline.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2013 Timo Bingmann <[email protected]>
7  *
8  * Distributed under the Boost Software License, Version 1.0.
9  * (See accompanying file LICENSE_1_0.txt or copy at
10  * http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #ifndef STXXL_COMMON_CMDLINE_HEADER
14 #define STXXL_COMMON_CMDLINE_HEADER
15 
16 #include <cstddef>
17 #include <cstdio>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 
24 #include <stxxl/bits/namespace.h>
25 #include <stxxl/bits/noncopyable.h>
26 
28 
29 /**
30  * \brief Command line parser which automatically fills variables and prints
31  * nice usage messages.
32  *
33  * This is a straightforward command line parser in C++, which will recognize
34  * short options -s, long options --long and parameters, both required and
35  * optional. It will automatically parse integers and <b>byte sizes</b> with
36  * SI/IEC suffixes (e.g. 1 GiB). It also works with lists of strings,
37  * e.g. multiple filenames.
38  *
39  * Maybe most important it will nicely format the options and parameters
40  * description using word wrapping.
41  */
42 class cmdline_parser : private noncopyable
43 {
44 protected:
45  //! base class of all options and parameters
46  struct argument
47  {
48  //! single letter short option, or 0 is none
49  char m_key;
50  //! long option key or name for parameters
51  std::string m_longkey;
52  //! option type description, e.g. "<#>" to indicate numbers
53  std::string m_keytype;
54  //! longer description, which will be wrapped
55  std::string m_desc;
56  //! required, process() fails if the option/parameter is not found.
57  bool m_required;
58  //! found during processing of command line
59  bool m_found;
60  //! repeated argument, i.e. std::vector<std::string>
61  bool m_repeated;
62 
63  //! contructor filling most attributes
64  argument(char key, const std::string& longkey, const std::string& keytype,
65  const std::string& desc, bool required)
66  : m_key(key), m_longkey(longkey), m_keytype(keytype),
67  m_desc(desc), m_required(required), m_found(false), m_repeated(false)
68  { }
69 
70  //! empty virtual destructor
71  virtual ~argument() { }
72 
73  //! return formatted type name to user
74  virtual const char * type_name() const = 0;
75 
76  //! process one item from command line for this argument
77  virtual bool process(int& argc, const char* const*& argv) = 0;
78 
79  //! format value to ostream
80  virtual void print_value(std::ostream& os) const = 0;
81 
82  //! return 'longkey [keytype]'
83  std::string param_text() const
84  {
85  std::string s = m_longkey;
86  if (m_keytype.size()) {
87  s += ' ' + m_keytype;
88  }
89  return s;
90  }
91 
92  //! return '-s, --longkey [keytype]'
93  std::string option_text() const
94  {
95  std::string s;
96  if (m_key) {
97  s += '-';
98  s += m_key;
99  s += ", ";
100  }
101  s += "--";
102  s += m_longkey;
103  if (m_keytype.size()) {
104  s += ' ' + m_keytype;
105  }
106  return s;
107  }
108  };
109 
110  //! specialization of argument for boolean flags (can only be set to true).
111  struct argument_flag : public argument
112  {
113  //! reference to boolean to set to true
114  bool& m_dest;
115 
116  //! contructor filling most attributes
117  argument_flag(char key, const std::string& longkey, const std::string& keytype,
118  const std::string& desc, bool required, bool& dest)
119  : argument(key, longkey, keytype, desc, required),
120  m_dest(dest)
121  { }
122 
123  virtual const char * type_name() const
124  { return "flag"; }
125 
126  //! "process" argument: just set to true, no argument is used.
127  virtual bool process(int&, const char* const*&)
128  {
129  m_dest = true;
130  return true;
131  }
132 
133  virtual void print_value(std::ostream& os) const
134  { os << (m_dest ? "true" : "false"); }
135  };
136 
137  //! specialization of argument for integer options or parameters
138  struct argument_int : public argument
139  {
140  int& m_dest;
141 
142  //! contructor filling most attributes
143  argument_int(char key, const std::string& longkey, const std::string& keytype,
144  const std::string& desc, bool required, int& dest)
145  : argument(key, longkey, keytype, desc, required),
146  m_dest(dest)
147  { }
148 
149  virtual const char * type_name() const
150  { return "integer"; }
151 
152  //! parse signed integer using sscanf.
153  virtual bool process(int& argc, const char* const*& argv)
154  {
155  if (argc == 0) return false;
156  if (sscanf(argv[0], "%d", &m_dest) == 1) {
157  --argc, ++argv;
158  return true;
159  } else {
160  return false;
161  }
162  }
163 
164  virtual void print_value(std::ostream& os) const
165  { os << m_dest; }
166  };
167 
168  //! specialization of argument for unsigned integer options or parameters
169  struct argument_uint : public argument
170  {
171  unsigned int& m_dest;
172 
173  //! contructor filling most attributes
174  argument_uint(char key, const std::string& longkey, const std::string& keytype,
175  const std::string& desc, bool required, unsigned int& dest)
176  : argument(key, longkey, keytype, desc, required),
177  m_dest(dest)
178  { }
179 
180  virtual const char * type_name() const
181  { return "unsigned integer"; }
182 
183  //! parse unsigned integer using sscanf.
184  virtual bool process(int& argc, const char* const*& argv)
185  {
186  if (argc == 0) return false;
187  if (sscanf(argv[0], "%u", &m_dest) == 1) {
188  --argc, ++argv;
189  return true;
190  } else {
191  return false;
192  }
193  }
194 
195  virtual void print_value(std::ostream& os) const
196  { os << m_dest; }
197  };
198 
199  //! specialization of argument for SI/IEC suffixes byte size options or parameters
200  struct argument_bytes : public argument
201  {
203 
204  //! contructor filling most attributes
205  argument_bytes(char key, const std::string& longkey, const std::string& keytype,
206  const std::string& desc, bool required, uint64& dest)
207  : argument(key, longkey, keytype, desc, required),
208  m_dest(dest)
209  { }
210 
211  virtual const char * type_name() const
212  { return "bytes"; }
213 
214  //! parse byte size using SI/IEC parser from stxxl.
215  virtual bool process(int& argc, const char* const*& argv)
216  {
217  if (argc == 0) return false;
218  if (parse_SI_IEC_size(argv[0], m_dest)) {
219  --argc, ++argv;
220  return true;
221  } else {
222  return false;
223  }
224  }
225 
226  virtual void print_value(std::ostream& os) const
227  { os << m_dest; }
228  };
229 
230  //! specialization of argument for string options or parameters
231  struct argument_string : public argument
232  {
233  std::string& m_dest;
234 
235  //! contructor filling most attributes
236  argument_string(char key, const std::string& longkey, const std::string& keytype,
237  const std::string& desc, bool required, std::string& dest)
238  : argument(key, longkey, keytype, desc, required),
239  m_dest(dest)
240  { }
241 
242  virtual const char * type_name() const
243  { return "string"; }
244 
245  //! "process" string argument just by storing it.
246  virtual bool process(int& argc, const char* const*& argv)
247  {
248  if (argc == 0) return false;
249  m_dest = argv[0];
250  --argc, ++argv;
251  return true;
252  }
253 
254  virtual void print_value(std::ostream& os) const
255  { os << '"' << m_dest << '"'; }
256  };
257 
258  //! specialization of argument for multiple string options or parameters
260  {
261  std::vector<std::string>& m_dest;
262 
263  //! contructor filling most attributes
264  argument_stringlist(char key, const std::string& longkey, const std::string& keytype,
265  const std::string& desc, bool required, std::vector<std::string>& dest)
266  : argument(key, longkey, keytype, desc, required),
267  m_dest(dest)
268  {
269  m_repeated = true;
270  }
271 
272  virtual const char * type_name() const
273  { return "string list"; }
274 
275  //! "process" string argument just by storing it in vector.
276  virtual bool process(int& argc, const char* const*& argv)
277  {
278  if (argc == 0) return false;
279  m_dest.push_back(argv[0]);
280  --argc, ++argv;
281  return true;
282  }
283 
284  virtual void print_value(std::ostream& os) const
285  {
286  os << '[';
287  for (size_t i = 0; i < m_dest.size(); ++i)
288  {
289  if (i != 0) os << ',';
290  os << '"' << m_dest[i] << '"';
291  }
292  os << ']';
293  }
294  };
295 
296 protected:
297  //! option and parameter list type
298  typedef std::vector<argument*> arglist_type;
299 
300  //! list of options available
302  //! list of parameters, both required and optional
304 
305  //! formatting width for options, '-s, --switch <#>'
307  //! formatting width for parameters, 'param <#>'
309 
310  //! argv[0] for usage.
311  const char* m_progname;
312 
313  //! verbose processing of arguments
315 
316  //! user set description of program, will be wrapped
317  std::string m_description;
318  //! user set author of program, will be wrapped
319  std::string m_author;
320 
321  //! set line wrap length
322  unsigned int m_linewrap;
323 
324  //! maximum length of a type_name() result
325  static const int m_maxtypename = 16;
326 
327 private:
328  //! update maximum formatting width for new option
329  void calc_opt_max(const argument* arg)
330  {
331  m_opt_maxlong = STXXL_MAX(arg->option_text().size() + 2, m_opt_maxlong);
332  }
333 
334  //! update maximum formatting width for new parameter
335  void calc_param_max(const argument* arg)
336  {
337  m_param_maxlong = STXXL_MAX(arg->param_text().size() + 2, m_param_maxlong);
338  }
339 
340 public:
341  //! Wrap a long string at spaces into lines. Prefix is added
342  //! unconditionally to each line. Lines are wrapped after wraplen
343  //! characters if possible.
344  static void
345  output_wrap(std::ostream& os, const std::string& text, size_t wraplen,
346  size_t indent_first = 0, size_t indent_rest = 0,
347  size_t current = 0, size_t indent_newline = 0);
348 
349 public:
350  //! Construct new command line parser
352  : m_opt_maxlong(8),
353  m_param_maxlong(8),
354  m_progname(NULL),
355  m_verbose_process(true),
356  m_linewrap(80)
357  { }
358 
359  //! Delete all added arguments
361  {
362  for (size_t i = 0; i < m_optlist.size(); ++i)
363  delete m_optlist[i];
364  m_optlist.clear();
365 
366  for (size_t i = 0; i < m_paramlist.size(); ++i)
367  delete m_paramlist[i];
368  m_paramlist.clear();
369  }
370 
371  //! Set description of program, text will be wrapped
372  void set_description(const std::string& description)
373  {
374  m_description = description;
375  }
376 
377  //! Set author of program, will be wrapped.
378  void set_author(const std::string& author)
379  {
380  m_author = author;
381  }
382 
383  //! Set verbose processing of command line arguments
384  void set_verbose_process(bool verbose_process)
385  {
386  m_verbose_process = verbose_process;
387  }
388 
389  // ************************************************************************
390 
391  //! add boolean option flag -key, --longkey [keytype] with description and store to dest
392  void add_flag(char key, const std::string& longkey, const std::string& keytype, const std::string& desc, bool& dest)
393  {
394  m_optlist.push_back(
395  new argument_flag(key, longkey, keytype, desc, false, dest)
396  );
397  calc_opt_max(m_optlist.back());
398  }
399 
400  //! add signed integer option -key, --longkey [keytype] with description and store to dest
401  void add_int(char key, const std::string& longkey, const std::string& keytype, const std::string& desc, int& dest)
402  {
403  m_optlist.push_back(
404  new argument_int(key, longkey, keytype, desc, false, dest)
405  );
406  calc_opt_max(m_optlist.back());
407  }
408 
409  //! add unsigned integer option -key, --longkey [keytype] with description and store to dest
410  void add_uint(char key, const std::string& longkey, const std::string& keytype, const std::string& desc, unsigned int& dest)
411  {
412  m_optlist.push_back(
413  new argument_uint(key, longkey, keytype, desc, false, dest)
414  );
415  calc_opt_max(m_optlist.back());
416  }
417 
418  //! add SI/IEC suffixes byte size option -key, --longkey [keytype] and store to 64-bit dest
419  void add_bytes(char key, const std::string& longkey, const std::string& keytype, const std::string& desc, stxxl::uint64& dest)
420  {
421  m_optlist.push_back(
422  new argument_bytes(key, longkey, keytype, desc, false, dest)
423  );
424  calc_opt_max(m_optlist.back());
425  }
426 
427  //! add string option -key, --longkey [keytype] and store to dest
428  void add_string(char key, const std::string& longkey, const std::string& keytype, const std::string& desc, std::string& dest)
429  {
430  m_optlist.push_back(
431  new argument_string(key, longkey, keytype, desc, false, dest)
432  );
433  calc_opt_max(m_optlist.back());
434  }
435 
436  //! add string list option -key, --longkey [keytype] and store to dest
437  void add_stringlist(char key, const std::string& longkey, const std::string& keytype, const std::string& desc, std::vector<std::string>& dest)
438  {
439  m_optlist.push_back(
440  new argument_stringlist(key, longkey, keytype, desc, false, dest)
441  );
442  calc_opt_max(m_optlist.back());
443  }
444 
445  //! add boolean option flag -key, --longkey with description and store to dest
446  void add_flag(char key, const std::string& longkey, const std::string& desc, bool& dest)
447  { return add_flag(key, longkey, "", desc, dest); }
448 
449  //! add signed integer option -key, --longkey with description and store to dest
450  void add_int(char key, const std::string& longkey, const std::string& desc, int& dest)
451  { return add_int(key, longkey, "", desc, dest); }
452 
453  //! add unsigned integer option -key, --longkey [keytype] with description and store to dest
454  void add_uint(char key, const std::string& longkey, const std::string& desc, unsigned int& dest)
455  { return add_uint(key, longkey, "", desc, dest); }
456 
457  //! add SI/IEC suffixes byte size option -key, --longkey [keytype] and store to 64-bit dest
458  void add_bytes(char key, const std::string& longkey, const std::string& desc, stxxl::uint64& dest)
459  { return add_bytes(key, longkey, "", desc, dest); }
460 
461  //! add string option -key, --longkey [keytype] and store to dest
462  void add_string(char key, const std::string& longkey, const std::string& desc, std::string& dest)
463  { return add_string(key, longkey, "", desc, dest); }
464 
465  //! add string list option -key, --longkey [keytype] and store to dest
466  void add_stringlist(char key, const std::string& longkey, const std::string& desc, std::vector<std::string>& dest)
467  { return add_stringlist(key, longkey, "", desc, dest); }
468 
469  // ************************************************************************
470 
471  //! add signed integer parameter [name] with description and store to dest
472  void add_param_int(const std::string& name, const std::string& desc, int& dest)
473  {
474  m_paramlist.push_back(
475  new argument_int(0, name, "", desc, true, dest)
476  );
477  calc_param_max(m_paramlist.back());
478  }
479 
480  //! add unsigned integer parameter [name] with description and store to dest
481  void add_param_uint(const std::string& name, const std::string& desc, unsigned int& dest)
482  {
483  m_paramlist.push_back(
484  new argument_uint(0, name, "", desc, true, dest)
485  );
486  calc_param_max(m_paramlist.back());
487  }
488 
489  //! add SI/IEC suffixes byte size parameter [name] with description and store to dest
490  void add_param_bytes(const std::string& name, const std::string& desc, uint64& dest)
491  {
492  m_paramlist.push_back(
493  new argument_bytes(0, name, "", desc, true, dest)
494  );
495  calc_param_max(m_paramlist.back());
496  }
497 
498  //! add string parameter [name] with description and store to dest
499  void add_param_string(const std::string& name, const std::string& desc, std::string& dest)
500  {
501  m_paramlist.push_back(
502  new argument_string(0, name, "", desc, true, dest)
503  );
504  calc_param_max(m_paramlist.back());
505  }
506 
507  //! add string list parameter [name] with description and store to dest.
508  //! \warning this parameter must be last, as it will gobble all non-option arguments!
509  void add_param_stringlist(const std::string& name, const std::string& desc, std::vector<std::string>& dest)
510  {
511  m_paramlist.push_back(
512  new argument_stringlist(0, name, "", desc, true, dest)
513  );
514  calc_param_max(m_paramlist.back());
515  }
516 
517  // ************************************************************************
518 
519  //! add optional signed integer parameter [name] with description and store to dest
520  void add_opt_param_int(const std::string& name, const std::string& desc, int& dest)
521  {
522  m_paramlist.push_back(
523  new argument_int(0, name, "", desc, false, dest)
524  );
525  calc_param_max(m_paramlist.back());
526  }
527 
528  //! add optional unsigned integer parameter [name] with description and store to dest
529  void add_opt_param_uint(const std::string& name, const std::string& desc, unsigned int& dest)
530  {
531  m_paramlist.push_back(
532  new argument_uint(0, name, "", desc, false, dest)
533  );
534  calc_param_max(m_paramlist.back());
535  }
536 
537  //! add optional SI/IEC suffixes byte size parameter [name] with description and store to dest
538  void add_opt_param_bytes(const std::string& name, const std::string& desc, uint64& dest)
539  {
540  m_paramlist.push_back(
541  new argument_bytes(0, name, "", desc, false, dest)
542  );
543  calc_param_max(m_paramlist.back());
544  }
545 
546  //! add optional string parameter [name] with description and store to dest
547  void add_opt_param_string(const std::string& name, const std::string& desc, std::string& dest)
548  {
549  m_paramlist.push_back(
550  new argument_string(0, name, "", desc, false, dest)
551  );
552  calc_param_max(m_paramlist.back());
553  }
554 
555  //! add optional string parameter [name] with description and store to dest
556  //! \warning this parameter must be last, as it will gobble all non-option arguments!
557  void add_opt_param_stringlist(const std::string& name, const std::string& desc, std::vector<std::string>& dest)
558  {
559  m_paramlist.push_back(
560  new argument_stringlist(0, name, "", desc, false, dest)
561  );
562  calc_param_max(m_paramlist.back());
563  }
564 
565  // ************************************************************************
566 
567  //! output nicely formatted usage information including description of all
568  //! parameters and options.
569  void print_usage(std::ostream& os = std::cout);
570 
571 private:
572  //! print error about option.
573  void print_option_error(int argc, const char* const* argv, const argument* arg,
574  std::ostream& os);
575 
576  //! print error about parameter.
577  void print_param_error(int argc, const char* const* argv, const argument* arg,
578  std::ostream& os);
579 
580 public:
581  //! parse command line options as specified by the options and parameters added.
582  //! \return true if command line is okay and all required parameters are present.
583  bool process(int argc, const char* const* argv, std::ostream& os = std::cout);
584 
585  //! print nicely formatted result of processing
586  void print_result(std::ostream& os = std::cout);
587 };
588 
590 
591 #endif // !STXXL_COMMON_CMDLINE_HEADER
size_t m_opt_maxlong
formatting width for options, &#39;-s, –switch &lt;#&gt;&#39;
Definition: cmdline.h:306
bool m_required
required, process() fails if the option/parameter is not found.
Definition: cmdline.h:57
virtual const char * type_name() const
return formatted type name to user
Definition: cmdline.h:242
std::string m_longkey
long option key or name for parameters
Definition: cmdline.h:51
std::string m_description
user set description of program, will be wrapped
Definition: cmdline.h:317
void add_opt_param_stringlist(const std::string &name, const std::string &desc, std::vector< std::string > &dest)
add optional string parameter [name] with description and store to dest
Definition: cmdline.h:557
const char * m_progname
argv[0] for usage.
Definition: cmdline.h:311
argument_flag(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, bool &dest)
contructor filling most attributes
Definition: cmdline.h:117
argument(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required)
contructor filling most attributes
Definition: cmdline.h:64
virtual const char * type_name() const
return formatted type name to user
Definition: cmdline.h:149
unsigned long long int uint64
Definition: types.h:41
void add_param_bytes(const std::string &name, const std::string &desc, uint64 &dest)
add SI/IEC suffixes byte size parameter [name] with description and store to dest ...
Definition: cmdline.h:490
std::vector< std::string > & m_dest
Definition: cmdline.h:261
virtual void print_value(std::ostream &os) const
format value to ostream
Definition: cmdline.h:254
virtual void print_value(std::ostream &os) const
format value to ostream
Definition: cmdline.h:133
void add_bytes(char key, const std::string &longkey, const std::string &desc, stxxl::uint64 &dest)
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest ...
Definition: cmdline.h:458
virtual const char * type_name() const
return formatted type name to user
Definition: cmdline.h:211
void add_param_string(const std::string &name, const std::string &desc, std::string &dest)
add string parameter [name] with description and store to dest
Definition: cmdline.h:499
argument_string(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, std::string &dest)
contructor filling most attributes
Definition: cmdline.h:236
void set_verbose_process(bool verbose_process)
Set verbose processing of command line arguments.
Definition: cmdline.h:384
void add_flag(char key, const std::string &longkey, const std::string &desc, bool &dest)
add boolean option flag -key, –longkey with description and store to dest
Definition: cmdline.h:446
void add_opt_param_string(const std::string &name, const std::string &desc, std::string &dest)
add optional string parameter [name] with description and store to dest
Definition: cmdline.h:547
cmdline_parser()
Construct new command line parser.
Definition: cmdline.h:351
arglist_type m_optlist
list of options available
Definition: cmdline.h:301
virtual bool process(int &argc, const char *const *&argv)
parse signed integer using sscanf.
Definition: cmdline.h:153
virtual void print_value(std::ostream &os) const
format value to ostream
Definition: cmdline.h:284
void calc_param_max(const argument *arg)
update maximum formatting width for new parameter
Definition: cmdline.h:335
virtual ~argument()
empty virtual destructor
Definition: cmdline.h:71
Command line parser which automatically fills variables and prints nice usage messages.
Definition: cmdline.h:42
base class of all options and parameters
Definition: cmdline.h:46
void set_author(const std::string &author)
Set author of program, will be wrapped.
Definition: cmdline.h:378
void add_param_stringlist(const std::string &name, const std::string &desc, std::vector< std::string > &dest)
add string list parameter [name] with description and store to dest.
Definition: cmdline.h:509
std::string m_keytype
option type description, e.g. &quot;&lt;#&gt;&quot; to indicate numbers
Definition: cmdline.h:53
void add_param_uint(const std::string &name, const std::string &desc, unsigned int &dest)
add unsigned integer parameter [name] with description and store to dest
Definition: cmdline.h:481
void set_description(const std::string &description)
Set description of program, text will be wrapped.
Definition: cmdline.h:372
void add_opt_param_uint(const std::string &name, const std::string &desc, unsigned int &dest)
add optional unsigned integer parameter [name] with description and store to dest ...
Definition: cmdline.h:529
unsigned int m_linewrap
set line wrap length
Definition: cmdline.h:322
virtual bool process(int &argc, const char *const *&argv)
&quot;process&quot; string argument just by storing it in vector.
Definition: cmdline.h:276
void add_param_int(const std::string &name, const std::string &desc, int &dest)
add signed integer parameter [name] with description and store to dest
Definition: cmdline.h:472
virtual void print_value(std::ostream &os) const
format value to ostream
Definition: cmdline.h:195
specialization of argument for string options or parameters
Definition: cmdline.h:231
std::string option_text() const
return &#39;-s, –longkey [keytype]&#39;
Definition: cmdline.h:93
virtual const char * type_name() const
return formatted type name to user
Definition: cmdline.h:123
void add_int(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, int &dest)
add signed integer option -key, –longkey [keytype] with description and store to dest ...
Definition: cmdline.h:401
void add_opt_param_bytes(const std::string &name, const std::string &desc, uint64 &dest)
add optional SI/IEC suffixes byte size parameter [name] with description and store to dest ...
Definition: cmdline.h:538
const Tp & STXXL_MAX(const Tp &a, const Tp &b)
Definition: utils.h:154
std::vector< argument * > arglist_type
option and parameter list type
Definition: cmdline.h:298
void add_uint(char key, const std::string &longkey, const std::string &desc, unsigned int &dest)
add unsigned integer option -key, –longkey [keytype] with description and store to dest ...
Definition: cmdline.h:454
argument_int(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, int &dest)
contructor filling most attributes
Definition: cmdline.h:143
bool m_found
found during processing of command line
Definition: cmdline.h:59
void add_uint(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, unsigned int &dest)
add unsigned integer option -key, –longkey [keytype] with description and store to dest ...
Definition: cmdline.h:410
bool m_repeated
repeated argument, i.e. std::vector&lt;std::string&gt;
Definition: cmdline.h:61
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
void add_string(char key, const std::string &longkey, const std::string &desc, std::string &dest)
add string option -key, –longkey [keytype] and store to dest
Definition: cmdline.h:462
std::string m_author
user set author of program, will be wrapped
Definition: cmdline.h:319
virtual void print_value(std::ostream &os) const
format value to ostream
Definition: cmdline.h:164
std::string param_text() const
return &#39;longkey [keytype]&#39;
Definition: cmdline.h:83
bool parse_SI_IEC_size(const std::string &str, uint64 &size, char def_unit=0)
Parse a string like &quot;343KB&quot; or &quot;44 GiB&quot; into the corresponding size in bytes. Returns the number of b...
Definition: utils.cpp:24
void add_bytes(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, stxxl::uint64 &dest)
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest ...
Definition: cmdline.h:419
virtual void print_value(std::ostream &os) const
format value to ostream
Definition: cmdline.h:226
std::string m_desc
longer description, which will be wrapped
Definition: cmdline.h:55
size_t m_param_maxlong
formatting width for parameters, &#39;param &lt;#&gt;&#39;
Definition: cmdline.h:308
virtual const char * type_name() const
return formatted type name to user
Definition: cmdline.h:180
virtual bool process(int &argc, const char *const *&argv)
parse byte size using SI/IEC parser from stxxl.
Definition: cmdline.h:215
void add_flag(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool &dest)
add boolean option flag -key, –longkey [keytype] with description and store to dest ...
Definition: cmdline.h:392
virtual bool process(int &, const char *const *&)
&quot;process&quot; argument: just set to true, no argument is used.
Definition: cmdline.h:127
void add_int(char key, const std::string &longkey, const std::string &desc, int &dest)
add signed integer option -key, –longkey with description and store to dest
Definition: cmdline.h:450
virtual bool process(int &argc, const char *const *&argv)
&quot;process&quot; string argument just by storing it.
Definition: cmdline.h:246
bool & m_dest
reference to boolean to set to true
Definition: cmdline.h:114
char m_key
single letter short option, or 0 is none
Definition: cmdline.h:49
specialization of argument for unsigned integer options or parameters
Definition: cmdline.h:169
specialization of argument for integer options or parameters
Definition: cmdline.h:138
void add_string(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, std::string &dest)
add string option -key, –longkey [keytype] and store to dest
Definition: cmdline.h:428
void add_stringlist(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, std::vector< std::string > &dest)
add string list option -key, –longkey [keytype] and store to dest
Definition: cmdline.h:437
argument_uint(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, unsigned int &dest)
contructor filling most attributes
Definition: cmdline.h:174
specialization of argument for multiple string options or parameters
Definition: cmdline.h:259
arglist_type m_paramlist
list of parameters, both required and optional
Definition: cmdline.h:303
void calc_opt_max(const argument *arg)
update maximum formatting width for new option
Definition: cmdline.h:329
void add_stringlist(char key, const std::string &longkey, const std::string &desc, std::vector< std::string > &dest)
add string list option -key, –longkey [keytype] and store to dest
Definition: cmdline.h:466
argument_bytes(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, uint64 &dest)
contructor filling most attributes
Definition: cmdline.h:205
virtual bool process(int &argc, const char *const *&argv)
parse unsigned integer using sscanf.
Definition: cmdline.h:184
argument_stringlist(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, std::vector< std::string > &dest)
contructor filling most attributes
Definition: cmdline.h:264
specialization of argument for SI/IEC suffixes byte size options or parameters
Definition: cmdline.h:200
bool m_verbose_process
verbose processing of arguments
Definition: cmdline.h:314
specialization of argument for boolean flags (can only be set to true).
Definition: cmdline.h:111
virtual const char * type_name() const
return formatted type name to user
Definition: cmdline.h:272
void add_opt_param_int(const std::string &name, const std::string &desc, int &dest)
add optional signed integer parameter [name] with description and store to dest
Definition: cmdline.h:520
#define STXXL_END_NAMESPACE
Definition: namespace.h:17
~cmdline_parser()
Delete all added arguments.
Definition: cmdline.h:360