forked from Thalhammer/snowman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snowboy-options.h
53 lines (47 loc) · 2.91 KB
/
snowboy-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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vector>
namespace snowboy {
struct OptionsItf {
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, bool* ptr) = 0;
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, int32_t* ptr) = 0;
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, uint32_t* ptr) = 0;
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, int64_t* ptr) = 0;
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, uint64_t* ptr) = 0;
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, float* ptr) = 0;
virtual void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, std::string* ptr) = 0;
virtual void Remove(const std::string& prefix, const std::string& name) = 0;
virtual ~OptionsItf() {}
};
struct OptionInfo;
class ParseOptions : public OptionsItf {
bool m_opt_print_usage;
std::string m_opt_config_file;
std::string m_usage;
std::vector<std::string> m_arguments;
std::map<std::string, OptionInfo> m_options;
int m_verbose_level;
void Register(const std::string& prefix, const std::string& name, const std::string usage_info, OptionInfo&& info);
public:
ParseOptions(const std::string& usage);
~ParseOptions();
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, bool* ptr) override;
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, int32_t* ptr) override;
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, uint32_t* ptr) override;
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, int64_t* ptr) override;
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, uint64_t* ptr) override;
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, float* ptr) override;
void Register(const std::string& prefix, const std::string& name, const std::string& usage_info, std::string* ptr) override;
void Remove(const std::string& prefix, const std::string& name) override;
std::string GetArgument(size_t index) const;
bool IsValidOption(const std::string& opt) const;
std::string NormalizeOptionName(const std::string& option) const;
void ParseOneOption(const std::string& opt, std::string* out_name, std::string* out_value) const;
void PrintUsage(bool);
void ReadArguments(int argc, char const* const* argv);
void ReadConfigFile(const std::string& filename);
void ReadConfigString(const std::string& config);
};
} // namespace snowboy