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


C++ OptionParser::checkOptions方法代码示例

本文整理汇总了C++中OptionParser::checkOptions方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionParser::checkOptions方法的具体用法?C++ OptionParser::checkOptions怎么用?C++ OptionParser::checkOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OptionParser的用法示例。


在下文中一共展示了OptionParser::checkOptions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parseOptions

Options parseOptions(int _argc, char * _argv[], Options defaults) {

    /******************************************
     *  Pass the array of argument and the name of
     *  a configuration file to the ArgumentParser
     *  object.  Then ask for the value of the argument
     *  and collect error and warnings.
     *
     *  This function returns a Options structure
     *  defined at the head of this file
     ******************************************/

    Options opt;

    /******************************************
     *  Set the allowed and required options:
     *
     *  Example of configuartion file:
     *
     ******************************************/
    vector<string> required;
    vector<string> allowed;

    opt.required.push_back("pdb");
    opt.required.push_back("type");
    opt.required.push_back("atomNames");
    opt.required.push_back("value");
    opt.allowed.push_back("outputPdb");
    //opt.allowed.push_back("outputdir");
    opt.allowed.push_back("configfile");
    opt.allowed.push_back("version"); // --version
    opt.allowed.push_back("v"); // -v is equivalent to --version
    opt.allowed.push_back("help"); // --help
    opt.allowed.push_back("h"); // -h is equivalent to --help

    opt.equivalent.push_back(vector<string>());
    opt.equivalent.back().push_back("v");
    opt.equivalent.back().push_back("version");
    opt.equivalent.push_back(vector<string>());
    opt.equivalent.back().push_back("h");
    opt.equivalent.back().push_back("help");

    opt.defaultArgs.push_back("configfile");


    //OptionParser OP(_argc, _argv);
    OptionParser OP;
    OP.setShortOptionEquivalent(opt.equivalent);
    OP.readArgv(_argc, _argv);
    OP.setDefaultArguments(opt.defaultArgs); // a pdb file value can be given as a default argument without the --pdbfile option
    OP.setRequired(opt.required);
    OP.setAllowed(opt.allowed);
    OP.autoExtendOptions(); // if you give option "solvat" it will be autocompleted to "solvationfile"
    if (OP.countOptions() == 0) {
        usage();
        exit(0);
    }
    opt.configfile = OP.getString("configfile");
    if (opt.configfile != "") {
        OP.readFile(opt.configfile);
        if (OP.fail()) {
            opt.errorFlag = true;
            opt.errorMessages += "Cannot read configuration file " + opt.configfile + "\n";
            exit(1);
        }
    }

    /*****************************************
     *  VERSION AND HELP
     *
     *  --version or -v arguments print the version number
     *  --help prints the usage and help
     *****************************************/
    opt.version = OP.getBool("version");
    //if (OP.fail()) {
    //	opt.version = OP.getBool("v");
    //}

    if (opt.version) {
        version();
        exit(0);
    }

    opt.help = OP.getBool("help");
//	if (OP.fail()) {
//		opt.help = OP.getBool("h");
//	}

    if (opt.help) {
        help(defaults);
        exit(0);
    }

    /*****************************************
     *  CHECK THE GIVEN OPTIONS
     *****************************************/
    if (!OP.checkOptions()) {
        opt.errorFlag = true;
        opt.OPerrors = OP.getErrors();
        return opt;
//.........这里部分代码省略.........
开发者ID:Suncuss,项目名称:mslib,代码行数:101,代码来源:setConformation.cpp

示例2: parseOptions


//.........这里部分代码省略.........
			exit(1);
		}
	}

	/*****************************************
	 *  VERSION AND HELP
	 *
	 *  --version or -v arguments print the version number
	 *  --help prints the usage and help
	 *****************************************/
	opt.version = OP.getBool("version");
	//if (OP.fail()) {
	//	opt.version = OP.getBool("v");
	//}

	if (opt.version) {
		version();
		exit(0);
	}

	opt.help = OP.getBool("help");
//	if (OP.fail()) {
//		opt.help = OP.getBool("h");
//	}

	if (opt.help) {
		help(defaults);
		exit(0);
	}

	/*****************************************
	 *  CHECK THE GIVEN OPTIONS
	 *****************************************/
	if (!OP.checkOptions()) {
		opt.errorFlag = true;
		opt.OPerrors = OP.getErrors();
		return opt;
	}
	opt.errorFlag = false;
	opt.warningFlag = false;

	/*****************************************
	 *  OUTPUT DIR AND FILES
	 *****************************************/
	opt.outputdir = OP.getString("outputdir");
	if (OP.fail() || opt.outputdir == "") {
		opt.outputdir = defaults.outputdir;
	}
	
	opt.outputfile = OP.getString("outputfile");
	if (OP.fail()) {
		opt.outputfile = defaults.outputfile;
	}
	if (opt.outputfile != "" && opt.outputfile != "STDOUT") {
		opt.coutRedirected = true;
		opt.cout_fs = new ofstream();
		opt.cerr_fs = new ofstream();
	} else {
		opt.coutRedirected = false;
		opt.cout_fs = NULL;
		opt.cerr_fs = NULL;
	}


	/*****************************************
	 *  CHECK THE GIVEN OPTIONS
开发者ID:Suncuss,项目名称:mslib,代码行数:67,代码来源:coiledCoilBuilder.cpp

示例3: parseOptions


//.........这里部分代码省略.........
			exit(1);
		}
	}

	/*****************************************
	 *  VERSION AND HELP
	 *
	 *  --version or -v arguments print the version number
	 *  --help prints the usage and help
	 *****************************************/
	opt.version = OP.getBool("version");
	//if (OP.fail()) {
	//	opt.version = OP.getBool("v");
	//}

	if (opt.version) {
		version();
		exit(0);
	}

	opt.help = OP.getBool("help");
//	if (OP.fail()) {
//		opt.help = OP.getBool("h");
//	}

	if (opt.help) {
		help(defaults);
		exit(0);
	}

	/*****************************************
	 *  CHECK THE GIVEN OPTIONS
	 *****************************************/
	if (!OP.checkOptions()) {
		opt.errorFlag = true;
		opt.OPerrors = OP.getErrors();
		return opt;
	}
	opt.errorFlag = false;
	opt.warningFlag = false;

	/*****************************************
	 *  OUTPUT DIR AND FILES
	 *****************************************/


	/*****************************************
	 *  CHECK THE GIVEN OPTIONS
	 *****************************************/
	opt.errorFlag = false;
	opt.warningFlag = false;

	opt.pdbFile = OP.getString("pdbFile");
	if (OP.fail()) {
		opt.errorMessages = "pdb file not specified";
		opt.errorFlag = true;
	}
	opt.helicalAxisPdbFile = OP.getString("helicalAxisPdbFile");
	if (OP.fail()) {
		opt.errorMessages = "helicalAxisPdbFile file not specified";
		opt.errorFlag = true;
	}
	opt.output = OP.getString("output");
	if (OP.fail()) {
		opt.errorMessages = "output not specified";
		opt.errorFlag = true;
开发者ID:Suncuss,项目名称:mslib,代码行数:67,代码来源:genHeteroUniverse.cpp


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