From 4e30b583059087e54c5d6d36af158cdf581ede8f Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 9 Sep 2021 11:40:13 +0200 Subject: [PATCH] Util: Switch ArgParser option/argument creation to list initialization --- src/util/argparser.cpp | 176 ++++------------------------------------- 1 file changed, 16 insertions(+), 160 deletions(-) diff --git a/src/util/argparser.cpp b/src/util/argparser.cpp index 586e301..7faff02 100644 --- a/src/util/argparser.cpp +++ b/src/util/argparser.cpp @@ -382,114 +382,42 @@ void ArgParser::addOption(Option&& option) void ArgParser::addOption(bool& value, char shortName, const char* longName, const char* usageString, const char* manString) { - Option option { - shortName, - longName, - nullptr, - usageString, - manString, - Required::No, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, nullptr, usageString, manString, Required::No, getAcceptFunction(value) }); } void ArgParser::addOption(const char*& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) }); } void ArgParser::addOption(std::string& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) }); } void ArgParser::addOption(std::string_view& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) }); } void ArgParser::addOption(int& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) }); } void ArgParser::addOption(unsigned int& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) }); } void ArgParser::addOption(double& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(value), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) }); } void ArgParser::addOption(std::vector& values, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) { - Option option { - shortName, - longName, - argumentName, - usageString, - manString, - requiresArgument, - getAcceptFunction(values), - }; - addOption(std::move(option)); + addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(values) }); } // ----------------------------------------- @@ -502,121 +430,49 @@ void ArgParser::addArgument(Argument&& argument) void ArgParser::addArgument(bool& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(const char*& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(std::string& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(std::string_view& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(int& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(unsigned int& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(double& value, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - 1, - 0, - getAcceptFunction(value), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) }); } void ArgParser::addArgument(std::vector& values, const char* name, const char* usageString, const char* manString, Required required) { size_t minValues = required == Required::Yes ? 1 : 0; - Argument argument { - name, - usageString, - manString, - minValues, - values.max_size(), - 0, - getAcceptFunction(values), - }; - addArgument(std::move(argument)); + addArgument({ name, usageString, manString, minValues, values.max_size(), 0, getAcceptFunction(values) }); } } // namespace Util