blob: 1b0fd22ea10396528f022c28579368c99ab82e91 (
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
|
#pragma once
#include <string>
#include <vector>
#include <functional>
class Option
{
friend class OptionSet;
public:
Option(const std::string& str, std::function<void()> func);
Option(const std::string& str, std::function<void(const std::string)> func);
private:
void parse(const std::string& str);
char m_short;
std::string m_long;
int m_has_arg;
std::function<void()> m_void_func;
std::function<void(const std::string)> m_func;
};
class OptionSet
{
public:
OptionSet(std::initializer_list<Option> il);
void parse(int argc, char** argv);
const std::vector<std::string> params() const { return m_params; }
private:
const Option& find_opt(int c);
const std::vector<Option> m_opts;
std::vector<std::string> m_params;
};
|