本文整理汇总了C++中ArgumentParser::parseArguments方法的典型用法代码示例。如果您正苦于以下问题:C++ ArgumentParser::parseArguments方法的具体用法?C++ ArgumentParser::parseArguments怎么用?C++ ArgumentParser::parseArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentParser
的用法示例。
在下文中一共展示了ArgumentParser::parseArguments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseOptions
/**
* @brief parseOptions parse user arguments
*/
UserOptions parseOptions(const int argc, const char* argv[]) {
UserOptions user_options;
vector<string> arguments;
for (const size_t argn : crange(argc))
arguments.push_back(argv[argn]);
// Parse arguments
ArgumentParser parser;
user_options = parser.parseArguments(arguments);
user_options.addDefaultFiles();
if (user_options.use_textfile) {
output_streamer.createStreamFile(results_str, user_options.datatext_file);
}
return user_options;
}
示例2: run_tests
int run_tests(u32 num, Test const* tests, int argc, char** argv)
{
State::SetInternalThreadState(State::CreateNewThreadState());
SetPrintingVerbosity(10);
auto args = AppArg::Clone(argc, argv);
RuntimeQueue::CreateNewQueue("Testing");
ArgumentParser parser;
parser.addSwitch("json", "json", nullptr, "Output JSON document");
auto parseArgs = parser.parseArguments(args);
bool json_formatting = parseArgs.switches.count("json");
Vector<TestInstance> test_results;
test_results.resize(num);
titles.resize(num);
descriptions.resize(num);
test_times.resize(num);
result.reserve(num);
required.reserve(num);
bool fail = false;
for(u32 i = 0; i < num; i++)
{
TestInstance& test_info = test_results.at(i);
RunTest(tests[i], test_info);
if(test_info.required && !test_info.result)
fail = true;
}
result.resize(num, false);
required.resize(num, true);
szptr suc = 0;
for(bool v : result)
if(v)
suc++;
u64 time_accum = 0;
for(u64 v : test_times)
time_accum += v;
ExtraData::Add("testing:title", GetCurrentApp().application_name);
ExtraData::Add("testing:bmark", cast_pod(time_accum));
ExtraData::Add("testing:result", Strings::fmt("{0},{1}", suc, num));
ExtraData::Add("testing:mem", cast_pod(ProcessProperty::Mem(0)));
for(auto i : Range<>(test_results.size()))
{
auto const& test = test_results.at(i);
titles.at(i) = test.title;
descriptions.at(i) = test.description;
test_times.at(i) = test.time;
result.at(i) = test.result;
required.at(i) = test.required;
}
if(!json_formatting)
{
PrintAsciiTable(time_accum, suc);
} else
{
JSON::WriteBuf buf;
WriteJsonData(buf, suc, time_accum, tests);
cOutputPrint("{0}", buf.GetString());
ExtraData::Add("testing:jsonresult", buf.GetString());
}
cDebug("Memory consumption: {0} kB", ProcessProperty::Mem(0));
/* For verbosity, we write it as this */
return (fail) ? 1 : 0;
}