本文整理汇总了C++中OptionsList::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionsList::parse方法的具体用法?C++ OptionsList::parse怎么用?C++ OptionsList::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionsList
的用法示例。
在下文中一共展示了OptionsList::parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
void AgentConfiguration::initialize(int aArgc, const char *aArgv[])
{
MTConnectService::initialize(aArgc, aArgv);
const char *configFile = "agent.cfg";
OptionsList optionList;
optionList.append(new Option(0, configFile, "The configuration file", "file", false));
optionList.parse(aArgc, (const char**) aArgv);
mConfigFile = configFile;
try
{
configureLogger();
ifstream file(mConfigFile.c_str());
loadConfig(file);
}
catch (std::exception & e)
{
sLogger << LFATAL << "Agent failed to load: " << e.what();
cerr << "Agent failed to load: " << e.what() << std::endl;
optionList.usage();
}
}
示例2: args
using dataTypes::OptionsList;
using dataTypes::OptionEntry;
TEST_FUNCTION(10) {
std::vector<std::string> args({"--test-argument-value-space", "argument value", "--test-argument-value-equals",
"=sample", "some/file/path", "--test-boolean"});
OptionsList opts;
opts.addEntry(OptionEntry(dataTypes::OptionArgumentType::OptionArgumentFilename, 0, "test-argument-value-space",
"Test passing argument for the value with space", nullptr, "name"));
opts.addEntry(OptionEntry(dataTypes::OptionArgumentType::OptionArgumentFilename, 0, "test-argument-value-equals",
"Test passing argument for the value with equals", nullptr, "name"));
opts.addEntry(
OptionEntry(dataTypes::OptionArgumentType::OptionArgumentLogical, 0, "test-boolean", "Test boolean value"));
int retVal = 0;
ensure("Unable to parse command line", opts.parse(args, retVal));
ensure("incorrect test-boolean", opts.getEntry("test-boolean")->value.logicalValue);
ensure_equals("incorrect test-argument-value-equals", opts.getEntry("test-argument-value-equals")->value.textValue,
"=sample");
ensure_equals("incorrect test-argument-value-space", opts.getEntry("test-argument-value-space")->value.textValue,
"argument value");
ensure("incorrect number of leftover values", opts.pathArgs.size() == 1);
ensure_equals("incorrect leftover value", opts.pathArgs[0], "some/file/path");
}
TEST_FUNCTION(20) {
std::vector<std::string> args({"--test-return-value", "--test-callback", "--test-argument-value-space",
"argument value", "--test-argument-value-equals", "=sample", "some/file/path",
"--test-boolean"});
OptionsList opts;
opts.addEntry(