diff options
Diffstat (limited to 'kms++util/opts.h')
-rw-r--r-- | kms++util/opts.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/kms++util/opts.h b/kms++util/opts.h new file mode 100644 index 0000000..1b0fd22 --- /dev/null +++ b/kms++util/opts.h @@ -0,0 +1,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; +}; |