summaryrefslogtreecommitdiff
path: root/src/include/argparser.h
blob: 8cbced0c750f0c408cdd2146b2758e1b0fdb6efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 *  @file argparser.h
 *  @brief  Declaration of the argument parser class.
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005
 */

#ifndef ARGPARSER_H_INCLUDED
#define ARGPARSER_H_INCLUDED

#include <map>
#include <string>
#include <vector>

namespace Binc {

  struct ArgOpts {
    std::string c;
    bool b;
    bool o;
    std::string desc;
  };

  class CommandLineArgs {
  public:
    CommandLineArgs();

    bool parse(int argc, char *argv[]);
    std::string errorString() const;

    int argc() const;

    const std::string operator[](const std::string &arg) const;

    void addOptional(const std::string &arg, const std::string &desc, bool boolean);
    void addRequired(const std::string &arg, const std::string &desc, bool boolean);
    bool hasArg(const std::string &arg) const;

    std::string usageString() const;

    void setTail(const std::string &str);

    const std::vector<std::string> &getUnqualifiedArgs() const;

  private:
    void registerArg(const std::string &arg,
                     const std::string &desc,
                     bool boolean,
                     bool optional);

    std::string errString;
    std::map<std::string, ArgOpts> reg;
    std::map<std::string, std::string> args;
    std::map<std::string, bool> passedArgs;
    std::vector<std::string> unqualified;
    std::string tail;
    std::string head;
    int ac;
  };
}

#endif