-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoptions.h
37 lines (29 loc) · 865 Bytes
/
options.h
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
#ifndef _OPTIONS_H
#define _OPTIONS_H
#include <string>
#include <map>
#include <type_traits>
class OptionManager {
public:
static OptionManager* get(int argc, char *argv[]);
std::string progName() const { return _progName; }
template<typename T>
T value(std::string opt);
private:
static OptionManager* _instance;
std::string _progName;
std::map<std::string, std::string> _opts;
OptionManager();
void parse(int argc, char *argv[]);
void usage();
int _value_helper(std::string, int);
bool _value_helper(std::string, bool);
float _value_helper(std::string, float);
std::string _value_helper(std::string, std::string);
};
template<typename T>
T OptionManager::value(std::string opt)
{
return _value_helper(_opts[opt], T {});
}
#endif