32 std::optional<T>
arg(std::string_view name, std::optional<T> default_value = {}) {
34 if (arg_value.empty()) {
35 return default_value.has_value() ? default_value.value() : T{};
37 std::size_t parsed = 0;
38 if constexpr (std::is_same_v<T, bool> || std::is_same_v<T, int> || std::is_same_v<T, int32_t>) {
39 return std::stoi(arg_value, &parsed);
40 }
else if constexpr (std::is_same_v<T, long long> || std::is_same_v<T, int64_t>) {
41 return std::stoll(arg_value, &parsed);
42 }
else if constexpr (std::is_same_v<T, float>) {
43 return std::stof(arg_value, &parsed);
44 }
else if constexpr (std::is_same_v<T, double>) {
45 return std::stod(arg_value, &parsed);
46 }
else if constexpr (std::is_same_v<T, std::string>) {
49 static_assert(
false,
"This type is not supported!");
Parses command line arguments.
Definition: ArgParser.hpp:17
std::optional< T > arg(std::string_view name, std::optional< T > default_value={})
Get the value of an argument. Supported types: bool, int, long long, float, double,...
Definition: ArgParser.hpp:32
static ArgParser * instance()
Definition: Utils.cpp:78
friend class App
Definition: ArgParser.hpp:18
void initialize(int argc, char **argv)
Initialize the ArgParser with the command line arguments.
Definition: Utils.cpp:83
int m_argc
Definition: ArgParser.hpp:70
char ** m_argv
Definition: ArgParser.hpp:71
std::string get_arg_value(std::string_view arg_name)
Get the string value of an argument.
Definition: Utils.cpp:89