From 6efa314c382e2455f2c25af20bfdeefe0f9fc600 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 9 Sep 2021 11:44:44 +0200 Subject: [PATCH] Util: Move ArgParser private function implementations to the bottom --- src/util/argparser.cpp | 176 ++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 88 deletions(-) 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