blob: 68e6bd874766e46548549e165111cb0c36079607 (
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
|
/*
* (C) 2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#ifndef BOTAN_CHECK_GETOPT_H__
#define BOTAN_CHECK_GETOPT_H__
#include <string>
#include <vector>
#include <map>
class OptionParser
{
public:
std::vector<std::string> leftovers() const { return leftover; }
bool is_set(const std::string&) const;
std::string value(const std::string&) const;
std::string value_if_set(const std::string&) const;
void parse(char*[]);
OptionParser(const std::string&);
private:
class OptionFlag
{
public:
std::string name() const { return opt_name; }
bool takes_arg() const { return opt_takes_arg; }
OptionFlag(const std::string& opt_string)
{
std::string::size_type mark = opt_string.find('=');
opt_name = opt_string.substr(0, mark);
opt_takes_arg = (mark != std::string::npos);
}
private:
std::string opt_name;
bool opt_takes_arg;
};
OptionFlag find_option(const std::string&) const;
std::vector<OptionFlag> flags;
std::map<std::string, std::string> options;
std::vector<std::string> leftover;
};
#endif
|