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