Browse Source

Util: Switch ArgParser option/argument creation to list initialization

master
Riyyi 3 years ago
parent
commit
4e30b58305
  1. 176
      src/util/argparser.cpp

176
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) void ArgParser::addOption(bool& value, char shortName, const char* longName, const char* usageString, const char* manString)
{ {
Option option { addOption({ shortName, longName, nullptr, usageString, manString, Required::No, getAcceptFunction(value) });
shortName,
longName,
nullptr,
usageString,
manString,
Required::No,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(const char*& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) void ArgParser::addOption(const char*& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument)
{ {
Option option { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(std::string& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) void ArgParser::addOption(std::string& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument)
{ {
Option option { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(std::string_view& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) 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 { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(int& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) void ArgParser::addOption(int& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument)
{ {
Option option { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(unsigned int& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) void ArgParser::addOption(unsigned int& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument)
{ {
Option option { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(double& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) void ArgParser::addOption(double& value, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument)
{ {
Option option { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(value) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(value),
};
addOption(std::move(option));
} }
void ArgParser::addOption(std::vector<std::string>& values, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument) void ArgParser::addOption(std::vector<std::string>& values, char shortName, const char* longName, const char* usageString, const char* manString, const char* argumentName, Required requiresArgument)
{ {
Option option { addOption({ shortName, longName, argumentName, usageString, manString, requiresArgument, getAcceptFunction(values) });
shortName,
longName,
argumentName,
usageString,
manString,
requiresArgument,
getAcceptFunction(values),
};
addOption(std::move(option));
} }
// ----------------------------------------- // -----------------------------------------
@ -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) void ArgParser::addArgument(bool& value, const char* name, const char* usageString, const char* manString, Required required)
{ {
size_t minValues = required == Required::Yes ? 1 : 0; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(const char*& value, const char* name, const char* usageString, const char* manString, Required required) 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; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(std::string& value, const char* name, const char* usageString, const char* manString, Required required) 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; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(std::string_view& value, const char* name, const char* usageString, const char* manString, Required required) 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; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(int& value, const char* name, const char* usageString, const char* manString, Required required) void ArgParser::addArgument(int& value, const char* name, const char* usageString, const char* manString, Required required)
{ {
size_t minValues = required == Required::Yes ? 1 : 0; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(unsigned int& value, const char* name, const char* usageString, const char* manString, Required required) 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; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(double& value, const char* name, const char* usageString, const char* manString, Required required) void ArgParser::addArgument(double& value, const char* name, const char* usageString, const char* manString, Required required)
{ {
size_t minValues = required == Required::Yes ? 1 : 0; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, 1, 0, getAcceptFunction(value) });
name,
usageString,
manString,
minValues,
1,
0,
getAcceptFunction(value),
};
addArgument(std::move(argument));
} }
void ArgParser::addArgument(std::vector<std::string>& values, const char* name, const char* usageString, const char* manString, Required required) void ArgParser::addArgument(std::vector<std::string>& values, const char* name, const char* usageString, const char* manString, Required required)
{ {
size_t minValues = required == Required::Yes ? 1 : 0; size_t minValues = required == Required::Yes ? 1 : 0;
Argument argument { addArgument({ name, usageString, manString, minValues, values.max_size(), 0, getAcceptFunction(values) });
name,
usageString,
manString,
minValues,
values.max_size(),
0,
getAcceptFunction(values),
};
addArgument(std::move(argument));
} }
} // namespace Util } // namespace Util

Loading…
Cancel
Save