#pragma once #include #include #include #include #include #include #include class CLParser { public: CLParser(int argc, char** argv); CLParser(const CLParser& other); [[nodiscard]] bool hasOption(const std::string& option) const; template [[nodiscard]] T getOption(const std::string& option, T defaultValue) const { if (!hasOption(option)) { return defaultValue; } T value = T(); parseString(_options.at(option), ParameterTypeTraits::type, static_cast(&value)); return value; } template [[nodiscard]] std::optional getOption(const std::string& option) const { if (!hasOption(option)) { return std::nullopt; } T value = T(); parseString(_options.at(option), ParameterTypeTraits::type, static_cast(&value)); return value; } [[nodiscard]] bool hasPositionalArgument(int index) const; [[nodiscard]] std::string getPositionalArgument(int index) const; template [[nodiscard]] T getPositionalArgument(int index) const { if (!hasPositionalArgument(index)) { return T(); } T value = T(); parseString(_argv[index], ParameterTypeTraits::type, static_cast(&value)); return value; } [[nodiscard]] int positionalArgumentsCount() const; ~CLParser(); protected: static void parseString(const std::string& str, ParameterType type, void* value) ; private: std::vector _argv; int _argc; std::map _options; };