libutil++  1.9.3
 All Classes Functions Variables
CommandLine.h
1 /*
2 ** libutil++
3 ** $Id: CommandLine.h 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__util__CommandLine_H__
10 #define __libutilxx__sella__util__CommandLine_H__
11 
12 #include "../../common.h"
13 
14 #include "CommandLineOption.h"
15 
16 #include <stdio.h>
17 #include <getopt.h>
18 #include <values.h>
19 
20 #include <exception>
21 #include <string>
22 #include <list>
23 #include <map>
24 
25 namespace sella {
26  namespace util {
27  class CommandLine;
28  }
29 }
30 
32  public:
33  CommandLine(int argc, char **argv) throw ();
34 
35  CommandLine(const CommandLine &copy) throw ();
36  virtual ~CommandLine() throw ();
37 
38  public:
39  CommandLine& operator=(const CommandLine &other) throw ();
40 
41  public:
42  void add(char opt, const std::string &option, const std::string &usage, const std::string &label = "", const std::string &value = "") throw ();
43  void add(char opt, const std::string &option, const std::string &usage, const std::string &label, long value, long min = MINLONG, long max = MINLONG) throw ();
44  void add(const CommandLineOption &option = CommandLineOption()) throw ();
45  void add(const std::string &argument, const std::string &usage) throw ();
46 
47  std::map<std::string, std::string> parse(FILE *stream) const throw ();
48  void usage(FILE *stream, int result = 0) const throw ();
49 
50  protected:
51  struct option build(char tag, const std::string &name, bool argument) const throw ();
52  const std::string tag(char tag, bool argument) const throw ();
53 
54  private:
55  int argc;
56  char **argv;
57 
58  std::list<CommandLineOption> option;
59  std::list<std::pair<std::string, std::string>> argument;
60 
61  size_t width;
62 };
63 
64 #endif
65 
66 /*
67 ** vim: noet ts=3 sw=3
68 */