1 // See LICENSE for license details. 2 3 #ifndef _OPTION_PARSER_H 4 #define _OPTION_PARSER_H 5 6 #include <vector> 7 #include <functional> 8 9 class option_parser_t 10 { 11 public: option_parser_t()12 option_parser_t() : helpmsg(0) {} help(void (* helpm)(void))13 void help(void (*helpm)(void)) { helpmsg = helpm; } 14 void option(char c, const char* s, int arg, std::function<void(const char*)> action); 15 const char* const* parse(const char* const* argv0); 16 private: 17 struct option_t 18 { 19 char chr; 20 const char* str; 21 int arg; 22 std::function<void(const char*)> func; option_toption_t23 option_t(char chr, const char* str, int arg, std::function<void(const char*)> func) 24 : chr(chr), str(str), arg(arg), func(func) {} 25 }; 26 std::vector<option_t> opts; 27 void (*helpmsg)(void); 28 void error(const char* msg, const char* argv0, const char* arg); 29 }; 30 31 #endif 32