本文整理汇总了C++中OptionParser::parse_args方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionParser::parse_args方法的具体用法?C++ OptionParser::parse_args怎么用?C++ OptionParser::parse_args使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionParser
的用法示例。
在下文中一共展示了OptionParser::parse_args方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, const char* argv[]) {
OptionParser parser;
parser.description("split input file by odd lines and even lines into two files\n"
"input from stdin, output odd lines to stdout, even lines to stderr")
.usage("%prog [OPTIONS] < INPUT > ODD_LINES 2> EVEN_LINES")
.version("1.0")
.epilog("By jadesoul @ 2013-11-19 14:47:14\n"
"please report bugs to " JADESOUL_EMAIL);
parser.add_option("-v", "--verbose")
.action("store_true")
.dest("verbose")
.set_default("0")
.help("print status messages to stdlog");
OptionArgs& optargs = parser.parse_args(argc, argv);
bool verbose=optargs.get("verbose");
if (verbose) cout<<"begin ..."<<endl;
uint i=0;
string s;
while (getline(cin, s))
if (++i%2==1) cout<<s<<endl;
else cerr<<s<<endl;
if (verbose) cout<<"finished"<<endl;
return 0;
}
示例2: OptionGroup
int
main(int argc, char *argv[])
{
OptionParser parser = create_common_options( USAGE, DESCRIPTION, false );
OptionGroup group = OptionGroup( parser, "Options for bayes", "These options will change the behaviour of bayes and fine." );
group.add_option( "-n", "--num-interactions" ).type( "int" ).help( "The number of interactions to correct for, this is used in the model prior (default: all)." );
group.add_option( "-s", "--num-single" ).type( "int" ).help( "The number of snps to consider when correcting (default: proportional to square of the number of interactions)." );
group.add_option( "-t", "--single-prior" ).type( "float" ).help( "The probability that a single snp is associated (default: %default)." ).set_default( 0.0 );
group.add_option( "-i", "--mc-iterations" ).type( "int" ).help( "The number of monte carlo iterations to use in the fine method (default: %default)." ).set_default( 4000000 );
group.add_option( "-a", "--beta-prior-param1" ).type( "float" ).help( "First shape parameter of beta prior (default: %default)." ).set_default( 2.0 );
group.add_option( "-b", "--beta-prior-param2" ).type( "float" ).help( "Second shape parameter of beta prior (default: %default)." ).set_default( 2.0 );
group.add_option( "-e", "--estimate-prior-params" ).action( "store_true" ).help( "Estimate prior parameters from data by permuting phenotype (default: off)." );
parser.add_option( "--additive" ).action( "store_true" ).help( "Use an additive model (slow)." );
parser.add_option_group( group );
Values options = parser.parse_args( argc, argv );
if( parser.args( ).size( ) != 2 )
{
parser.print_help( );
exit( 1 );
}
shared_ptr<common_options> parsed_data = parse_common_options( options, parser.args( ) );
/* Read prior parameters */
arma::vec alpha = arma::ones<arma::vec>( 2 );
alpha[ 0 ] = (float) options.get( "beta_prior_param1" );
alpha[ 1 ] = (float) options.get( "beta_prior_param2" );
if( options.is_set( "estimate_prior_params" ) )
{
alpha = estimate_prior_parameters( parsed_data->genotypes, parsed_data->data->phenotype, parsed_data->data->missing, 5000 );
}
/* Count the number of interactions to adjust for */
parsed_data->data->single_prior = (float) options.get( "single_prior" );
parsed_data->data->num_single = (unsigned int) options.get( "num_single" );
parsed_data->data->num_interactions = (unsigned int) options.get( "num_interactions" );
method_type *m = new besiq_method( parsed_data->data, alpha );
if( options.is_set( "additive" ) )
{
m = new besiq_method( parsed_data->data, alpha );
}
else
{
m = new besiq_fine_method( parsed_data->data, (int) options.get( "mc_iterations" ), alpha );
}
run_method( *m, parsed_data->genotypes, *parsed_data->pairs, *parsed_data->result_file );
delete m;
return 0;
}
示例3: main
void main(int argc, char* argv[])
{
OptionParser optparse = OptionParser();
optparse.add_option("--infile").help("select source for tracking");
optparse.add_option("--outlog").help("select file for output");
optparse.add_option("--outvideo").help("select file for video output");
optparse.add_option("--debug").action("store_true").help("show debug windows");
optparse.add_option("--recording").action("store_false").help("record the tracking process (just the main window)");
Values& options = optparse.parse_args(argc, argv);
GenericClassnameOneTracker9000 tracker(options["infile"], options["outlog"], options["outvideo"], options.is_set("debug"), options.is_set("recording"));
tracker.Routine();
}
示例4: main
int main(int argc, char * argv[]){
server_log(SERVER_LOG_INFO, "Starting MyFTP Server... \n");
OptionParser parser = OptionParser().description("MyFTP Server.");
parser.add_option("-v", "--verbose").dest("verbose").type("int").set_default("3")
.help("Set log level. Default: 3 - INFO");
parser.add_option("-p", "--port").dest("port").type("int").set_default("21")
.help("Set listening port. Default: 21");
parser.add_option("-i", "--IP").dest("ip").set_default("127.0.0.1")
.help("Set listening IP. Default: 127.0.0.1");
parser.add_option("-m", "--max-conns").dest("max_conns").type("int").set_default("10")
.help("Set max connections limit. Default: 10");
parser.add_option("-a", "--allow-anonymous").dest("allow_anony").type("int").set_default("0")
.help("Allow anonymous connections. Default: 0");
parser.add_option("-d", "--default-dir").dest("default_dir").set_default("")
.help("Default dir for anonymous users");
parser.add_option("-c", "--config").dest("config_file").set_default("")
.help("Configuration file");
parser.add_help_option();
optparse::Values & options = parser.parse_args(argc, argv);
myftpserver_t server_t;
log_level = (int)options.get("verbose");
server_t.port = (unsigned int)options.get("port");
server_log(SERVER_LOG_INFO, "Server port parsed: %d \n", server_t.port);
server_t.ipv4addr = (unsigned int)inet_addr(options["ip"].c_str());
server_log(SERVER_LOG_INFO, "Server IP parsed: %s Hex: %08x \n", options["ip"].c_str(), server_t.ipv4addr);
server_t.max_conns = (unsigned int)options.get("max_conns");
server_log(SERVER_LOG_INFO, "Server max connections: %d\n", server_t.max_conns);
server_t.allow_anonymous = (bool)options.get("allow_anony");
server_log(SERVER_LOG_INFO, "Server allows anonymous connections: %d\n", server_t.allow_anonymous);
strcpy(server_t.default_dir, options["default_dir"].c_str());
server_log(SERVER_LOG_INFO, "Server default dir: %s\n", server_t.default_dir);
start_server(&server_t);
return 0;
}
示例5: options
optparse::Values options(int argc, char *argv[]){
OptionParser parser = OptionParser().description("Generates guesses from a PCFG");
parser.add_option("-s", "--password_set").type("int");
parser.add_option("-m", "--mangle").help("enables mangling rules").action("store_true");
parser.add_option("-n", "--limit").type("double").help("limits the number of guesses generated")
.set_default(std::numeric_limits<double>::infinity());
parser.add_option("-l", "--length").help("minimum length of the guesses").type("int")
.set_default(0);
parser.add_option("-p", "--prob").type("double").help("sets a minimum guess probability threshold").set_default(0);
parser.add_option("-g", "--grammar").set_default("").help("location of the grammar");
parser.add_option("-v", "--verbose").action("store_true");
char const* const algorithms[] = { "next", "deadbeat"};
parser.add_option("-a", "--algorithm").choices(&algorithms[0], &algorithms[2]).help("Either 'next' or 'deadbeat'");
return parser.parse_args(argc, argv);
}
示例6: grid
int
main(int argc, char *argv[])
{
OptionParser parser = create_options( );
Values options = parser.parse_args( argc, argv );
if( parser.args( ).size( ) < 2 )
{
parser.print_help( );
exit( 1 );
}
std::vector<plink_file_ptr> plink_files = open_plink_file( parser.args( ) );
std::vector<genotype_matrix_ptr> genotypes = create_genotype_matrices( plink_files );
/**
* Create pair iterator
*/
size_t split = (size_t) options.get( "split" );
size_t num_splits = (size_t) options.get( "num_splits" );
if( split > num_splits || split == 0 || num_splits == 0 )
{
std::cerr << "besiq: error: Num splits and split must be > 0, and split <= num_splits." << std::endl;
exit( 1 );
}
std::vector<std::string> loci = plink_files[ 0 ]->get_locus_names( );
pairfile *pairs = open_pair_file( parser.args( )[ 0 ].c_str( ), loci );
if( pairs == NULL || !pairs->open( split, num_splits ) )
{
std::cerr << "besiq: error: Could not open pair file." << std::endl;
exit( 1 );
}
logp_grid grid( plink_files[ 0 ]->get_loci( ), 7000, 500000 );
double threshold = (double) options.get( "threshold" );
/**
* Set up method
*/
std::vector<wald_method *> methods;
for(int i = 0; i < plink_files.size( ); i++)
{
method_data_ptr data( new method_data( ) );
data->missing = zeros<uvec>( plink_files[ i ]->get_samples( ).size( ) );
data->phenotype = create_phenotype_vector( plink_files[ i ]->get_samples( ), data->missing );
methods.push_back( new wald_method( data ) );
}
/**
* Open results.
*/
resultfile *result = NULL;
if( options.is_set( "out" ) )
{
result = new bresultfile( options[ "out" ], loci );
}
else
{
std::ios_base::sync_with_stdio( false );
result = new tresultfile( "-", "w" );
}
if( result == NULL || !result->open( ) )
{
std::cerr << "besiq: error: Can not open result file." << std::endl;
exit( 1 );
}
std::vector<std::string> header;
header.push_back( "W" );
header.push_back( "P" );
header.push_back( "N" );
result->set_header( header );
/**
* Run analysis
*/
std::pair<std::string, std::string> pair;
float *output = new float[ methods[ 0 ]->init( ).size( ) ];
float meta_output[ header.size( ) ];
while( pairs->read( pair ) )
{
/* Compute betas and covariances */
std::vector<arma::vec> betas( methods.size( ), arma::zeros<arma::vec>( 4 ) );
std::vector<arma::mat> weights( methods.size( ), arma::zeros<arma::mat>( 4, 4 ) );
size_t N = 0;
bool all_valid = true;
for(int i = 0; i < methods.size( ); i++)
{
snp_row const *row1 = genotypes[ i ]->get_row( pair.first );
snp_row const *row2 = genotypes[ i ]->get_row( pair.second );
methods[ i ]->run( *row1, *row2, output );
betas[ i ] = methods[ i ]->get_last_beta( );
arma::mat C = methods[ i ]->get_last_C( );
arma::mat Cinv;
if( C.n_cols != 4 || C.n_rows != 4 || !arma::inv( Cinv, C ) )
//.........这里部分代码省略.........
示例7: main
int main(int argc, char *argv[])
{
const string usage =
(!getenv("DISABLE_USAGE")) ?
"usage: %prog [OPTION]... DIR [FILE]..." : SUPPRESS_USAGE;
const string version = "%prog 1.0\nCopyright (C) 2010 Johannes Weißl\n"
"License GPLv3+: GNU GPL version 3 or later "
"<http://gnu.org/licenses/gpl.html>.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.";
const string desc = "Lorem ipsum dolor sit amet, consectetur adipisicing"
" elit, sed do eiusmod tempor incididunt ut labore et dolore magna"
" aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco"
" laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor"
" in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla"
" pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa"
" qui officia deserunt mollit anim id est laborum.";
const string epilog = "Sed ut perspiciatis unde omnis iste natus error sit"
" voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque"
" ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae"
" dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit"
" aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos"
" qui ratione voluptatem sequi nesciunt.\nNeque porro quisquam est, qui"
" dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia"
" non numquam eius modi tempora incidunt ut labore et dolore magnam"
" aliquam quaerat voluptatem.";
OptionParser parser = OptionParser()
.usage(usage)
.version(version)
.description(desc)
.epilog(epilog)
;
if (getenv("DISABLE_INTERSPERSED_ARGS"))
parser.disable_interspersed_args();
parser.set_defaults("verbosity", "50");
parser.set_defaults("no_clear", "0");
// test all actions
parser.add_option("--clear") .action("store_false") .dest("no_clear") .help("clear (default)");
parser.add_option("--no-clear") .action("store_true") .help("not clear");
parser.add_option("--string")
.help("This is a really long text... very long indeed! It must be wrapped on normal terminals.");
parser.add_option("-x", "--clause", "--sentence") .metavar("SENTENCE") .set_default("I'm a sentence")
.help("This is a really long text... very long indeed! It must be wrapped on normal terminals. "
"Also it should appear not on the same line as the option.");
parser.add_option("-k") .action("count") .help("how many times?");
parser.add_option("--verbose") .action("store_const") .set_const("100") .dest("verbosity") .help("be verbose!");
parser.add_option("-s", "--silent") .action("store_const") .set_const("0") .dest("verbosity") .help("be silent!");
parser.add_option("-n", "--number") .type("int") .set_default("1") .metavar("NUM") .help("number of files (default: %default)");
parser.add_option("-H") .action("help") .help("alternative help");
parser.add_option("-V") .action("version") .help("alternative version");
parser.add_option("-i", "--int") .action("store") .type("int") .set_default(3) .help("default: %default");
parser.add_option("-f", "--float") .action("store") .type("float") .set_default(5.3) .help("default: %default");
parser.add_option("-c", "--complex") .action("store") .type("complex");
char const* const choices[] = { "foo", "bar", "baz" };
parser.add_option("-C", "--choices") .choices(&choices[0], &choices[3]);
#if __cplusplus >= 201103L
parser.add_option("--choices-list") .choices({"item1", "item2", "item3"});
#else
char const* const choices_list[] = { "item1", "item2", "item3" };
parser.add_option("--choices-list") .choices(&choices_list[0], &choices_list[3]);
#endif
parser.add_option("-m", "--more") .action("append");
parser.add_option("--more-milk") .action("append_const") .set_const("milk");
parser.add_option("--hidden") .help(SUPPRESS_HELP);
// test for 325cb47
parser.add_option("--option1") .action("store") .type("int") .set_default(1);
parser.add_option("--option2") .action("store") .type("int") .set_default("1");
parser.set_defaults("option1", "640");
parser.set_defaults("option2", 640); // now works
MyCallback mc;
parser.add_option("-K", "--callback") .action("callback") .callback(mc) .help("callback test");
parser.add_option("--string-callback") .action("callback") .callback(mc) .type("string") .help("callback test");
OptionGroup group1 = OptionGroup(parser, "Dangerous Options",
"Caution: use these options at your own risk. "
"It is believed that some of them\nbite.");
group1.add_option("-g") .action("store_true") .help("Group option.") .set_default("0");
parser.add_option_group(group1);
OptionGroup group2 = OptionGroup(parser, "Size Options", "Image Size Options.");
group2.add_option("-w", "--width") .action("store") .type("int") .set_default(640) .help("default: %default");
group2.add_option("--height") .action("store") .type("int") .help("default: %default");
parser.set_defaults("height", 480);
parser.add_option_group(group2);
try {
Values& options = parser.parse_args(argc, argv);
vector<string> args = parser.args();
cout << "clear: " << (options.get("no_clear") ? "false" : "true") << endl;
cout << "string: " << options["string"] << endl;
cout << "clause: " << options["clause"] << endl;
cout << "k: " << options["k"] << endl;
cout << "verbosity: " << options["verbosity"] << endl;
cout << "number: " << (int) options.get("number") << endl;
//.........这里部分代码省略.........