diff --git a/src/util/argparser.cpp b/src/util/argparser.cpp index 7faff02..6e2300b 100644 --- a/src/util/argparser.cpp +++ b/src/util/argparser.cpp @@ -287,94 +287,6 @@ bool ArgParser::parse(int argc, const char* argv[]) // ----------------------------------------- -AcceptFunction ArgParser::getAcceptFunction(bool& value) -{ - return [&value](const char*) -> bool { - value = true; - return true; - }; -} - -AcceptFunction ArgParser::getAcceptFunction(const char*& value) -{ - return [&value](const char* v) -> bool { - value = v; - return true; - }; -} - -AcceptFunction ArgParser::getAcceptFunction(std::string& value) -{ - return [&value](const char* v) -> bool { - value = v; - return true; - }; -} - -AcceptFunction ArgParser::getAcceptFunction(std::string_view& value) -{ - return [&value](const char* v) -> bool { - value = v; - return true; - }; -} - -AcceptFunction ArgParser::getAcceptFunction(int& value) -{ - return [&value](const char* v) -> bool { - try { - value = std::stoi(v); - return true; - } - catch (...) { - return false; - } - }; -} - -AcceptFunction ArgParser::getAcceptFunction(unsigned int& value) -{ - return [&value](const char* v) -> bool { - unsigned long convert = 0; - try { - convert = std::stoul(v); - } - catch (...) { - return false; - } - - if (convert <= std::numeric_limits::max()) { - value = static_cast(convert); - return true; - } - - return false; - }; -} - -AcceptFunction ArgParser::getAcceptFunction(double& value) -{ - return [&value](const char* v) -> bool { - try { - value = std::stod(v); - return true; - } - catch (...) { - return false; - } - }; -} - -AcceptFunction ArgParser::getAcceptFunction(std::vector& value) -{ - return [&value](const char* v) -> bool { - value.push_back(v); - return true; - }; -} - -// ----------------------------------------- - void ArgParser::addOption(Option&& option) { m_options.push_back(option); @@ -475,4 +387,92 @@ void ArgParser::addArgument(std::vector& values, const char* name, addArgument({ name, usageString, manString, minValues, values.max_size(), 0, getAcceptFunction(values) }); } +// ----------------------------------------- + +AcceptFunction ArgParser::getAcceptFunction(bool& value) +{ + return [&value](const char*) -> bool { + value = true; + return true; + }; +} + +AcceptFunction ArgParser::getAcceptFunction(const char*& value) +{ + return [&value](const char* v) -> bool { + value = v; + return true; + }; +} + +AcceptFunction ArgParser::getAcceptFunction(std::string& value) +{ + return [&value](const char* v) -> bool { + value = v; + return true; + }; +} + +AcceptFunction ArgParser::getAcceptFunction(std::string_view& value) +{ + return [&value](const char* v) -> bool { + value = v; + return true; + }; +} + +AcceptFunction ArgParser::getAcceptFunction(int& value) +{ + return [&value](const char* v) -> bool { + try { + value = std::stoi(v); + return true; + } + catch (...) { + return false; + } + }; +} + +AcceptFunction ArgParser::getAcceptFunction(unsigned int& value) +{ + return [&value](const char* v) -> bool { + unsigned long convert = 0; + try { + convert = std::stoul(v); + } + catch (...) { + return false; + } + + if (convert <= std::numeric_limits::max()) { + value = static_cast(convert); + return true; + } + + return false; + }; +} + +AcceptFunction ArgParser::getAcceptFunction(double& value) +{ + return [&value](const char* v) -> bool { + try { + value = std::stod(v); + return true; + } + catch (...) { + return false; + } + }; +} + +AcceptFunction ArgParser::getAcceptFunction(std::vector& value) +{ + return [&value](const char* v) -> bool { + value.push_back(v); + return true; + }; +} + } // namespace Util