1 #pragma once 2 3 #include <string> 4 #include <vector> 5 #include <functional> 6 7 class Option 8 { 9 friend class OptionSet; 10 public: 11 Option(const std::string& str, std::function<void()> func); 12 Option(const std::string& str, std::function<void(const std::string)> func); 13 14 private: 15 void parse(const std::string& str); 16 17 char m_short; 18 std::string m_long; 19 int m_has_arg; 20 std::function<void()> m_void_func; 21 std::function<void(const std::string)> m_func; 22 }; 23 24 class OptionSet 25 { 26 public: 27 OptionSet(std::initializer_list<Option> il); 28 29 void parse(int argc, char** argv); 30 params()31 const std::vector<std::string> params() const { return m_params; } 32 33 private: 34 const Option& find_opt(int c); 35 36 const std::vector<Option> m_opts; 37 std::vector<std::string> m_params; 38 }; 39