本文整理汇总了C++中OptionsParser::addOption方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionsParser::addOption方法的具体用法?C++ OptionsParser::addOption怎么用?C++ OptionsParser::addOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionsParser
的用法示例。
在下文中一共展示了OptionsParser::addOption方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char** argv)
{
string inFile = "";
string tileDir = "/class/cs225/mp6_bmps/";
string numTilesStr = "100";
string pixelsPerTileStr = "50";
string outFile = "mosaic.png";
OptionsParser optsparse;
optsparse.addArg(inFile);
optsparse.addArg(tileDir);
optsparse.addArg(numTilesStr);
optsparse.addArg(pixelsPerTileStr);
optsparse.addArg(outFile);
optsparse.addOption("help", opts::help);
optsparse.addOption("h", opts::help);
optsparse.parse(argc, argv);
if (opts::help)
{
cout << "Usage: " << argv[0] << " background_image.png tile_directory/ [number of tiles] [pixels per tile] [output_image.png]" << endl;
return 0;
}
if (inFile == "")
{
cout << "Usage: " << argv[0] << " background_image.png tile_directory/ [number of tiles] [pixels per tile] [output_image.png]" << endl;
return 1;
}
makePhotoMosaic(inFile, tileDir, lexical_cast<int>(numTilesStr), lexical_cast<int>(pixelsPerTileStr), outFile);
return 0;
}
示例2: processArgs
void monad::processArgs(int argc, const char* const* argv)
{
// Create OptionsMap for options and vector for positional arguments:
OptionsParser options;
// Add our possible options to our map
options.addOption("solution", opts::solution);
options.addOption("newtests", opts::newtests);
options.addOption("provided", opts::provided);
options.addOption("clean", opts::clean);
options.addOption("update", opts::update);
options.addOption("staff", opts::staff);
options.addOption("optimize", opts::optimize);
options.addOption("detailed", opts::detailed);
options.addOption("verbose", opts::verbose);
options.addOption("buffer", opts::buffer);
options.addOption("asan", opts::asan);
options.addOption("parallel", opts::parallel);
options.addOption("help", opts::help);
options.addOption("h", opts::help);
options.addOption("info", opts::info);
options.addOption("version", opts::info);
options.addOption("v", opts::info);
options.addOption("license", opts::license);
// Add arguments
string assignment = "";
options.addArg(assignment);
// Read in options and arguments
vector<string> posargs = options.parse(argc, argv);
// Help
if (opts::help || toLower(assignment) == "help")
{
if (toLower(assignment) == "config")
printHelpConfig();
else if (toLower(assignment) == "tests")
printHelpTests();
else
printHelp();
exit(0);
}
// Info
if (opts::info)
{
printInfo();
exit(0);
}
// License
if (opts::license)
{
printLicense();
exit(0);
}
// Clean
if (toLower(assignment) == "clean")
{
system("/bin/rm -rf *_grade/ *_tests/ *_newtests/ *_provided/ "
"*_solution/");
exit(0);
}
// Check argument list length
if (assignment == "")
{
cout << "Usage: " << argv[0] << " mp1" << endl;
cout << "Run \'" << argv[0] << " --help\' for more information" << endl;
exit(0);
}
// Find mp/lab name and tests folder
if (assignment[assignment.length() - 1] == '/')
assignment = assignment.substr(0, assignment.length() - 1);
size_t slash_i = assignment.find_last_of('/');
string assignment_name =
(slash_i == string::npos) ? assignment : assignment.substr(slash_i + 1);
string assignment_dir =
(slash_i == string::npos) ? "" : assignment.substr(0, slash_i);
// TODO (toole1): All this stuff is ugly!
vector<string> splitname = tokenize(assignment_name, '.');
assignment_base = splitname[0];
if (splitname.size() == 1)
mp_part = no_mp_part;
else
mp_part = lexical_cast<int>(splitname[1].c_str());
gradeFolder = "./" + assignment_base + "_grade/";
if (!exists(gradeFolder))
opts::clean = true;
if (opts::clean)
tempFolder = "";
else
//.........这里部分代码省略.........
示例3: processArgs
void monad::processArgs(int argc, const char * const * argv)
{
// Create OptionsMap for options and vector for positional arguments:
OptionsParser options;
// Add our possible options to our map
options.addOption("solution", opts::solution);
options.addOption("newtests", opts::newtests);
options.addOption("provided", opts::provided);
options.addOption("clean", opts::clean);
options.addOption("update", opts::update);
options.addOption("staff", opts::staff);
options.addOption("optimize", opts::optimize);
options.addOption("verbose", opts::verbose);
options.addOption("buffer", opts::buffer);
options.addOption("valgrind", opts::valgrind);
options.addOption("parallel", opts::parallel);
options.addOption("help", opts::help);
options.addOption("h", opts::help);
options.addOption("info", opts::info);
options.addOption("version", opts::info);
options.addOption("v", opts::info);
options.addOption("license", opts::license);
// Add arguments
string assignment = "";
options.addArg(assignment);
// Read in options and arguments
vector<string> posargs = options.parse(argc, argv);
// Help
if (opts::help || toLower(assignment) == "help")
{
if (toLower(assignment) == "config")
printHelpConfig();
else if (toLower(assignment) == "tests")
printHelpTests();
else
printHelp();
exit(0);
}
// Info
if (opts::info)
{
printInfo();
exit(0);
}
// License
if (opts::license)
{
printLicense();
exit(0);
}
// Clean
if (toLower(assignment) == "clean")
{
system("/bin/rm -rf *_grade/ *_tests/ *_newtests/ *_providedtests *_solution/");
exit(0);
}
// Check argument list length
if (assignment == "")
{
cout << "Usage: " << argv[0] << " mp1" << endl;
cout << "Run \'" << argv[0] << " --help\' for more information" << endl;
exit(0);
}
// Find mp/lab name and tests folder
vector<string> splitname = tokenize(assignment, '.');
assignment_base = splitname[0];
if (splitname.size() == 1)
mp_part = no_mp_part;
else
mp_part = lexical_cast<int>(splitname[1].c_str());
gradeFolder = "./" + assignment_base + "_grade/";
if (!exists(gradeFolder)) opts::clean = true;
if (opts::clean)
tempFolder = "";
else
tempFolder = "./" + assignment_base + "_temp/";
// Find source folder (i.e. ../mp1)
if (opts::solution)
sourceFolder = updateFolder(assignment_base + "_solution/", false);
else
sourceFolder = getFolder(assignment_base + '/', false);
// tests folder
if (opts::provided)
testsFolder = updateFolder(assignment_base + "_provided/", false);
else if (opts::newtests)
//.........这里部分代码省略.........