当前位置: 首页>>代码示例>>C++>>正文


C++ OptionsParser::addOption方法代码示例

本文整理汇总了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;
}
开发者ID:irtefa,项目名称:dumbshit,代码行数:34,代码来源:photomosaic.cpp

示例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
//.........这里部分代码省略.........
开发者ID:erjohns3,项目名称:CS_225,代码行数:101,代码来源:monad.cpp

示例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)
//.........这里部分代码省略.........
开发者ID:irtefa,项目名称:dumbshit,代码行数:101,代码来源:monad.cpp


注:本文中的OptionsParser::addOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。