本文整理汇总了C++中OptionsParser类的典型用法代码示例。如果您正苦于以下问题:C++ OptionsParser类的具体用法?C++ OptionsParser怎么用?C++ OptionsParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OptionsParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTraversalKind
TraversalKind getTraversalKind (int argc, char* argv[])
{
const char* STR_TRAVERSAL_MODE = "-traversal";
TraversalKind result;
// We create a command line parser.
OptionsParser parser ("Traversal");
parser.push_back (new OptionOneParam (STR_TRAVERSAL_MODE, "traversal mode ('unitig' or 'contig'", true));
// We retrieve the traversal kind.
try
{
IProperties* props = parser.parse (argc, argv);
parse (props->getStr(STR_TRAVERSAL_MODE), result);
}
catch (OptionFailure& e)
{
e.displayErrors (std::cout);
exit (EXIT_FAILURE);
}
catch (Exception& e)
{
cout << e.getMessage() << endl;
exit (EXIT_FAILURE);
}
return result;
}
示例2: main
int main(int argc, const char **argv) {
OptionsParser parser;
if (parser.ParseOptions(argc, argv) < 0 || parser.m_Help) {
parser.Usage(argv[0]);
return -1;
}
Sid::SkypePCMInterfaceServer *pcmif_server = new Sid::SkypePCMInterfaceServer();
Sid::SkypePCMCallbackInterfaceClient *pcmif_cb_client = new Sid::SkypePCMCallbackInterfaceClient();
SkypePCMInterface* pcmif = SkypePCMInterfaceGet(pcmif_cb_client);
pcmif_server->set_if(pcmif);
Sid::String fromskypekitkey;
Sid::String toskypekitkey;
fromskypekitkey.Format( "%spcm_from_skypekit_key", parser.m_IpcPrefix);
toskypekitkey.Format( "%spcm_to_skypekit_key", parser.m_IpcPrefix);
pcmif_server->Connect(fromskypekitkey.data(), 0);
pcmif_cb_client->Connect(toskypekitkey.data(), 500);
if(parser.m_OutFile)
{
Sid::String cmd;
Sid::String response;
cmd.Format("OUT:%s",parser.m_OutFile);
pcmif->CustomCommand(cmd, response);
}
if(parser.m_InFile)
{
Sid::String cmd;
Sid::String response;
cmd.Format("IN:%s",parser.m_InFile);
pcmif->CustomCommand(cmd,response);
}
if(parser.m_Loop)
{
Sid::String cmd = "LOOP:1";
Sid::String response;
pcmif->CustomCommand("LOOP:1", response);
}
Sid::Protocol::Status status;
do {
status =pcmif_server->ProcessCommands();
} while (status == Sid::Protocol::OK);
SkypePCMInterfaceRelease(pcmif);
pcmif_server->Disconnect();
pcmif_cb_client->Disconnect();
delete pcmif_server;
delete pcmif_cb_client;
printf("PCMServerTransport disconnected, exiting from pcmtesthost\n");
}
示例3: visitOptionsParser
/*********************************************************************
** METHOD :
** PURPOSE :
** INPUT :
** OUTPUT :
** RETURN :
** REMARKS :
*********************************************************************/
void VisibilityOptionsVisitor::visitOptionsParser (OptionsParser& object, size_t depth)
{
if (_names.find(object.getName()) != _names.end()) { object.setVisible(_visibility); }
for (std::list<IOptionsParser*>::const_iterator it = object.getParsers().begin(); it != object.getParsers().end(); ++it)
{
(*it)->accept (*this, depth+1);
}
}
示例4: main
int main (int argc, char* argv[])
{
// We create a command line parser.
OptionsParser parser ("SortingCount");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "sorting count input", true));
try
{
// Shortcuts.
typedef Kmer<>::Count Count;
typedef Kmer<>::Type Type;
// We parse the user options.
IProperties* options = parser.parse (argc, argv);
// We load the object storing the couples [kmer,abundance]
Storage* storage = StorageFactory(STORAGE_HDF5).load (options->getStr(STR_URI_INPUT)); LOCAL (storage);
// We get the group inside the storage object
Group& dskGroup = storage->getGroup("dsk");
// We retrieve the partition holding the couples [kmer,abundance]
Partition<Count>& solidKmers = dskGroup.getPartition<Count> ("solid");
// Now, we read the couples in two ways, computing a checksum in each case.
Type checksum1, checksum2;
// CASE 1: we read the couples [kmer,abundance] with an iterator over the whole partition
Iterator<Count>* it = solidKmers.iterator(); LOCAL (it);
for (it->first(); !it->isDone(); it->next()) { checksum1 = checksum1 + it->item().value; }
// CASE 2: we read the couples [kmer,abundance] with an iterator over each collection of the partition
for (size_t i=0; i<solidKmers.size(); i++)
{
// We get the current collection inside the partition
Collection<Count>& collection = solidKmers [i];
Iterator<Count>* it = collection.iterator(); LOCAL (it);
for (it->first(); !it->isDone(); it->next()) { checksum2 = checksum2 + it->item().value; }
}
// We check that we got the same checksum
cout << "checksum1=" << checksum1 << endl;
cout << "checksum2=" << checksum1 << endl;
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
return EXIT_SUCCESS;
}
示例5: 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;
}
示例6: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankFilter");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank reference", true));
parser.push_back (new OptionOneParam (STR_URI_SEQ_IDS, "file holding indexes of bank", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** We read the list of indexes. */
set<size_t> indexes;
FILE* file = fopen (options->getStr(STR_URI_SEQ_IDS).c_str(), "r");
if (file != 0)
{
char buffer[128];
while (fgets (buffer, sizeof(buffer), file)) { indexes.insert (atoi(buffer)); }
fclose (file);
}
cout << "found " << indexes.size() << " indexes" << endl;
/** We open the output bank. */
string outputBankUri = options->getStr(STR_URI_INPUT) + "_" + System::file().getBaseName (options->getStr(STR_URI_SEQ_IDS));
IBank* outputBank = Bank::open (outputBankUri);
LOCAL (outputBank);
/** We loop the input bank. */
IBank* inputBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inputBank);
/** We use another iterator for filtering out some sequences. */
FilterIterator<Sequence,FilterFunctor> itSeq (inputBank->iterator(), FilterFunctor(indexes));
/** We loop the sequences. */
for (itSeq.first(); !itSeq.isDone(); itSeq.next())
{
outputBank->insert (itSeq.item());
}
/** We flush the output bank. */
outputBank->flush();
}
catch (OptionFailure& e)
{
return e.displayErrors (cout);
}
catch (Exception& e)
{
cerr << "EXCEPTION: " << e.getMessage() << endl;
}
}
示例7: MONGO_STARTUP_OPTIONS_PARSE
MONGO_STARTUP_OPTIONS_PARSE(StartupOptions)(InitializerContext* context) {
OptionsParser parser;
Status ret = parser.run(startupOptions, context->args(), context->env(),
&startupOptionsParsed);
if (!ret.isOK()) {
std::cerr << ret.reason() << std::endl;
// TODO: Figure out if there's a use case for this help message ever being different
std::cerr << "try '" << context->args()[0]
<< " --help' for more information" << std::endl;
::_exit(EXIT_BADOPTIONS);
}
return Status::OK();
}
示例8: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankFilter");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
parser.push_back (new OptionOneParam (STR_FILTER_RATIO, "skip a sequence if 'good letters number / seq.len > X'", false, "0.8"));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** Shortcuts. */
double percentThreshold = options->getDouble(STR_FILTER_RATIO);
/** We open the input bank. */
IBank* inBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inBank);
/** We create the output inBank. */
IBank* outBank = new BankFasta (options->getStr(STR_URI_INPUT) + "_filtered");
LOCAL (outBank);
/** We iterate the inBank. NOTE: WE USE A LAMBDA EXPRESSION HERE. */
inBank->iterate ([&] (Sequence& s)
{
/** Shortcut. */
char* data = s.getDataBuffer();
size_t nbOK = 0;
for (size_t i=0; i<s.getDataSize(); i++)
{
if (data[i]=='A' || data[i]=='C' || data[i]=='G' || data[i]=='T') { nbOK++; }
}
if ((double)nbOK / (double)s.getDataSize() > percentThreshold) { outBank->insert (s); }
});
/** We flush the output bank. */
outBank->flush();
}
catch (OptionFailure& e)
{
return e.displayErrors (cout);
}
catch (Exception& e)
{
cerr << "EXCEPTION: " << e.getMessage() << endl;
}
}
示例9: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankStats");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
std::string filename = options->getStr(STR_URI_INPUT);
//! [snippet16_bank]
// We get an instance of IBank from the URI.
IBank* bank = Bank::open (filename);
//! [snippet16_seq]
// We create an iterator on the bank
Iterator<Sequence>* it = bank->iterator();
// We iterate the sequences of the bank
for (it->first(); !it->isDone(); it->next())
{
// We get a shortcut on the current sequence and its data
Sequence& seq = it->item();
Data& data = seq.getData();
// We dump some information about the sequence.
std::cout << "comment " << seq.getComment() << std::endl;
// We dump each nucleotide. NOTE: the output depends on the data encoding
for (size_t i=0; i<data.size(); i++) { std::cout << data[i]; } std::cout << std::endl;
}
//! [snippet16_seq]
// The bank and the iterator have been allocated on the heap, so we have to delete them
delete it;
delete bank;
//! [snippet16_bank]
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
}
示例10: main
int main(int argc, const char * argv[])
{
OptionsParser parser;
if (parser.ParseOptions(argc, argv) < 0 || parser.m_Help) {
parser.Usage(argv[0]);
return -1;
}
if (parser.m_List) {
CPPUNIT_NS::Test *test = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
for (int i = 0; i < test->getChildTestCount(); i++) {
printf("test %s\n", test->getChildTestAt(i)->getName().c_str());
for (int j = 0; j < test->getChildTestAt(i)->getChildTestCount(); j++) {
printf("test %s\n", test->getChildTestAt(i)->getChildTestAt(j)->getName().c_str());
}
}
return 0;
}
CPPUNIT_NS::TestResult controller;
// Add a listener that colllects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener( &result );
// Add a listener that print dots as test run.
CPPUNIT_NS::BriefTestProgressListener progress;
controller.addListener( &progress );
CPPUNIT_NS::TestRunner runner;
// Add the single test to the test runner
if (parser.m_RunSingle) {
runner.addTest(
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest()->findTest(parser.m_TestName));
// Add the top suite to the test runner
} else {
runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
}
runner.run( controller );
// Print test in a compiler compatible format.
CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
outputter.write();
return result.wasSuccessful() ? 0 : 1;
}
示例11: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankStats");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
// We get information about the bank.
u_int64_t nbSequences=0, dataSize=0, seqMaxSize=0, seqMinSize=~0;
// We declare an input Bank and use it locally
IBank* inputBank = Bank::open (options->getStr(STR_URI_INPUT));
LOCAL (inputBank);
ProgressIterator<Sequence> it (*inputBank, "iterate");
for (it.first(); !it.isDone(); it.next())
{
Data& data = it.item().getData();
nbSequences ++;
if (data.size() > seqMaxSize) { seqMaxSize = data.size(); }
if (data.size() < seqMinSize) { seqMinSize = data.size(); }
dataSize += data.size ();
}
std::cout << "data size : " << dataSize << std::endl;
std::cout << "sequence number : " << nbSequences << std::endl;
std::cout << "sequence max size : " << seqMaxSize << std::endl;
std::cout << "sequence min size : " << seqMinSize << std::endl;
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
}
示例12: indent
/*********************************************************************
** METHOD :
** PURPOSE :
** INPUT :
** OUTPUT :
** RETURN :
** REMARKS :
*********************************************************************/
void OptionsHelpVisitor::visitOptionsParser (OptionsParser& object, size_t depth)
{
if (object.isVisible() == true)
{
/** We first look for the longest option name. */
nameMaxLen=0;
for (list<IOptionsParser*>::const_iterator it = object.getParsers().begin(); it != object.getParsers().end(); ++it)
{
if (!(*it)->getName().empty()) { nameMaxLen = std::max (nameMaxLen, (*it)->getName().size()); }
}
os << endl;
indent(os,depth) << "[" << object.getName() << " options]" << endl;
/** We loop over each known parser. */
for (list<IOptionsParser*>::const_iterator it = object.getParsers().begin(); it != object.getParsers().end(); ++it)
{
if ((*it)->isVisible()) { (*it)->accept (*this, depth+1); }
}
}
}
示例13: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("BankDump");
parser.push_back (new OptionOneParam (STR_URI_INPUT, "bank input", true));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** We dump the bank hierarchy. */
dump (Bank::open (options->getStr(STR_URI_INPUT)));
}
catch (OptionFailure& e)
{
return e.displayErrors (std::cout);
}
catch (Exception& e)
{
std::cerr << "EXCEPTION: " << e.getMessage() << std::endl;
}
}
示例14: main
int main (int argc, char* argv[])
{
/** We create a command line parser. */
OptionsParser parser ("bankgen");
const char* OUTPUT_PREFIX = "-out";
const char* SEQ_LEN = "-seq-len";
const char* READ_LEN = "-read-len";
const char* OVERLAP_LEN = "-overlap-len";
const char* COVERAGE = "-coverage";
parser.push_back (new OptionOneParam (OUTPUT_PREFIX, "output prefix", true));
parser.push_back (new OptionOneParam (SEQ_LEN, "sequence length", false, "1000000"));
parser.push_back (new OptionOneParam (READ_LEN, "read length", false, "150" ));
parser.push_back (new OptionOneParam (OVERLAP_LEN, "overlap between two reads", false, "50" ));
parser.push_back (new OptionOneParam (COVERAGE, "coverage", false, "3" ));
try
{
/** We parse the user options. */
IProperties* options = parser.parse (argc, argv);
/** We create the random sequence. */
IBank* randomBank = new BankRandom (1, options->getInt(SEQ_LEN));
LOCAL (randomBank);
/** We create the reads bank. */
IBank* readsBank = new BankSplitter (
randomBank,
options->getInt(READ_LEN),
options->getInt(OVERLAP_LEN),
options->getInt(COVERAGE)
);
LOCAL (readsBank);
/** We save the random bank. */
SaveAsFasta (randomBank, options->getStr(OUTPUT_PREFIX) + "_sequence.fa");
/** We save the reads bank. */
SaveAsFasta (readsBank, options->getStr(OUTPUT_PREFIX) + "_reads.fa");
}
catch (OptionFailure& e)
{
e.getParser().displayErrors (stdout);
e.getParser().displayHelp (stdout);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例15: main
int main(int argc, char* argv[])
{
OptionsParser options;
options.ReadArgs(argc, argv);
int result = options.HandleArgs();
if (result != OPTIONS_ERROR && result != OPTIONS_HELP)
{
EnigmaPlugin plugin;
plugin.Init();
plugin.LogMakeToConsole();
plugin.SetDefinitions(options.APIyaml().c_str());
Game game;
GameMode mode;
std::string _mode = options.GetOption("mode").as<std::string>();
if (_mode == "Compile")
mode = emode_compile;
else if (_mode == "Run")
mode = emode_run;
else if (_mode == "Debug")
mode = emode_debug;
else if (_mode == "Design")
mode = emode_design;
else if (_mode == "Rebuild")
mode = emode_rebuild;
bool _run = options.GetOption("run").as<bool>();
if (!_run) plugin.HandleGameLaunch();
return plugin.BuildGame(game.ConstructGame(), mode, options.GetOption("output").as<std::string>().c_str());
}
return result;
}