11#include <unordered_map>
36 [[nodiscard]]
const char *
what() const noexcept
override {
return m_msg.c_str(); };
44 inline bool isNumeric(
const std::string_view str) {
return !str.empty() && std::ranges::all_of(str, ::isdigit); }
49 {
"width", [](
Config& conf,
const std::string_view arg)
52 throw std::invalid_argument(
"Invalid value for width: " + std::string(arg));
56 {
"height", [](
Config& conf,
const std::string_view arg)
59 throw std::invalid_argument(
"Invalid value for height: " + std::string(arg));
64 {
"vsync", [](
Config& conf, std::string_view arg) { conf.
vsync =
true; } },
65 {
"fov", [](
Config& conf,
const std::string_view arg)
68 throw std::invalid_argument(
"Invalid value for fov: " + std::string(arg));
70 const float value = std::stof(std::string(arg));
71 if (value < 1.0F || value > 300.0F) {
72 throw std::out_of_range(
"Field of view must be between 1 and 300");
76 {
"mspeed", [](
Config& conf,
const std::string_view arg)
79 throw std::invalid_argument(
"Invalid value for move speed: " + std::string(arg));
81 const float value = std::stof(std::string(arg));
82 if (value < 0.1F || value > 100.0F) {
83 throw std::out_of_range(
"Move speed must be between 0.1 and 100.0");
87 {
"lspeed", [](
Config& conf,
const std::string_view arg)
90 throw std::invalid_argument(
"Invalid value for look speed: " + std::string(arg));
92 const float value = std::stof(std::string(arg));
93 if (value < 0.1F || value > 100.0F) {
94 throw std::out_of_range(
"Look speed must be between 0.1 and 100.0");
98 {
"far", [](
Config& conf,
const std::string_view arg)
101 throw std::invalid_argument(
"Invalid value for far: " + std::string(arg));
103 const float value = std::stof(std::string(arg));
104 if (value < 0.1F || value > 100.0F) {
105 throw std::out_of_range(
"Far plane must be between 0.1 and 100.0");
109 {
"near", [](
Config& conf,
const std::string_view arg)
112 throw std::invalid_argument(
"Invalid value for near: " + std::string(arg));
114 const float value = std::stof(std::string(arg));
115 if (value < 0.1F || value > 100.0F) {
116 throw std::out_of_range(
"Near plane must be between 0.1 and 100.0");
125 {
"f", [](
Config& conf) { conf.window.fullscreen =
true; } },
126 {
"V", [](
Config& conf) { conf.vsync =
true; } }
138 Parser(
int argc,
char* argv[],
char* envp[]);
155 void parseArgs(
const std::vector<std::string_view>& argv);
156 void parseEnv(
const std::unordered_map<std::string, std::string>& envp);
158 void handleLongOption(
const std::string_view& arg,
const std::vector<std::string_view>& argv,
size_t& index);
Custom exception class for parsing errors.
ParserException & operator=(const ParserException &)=delete
ParserException(const ParserException &)=delete
ParserException & operator=(ParserException &&)=delete
ParserException(ParserException &&)=delete
const char * what() const noexcept override
ParserException(std::string msg)
~ParserException() override=default
Parser(int argc, char *argv[], char *envp[])
Parser(const Parser &)=delete
static bool isValidOption(const std::string_view &option)
void printArguments() const
Parser & operator=(const Parser &)=delete
Parser & operator=(Parser &&)=delete
void parseEnv(const std::unordered_map< std::string, std::string > &envp)
void handleShortOptions(const std::string_view &arg)
void parseArgs(const std::vector< std::string_view > &argv)
void handleLongOption(const std::string_view &arg, const std::vector< std::string_view > &argv, size_t &index)
static const std::unordered_map< std::string_view, std::function< void(Config &conf, std::string_view arg)> > FUNCTION_MAP_OPT_LONG
constexpr auto VERSION_MESSAGE
bool isNumeric(const std::string_view str)
constexpr auto HELP_MESSAGE
static const std::unordered_map< std::string_view, std::function< void(Config &conf)> > FUNCTION_MAP_OPT_SHORT