本文整理汇总了C++中Options::addArgument方法的典型用法代码示例。如果您正苦于以下问题:C++ Options::addArgument方法的具体用法?C++ Options::addArgument怎么用?C++ Options::addArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options::addArgument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Options
Options *OptionParser::parse(int argc, char *const argv[])
{
Options *options = new Options();
QByteArray shortOptions;
int shortIndexes[256];
std::fill(shortIndexes, shortIndexes + 256, -1);
ScopedArrayPtr<struct option> longOptions(new struct option[m_options.size() + 1]);
int i;
for (i = 0; i < m_options.size(); i++) {
const Option *option = m_options.at(i);
QByteArray name = option->longName().toLocal8Bit();
longOptions[i].name = strdup(name.constData());
if (option->argument() == Option::NoArgument) {
longOptions[i].has_arg = no_argument;
}
else {
longOptions[i].has_arg = required_argument;
}
longOptions[i].flag = 0;
longOptions[i].val = 0;
if (option->shortName()) {
shortOptions += option->shortName();
if (option->argument() != Option::NoArgument) {
shortOptions += ':';
}
shortIndexes[option->shortName()] = i;
}
if (!option->defaultValue().isNull()) {
options->addOption(name, option->defaultValue());
}
}
longOptions[i].name = 0;
longOptions[i].has_arg = 0;
longOptions[i].flag = 0;
longOptions[i].val = 0;
m_prog = argv[0];
int longIndex = 0;
while (true) {
int c = getopt_long(argc, argv, shortOptions.constData(), longOptions.get(), &longIndex);
if (c == -1) {
break;
}
if (c == 0 || shortIndexes[c] != -1) {
i = (c == 0) ? longIndex : shortIndexes[c];
QString name = m_options[i]->longName();
options->addOption(name, QString::fromLocal8Bit(optarg));
if (name == "help") {
showHelp();
exit(EXIT_SUCCESS);
}
}
else {
showHelp();
exit(EXIT_FAILURE);
}
}
while (optind < argc) {
options->addArgument(QString::fromLocal8Bit(argv[optind++]));
}
for (i = 0; i < m_options.size(); i++) {
free((void *) longOptions[i].name);
}
return options;
}