#ifndef CB_ARGUMENTPARSER_H #define CB_ARGUMENTPARSER_H #include "argument.h" #include #include #include #include #include #include #include #include namespace cb::argparser { using ArgumentMapType = std::unordered_map; class ArgumentMap : public ArgumentMapType { public: Argument &operator[](std::string &&argument_name) { assert(count(argument_name) > 0 && "Argument not found!"); return this->at(argument_name); } }; class ArgumentParser { private: std::vector arguments; std::vector positional_arguments; public: void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description, bool default_value, Mode mode = Mode::OPTIONAL_MODE); void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description, const char *default_value, Mode mode = Mode::OPTIONAL_MODE); void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description, int default_value, Mode mode = Mode::OPTIONAL_MODE); void add_argument(const std::string &short_name, const std::string &name, Type type, std::string description, std::string default_value = "", Mode mode = Mode::OPTIONAL_MODE); ArgumentMap parse(int argc, char *argv[]); private: static void insert_argument(ArgumentMap &parsed_args, ParseArgument &positional_arg, const Argument &argument); ArgumentMap parse_arguments(int argc, char *const *argv); static bool requiresAdditionalArgument(const ParseArgument &parseArgument, int argc, char *const *argv, int i); static void consume_argument(ArgumentMap &parsed_args, ParseArgument &arg, std::string content = "1"); void verify_required_arguments_present() const; static bool matchesArgument(const std::string &text, const ParseArgument &arg); bool argument_exists(const std::string &short_name, const std::string &name); }; } #endif //CB_ARGUMENTPARSER_H