本文整理汇总了C++中CmdLineParser::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ CmdLineParser::parse方法的具体用法?C++ CmdLineParser::parse怎么用?C++ CmdLineParser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CmdLineParser
的用法示例。
在下文中一共展示了CmdLineParser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: param_map
/*!
*/
bool
Strategy::init( CmdLineParser & cmd_parser )
{
ParamMap param_map( "HELIOS_base options" );
// std::string fconf;
//param_map.add()
// ( "fconf", "", &fconf, "another formation file." );
//
//
//
if ( cmd_parser.count( "help" ) > 0 )
{
param_map.printHelp( std::cout );
return false;
}
//
//
//
cmd_parser.parse( param_map );
return true;
}
示例2:
/*!
*/
bool
SampleTrainer::initImpl( CmdLineParser & cmd_parser )
{
bool result = TrainerAgent::initImpl( cmd_parser );
#if 0
ParamMap my_params;
std::string formation_conf;
my_map.add()
( &conf_path, "fconf" )
;
cmd_parser.parse( my_params );
#endif
if ( cmd_parser.failed() )
{
std::cerr << "coach: ***WARNING*** detected unsupported options: ";
cmd_parser.print( std::cerr );
std::cerr << std::endl;
}
if ( ! result )
{
return false;
}
//////////////////////////////////////////////////////////////////
// Add your code here.
//////////////////////////////////////////////////////////////////
return true;
}
示例3: main
int main(int argc, char** argv)
{
cout << SectorVersionString << endl;
SlaveConf global_conf;
CmdLineParser clp;
clp.parse(argc, argv);
for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
{
if (i->first == "mh")
global_conf.m_strMasterHost = i->second;
else if (i->first == "mp")
global_conf.m_iMasterPort = atoi(i->second.c_str());
else if (i->first == "h")
{
global_conf.m_strHomeDir = i->second;
}
else if (i->first == "ds")
global_conf.m_llMaxDataSize = atoll(i->second.c_str()) * 1024 * 1024;
else if (i->first == "log")
global_conf.m_iLogLevel = atoi(i->second.c_str());
else
{
cout << "warning: unrecognized flag " << i->first << endl;
help();
}
}
string base = "";
if (clp.m_vParams.size() == 1)
base = clp.m_vParams.front();
else if (clp.m_vParams.size() > 1)
cout << "warning: wrong parameters ignored.\n";
Slave s;
if (s.init(&base, &global_conf) < 0)
{
cout << "error: failed to initialize the slave. check slave configurations.\n";
return-1;
}
if (s.connect() < 0)
{
cout << "error: failed to connect to the master, or the connection request is rejected.\n";
return -1;
}
s.run();
s.close();
return 0;
}
示例4: main
int main(int argc, char *argv[]) {
QCoreApplication app (argc, argv);
QTime time;
int duration;
CmdLineParser cmd (app.arguments());
CmdLineParser::Result res = cmd.parse();
if (res == CmdLineParser::Help)
return 0;
else if (res == CmdLineParser::Error)
return -1;
QString filename = cmd.file();
if (!QFile::exists ( filename )) {
qCritical ("The file you specified doesn't exist!");
exit (1);
}
Parser parser;
bool ok;
QFile file (filename);
time.start();
QVariant data = parser.parse (&file, &ok);
duration = time.elapsed();
if (!ok) {
qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
exit (1);
}
else {
qDebug() << "Parsing of" << filename << "took" << duration << "ms";
if (!cmd.quiet())
qDebug() << data;
}
if (cmd.serialize()) {
// serializer tests
qDebug() << "Serializing... ";
QJson::Serializer serializer;
serializer.setIndentMode(cmd.indentationMode());
time.start();
QByteArray b = serializer.serialize(data);
duration = time.elapsed();
qDebug() << "Serialization took:" << duration << "ms";
if (!cmd.quiet())
qDebug() << b;
}
qDebug() << "JOB DONE, BYE";
return 0;
}
示例5: get_cmd_line_parser
/**
* Creates a command line parser initialized with default values.
* @return a command line parser initialized with default values.
*/
CmdLineParser get_cmd_line_parser() {
CmdLineParser parser;
parser.add_legal("-h --help -L --list -v --verbose -V --version -a --all -f --conformity --conformity-format --max-time");
const int argc = 3;
const char *defaults[argc] = {
"--conformity-format=*Test|test_*|*",
"-f=%p::%n - %m (%ts)%N(Registered at %f:%l)",
"--max-time=1e+10",
};
parser.parse(argc, defaults);
CPUNIT_ITRACE("EntryPoint - Default arguments:"<<parser.to_string());
return parser;
}
示例6: my_params
/*!
*/
bool
SamplePlayer::initImpl( CmdLineParser & cmd_parser )
{
bool result = PlayerAgent::initImpl( cmd_parser );
// read additional options
result &= Strategy::instance().init( cmd_parser );
rcsc::ParamMap my_params( "Additional options" );
#if 0
std::string param_file_path = "params";
param_map.add()
( "param-file", "", ¶m_file_path, "specified parameter file" );
#endif
cmd_parser.parse( my_params );
if ( cmd_parser.count( "help" ) > 0 )
{
my_params.printHelp( std::cout );
return false;
}
if ( cmd_parser.failed() )
{
std::cerr << "player: ***WARNING*** detected unsuppprted options: ";
cmd_parser.print( std::cerr );
std::cerr << std::endl;
}
if ( ! result )
{
return false;
}
if ( ! Strategy::instance().read( config().configDir() ) )
{
std::cerr << "***ERROR*** Failed to read team strategy." << std::endl;
return false;
}
if ( KickTable::instance().read( config().configDir() + "/kick-table" ) )
{
std::cerr << "Loaded the kick table: ["
<< config().configDir() << "/kick-table]"
<< std::endl;
}
return true;
}
示例7: main
int main(int argc, char** argv)
{
cout << SectorVersionString << endl;
Sector client;
if (Utility::login(client) < 0)
return -1;
bool address = false;
CmdLineParser clp;
if (clp.parse(argc, argv) < 0)
{
help();
return -1;
}
for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
{
if (i->first == "a")
address = true;
else
{
help();
return -1;
}
}
for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
{
if (*i == "a")
address = true;
else
{
help();
return -1;
}
}
SysStat sys;
int result = client.sysinfo(sys);
if (result >= 0)
print(sys, address);
else
Utility::print_error(result);
Utility::logout(client);
return result;
}
示例8: main
int main(int argc, char** argv)
{
string sector_home;
if (ConfLocation::locate(sector_home) < 0)
{
cerr << "no Sector information located; nothing to stop.\n";
return -1;
}
string slaves_list = sector_home + "/conf/slaves.list";
bool force = false;
CmdLineParser clp;
clp.parse(argc, argv);
for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
{
if (i->first == "s")
slaves_list = i->second;
else
{
help();
return 0;
}
}
for (vector<string>::const_iterator i = clp.m_vSFlags.begin(); i != clp.m_vSFlags.end(); ++ i)
{
if ((*i == "f") || (*i == "force"))
force = true;
else
{
help();
return 0;
}
}
cout << "This will stop this master and all slave nodes by brutal forces. If you need a graceful shutdown, use ./tools/sector_shutdown.\n";
if (!force)
{
cout << "Do you want to continue? Y/N:";
char answer;
cin >> answer;
if ((answer != 'Y') && (answer != 'y'))
{
cout << "aborted.\n";
return -1;
}
}
示例9: main
int main(int argc, char** argv)
{
CmdLineParser clp;
if (clp.parse(argc, argv) <= 0)
{
help();
return -1;
}
int32_t id = 0;
string addr;
int32_t code = 0;
for (map<string, string>::iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
{
if (i->first == "i")
id = atoi(i->second.c_str());
else if (i->first == "d")
addr = i->second;
else if (i->first == "c")
code = atoi(i->second.c_str());
else
{
help();
return -1;
}
}
if (((id == 0) && (addr.c_str()[0] == 0))|| (code == 0))
{
help();
return -1;
}
Session s;
s.loadInfo("../conf/client.conf");
Client c;
if (c.init(s.m_ClientConf.m_strMasterIP, s.m_ClientConf.m_iMasterPort) < 0)
return -1;
string passwd = s.m_ClientConf.m_strPassword;
if (s.m_ClientConf.m_strUserName != "root")
{
cout << "please input root password:";
cin >> passwd;
}
示例10: config
/*!
*/
bool
SampleCoach::initImpl( CmdLineParser & cmd_parser )
{
bool result =CoachAgent::initImpl( cmd_parser );
#if 0
ParamMap my_params;
if ( cmd_parser.count( "help" ) )
{
my_params.printHelp( std::cout );
return false;
}
cmd_parser.parse( my_params );
#endif
if ( cmd_parser.failed() )
{
std::cerr << "coach: ***WARNING*** detected unsupported options: ";
cmd_parser.print( std::cerr );
std::cerr << std::endl;
}
if ( ! result )
{
return false;
}
//////////////////////////////////////////////////////////////////
// Add your code here.
//////////////////////////////////////////////////////////////////
if ( config().useTeamGraphic() )
{
if ( config().teamGraphicFile().empty() )
{
M_team_graphic.createXpmTiles( team_logo_xpm );
}
else
{
M_team_graphic.readXpmFile( config().teamGraphicFile().c_str() );
}
}
return true;
}
示例11: main
int main(int argc, char *argv[]) {
QCoreApplication app (argc, argv);
CmdLineParser cmd (app.arguments());
CmdLineParser::Result res = cmd.parse();
if (res == CmdLineParser::Help)
return 0;
else if (res == CmdLineParser::Error)
return -1;
QString filename = cmd.file();
if (!QFile::exists ( filename )) {
qCritical ("The file you specified doesn't exist!");
exit (1);
}
Parser parser;
bool ok;
QFile file (filename);
QVariant data = parser.parse (&file, &ok);
if (!ok) {
qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
exit (1);
}
else {
qDebug() << "json object successfully converted to:";
qDebug() << data;
}
if (cmd.serialize()) {
// serializer tests
qDebug() << "Serialization output";
QJson::Serializer serializer;
serializer.setIndentMode(cmd.indentationMode());
QByteArray b = serializer.serialize(data);
qDebug() << b;
}
qDebug() << "JOB DONE, BYE";
return 0;
}
示例12: main
int main(int argc, char * argv[])
{
using namespace lyx;
lyxerr.setStream(cerr);
char const * const lyxsocket = getenv("LYXSOCKET");
if (lyxsocket)
cmdline::serverAddress = from_local8bit(lyxsocket);
CmdLineParser args;
args.helper["-h"] = cmdline::h;
args.helper["-c"] = cmdline::c;
args.helper["-g"] = cmdline::g;
args.helper["-n"] = cmdline::n;
args.helper["-a"] = cmdline::a;
args.helper["-t"] = cmdline::t;
args.helper["-p"] = cmdline::p;
// Command line failure conditions:
if ((!args.parse(argc, argv))
|| (args.isset["-c"] && args.isset["-g"])
|| (args.isset["-a"] && args.isset["-p"])) {
cmdline::usage();
return 1;
}
scoped_ptr<LyXDataSocket> server;
if (!cmdline::serverAddress.empty()) {
server.reset(new LyXDataSocket(FileName(to_utf8(cmdline::serverAddress))));
if (!server->connected()) {
cerr << "lyxclient: " << "Could not connect to "
<< to_utf8(cmdline::serverAddress) << endl;
return EXIT_FAILURE;
}
} else {
// We have to look for an address.
// serverPid can be empty.
FileNameList addrs = lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid);
FileNameList::const_iterator addr = addrs.begin();
FileNameList::const_iterator end = addrs.end();
for (; addr != end; ++addr) {
// Caution: addr->string() is in filesystem encoding
server.reset(new LyXDataSocket(*addr));
if (server->connected())
break;
lyxerr << "lyxclient: " << "Could not connect to "
<< addr->absFileName() << endl;
}
if (addr == end) {
lyxerr << "lyxclient: No suitable server found."
<< endl;
return EXIT_FAILURE;
}
cerr << "lyxclient: " << "Connected to " << addr->absFileName() << endl;
}
int const serverfd = server->fd();
IOWatch iowatch;
iowatch.addfd(serverfd);
// Used to read from server
string answer;
// Send greeting
server->writeln("HELLO:" + to_utf8(cmdline::clientName));
// wait at most 2 seconds until server responds
iowatch.wait(2.0);
if (iowatch.isset(serverfd) && server->readln(answer)) {
if (prefixIs(answer, "BYE:")) {
cerr << "lyxclient: Server disconnected." << endl;
cout << answer << endl;
return EXIT_FAILURE;
}
} else {
cerr << "lyxclient: No answer from server." << endl;
return EXIT_FAILURE;
}
if (args.isset["-g"] || args.isset["-c"]) {
server->writeln(to_utf8(cmdline::singleCommand));
iowatch.wait(2.0);
if (iowatch.isset(serverfd) && server->readln(answer)) {
cout << answer;
if (prefixIs(answer, "ERROR:"))
return EXIT_FAILURE;
return EXIT_SUCCESS;
} else {
cerr << "lyxclient: No answer from server." << endl;
return EXIT_FAILURE;
}
}
// Take commands from stdin
iowatch.addfd(0); // stdin
bool saidbye = false;
while ((!saidbye) && server->connected()) {
iowatch.wait();
if (iowatch.isset(0)) {
//.........这里部分代码省略.........
示例13: main
int main(int argc, char* argv[]) {
int ctThreads = tbb::task_scheduler_init::default_num_threads();
tbb::task_scheduler_init init(ctThreads);
cout << "started tbb with " << ctThreads << " threads." << endl;
//parser
g_parser.addSwitch("--disjoint", "-d", "converts splitted part to disjoint meshes", "0");
g_parser.addSwitch("--ringscalpel", "-r", "If the switch presents then the ring scalpel will be used");
g_parser.addSwitch("--verbose", "-v", "prints detailed description.");
g_parser.addSwitch("--input", "-i", "[filepath] set input file in vega format", "internal");
//g_parser.addSwitch("--example", "-e", "[one, two, cube, eggshell] set an internal example", "two");
//g_parser.addSwitch("--gizmo", "-g", "loads a file to set gizmo location and orientation", "gizmo.ini");
if(g_parser.parse(argc, argv) < 0)
exit(0);
//file path
g_strIniFilePath = AnsiStr(g_parser.value("input").c_str());
if(FileExists(g_strIniFilePath))
vloginfo("input file: %s.", g_strIniFilePath.cptr());
else {
vlogerror("Unable to find input filepath: [%s]", g_strIniFilePath.cptr());
exit(1);
}
//GLFW LIB
g_lpWindow = NULL;
glfwSetErrorCallback(error_callback);
if (!glfwInit()) {
vlogerror("Failed to init glfw");
exit(EXIT_FAILURE);
}
/*
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
*/
g_lpWindow = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "tetcutter - Pourya Shirazian", NULL, NULL);
if (!g_lpWindow)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(g_lpWindow);
glfwSwapInterval(1);
glfwSetKeyCallback(g_lpWindow, key_callback);
glfwSetCursorPosCallback(g_lpWindow, mouse_motion_callback);
glfwSetMouseButtonCallback(g_lpWindow, mouse_button_callback);
glfwSetScrollCallback(g_lpWindow, scroll_callback);
//init gl
def_initgl();
//Build Shaders for drawing the mesh
IniFile ini(g_strIniFilePath, IniFile::fmRead);
AnsiStr strRoot = ini.readString("system", "data");
AnsiStr strShaderRoot = strRoot + "shaders/";
AnsiStr strTextureRoot = strRoot + "textures/";
AnsiStr strFontsRoot = strRoot + "fonts/";
//convert mesh
// AnsiStr strNodesFP = strRoot + AnsiStr("data/meshes/matlab/nodes.txt");
// AnsiStr strFacesFP = strRoot + AnsiStr("data/meshes/matlab/faces.txt");
// AnsiStr strCellsFP = strRoot + AnsiStr("data/meshes/matlab/cells.txt");
// VolMeshIO::convertMatlabTextToVega(strNodesFP, strFacesFP, strCellsFP);
//Load Shaders
TheShaderManager::Instance().addFromFolder(strShaderRoot.cptr());
//Load Textures
TheTexManager::Instance().add(strTextureRoot + "wood.png");
TheTexManager::Instance().add(strTextureRoot + "spin.png");
TheTexManager::Instance().add(strTextureRoot + "icefloor.png");
// TheTexManager::Instance().add(strTextureRoot + "rendermask.png");
// TheTexManager::Instance().add(strTextureRoot + "maskalpha.png");
// TheTexManager::Instance().add(strTextureRoot + "maskalphafilled.png");
vloginfo("Floor show is set to: [%d]", ini.readBool("visible", "floor"));
//Ground and Room
SGQuad* floor = new SGQuad(16.0f, 16.0f, TheTexManager::Instance().get("icefloor"));
floor->setName("floor");
floor->transform()->translate(vec3f(0, -0.1f, 0));
floor->transform()->rotate(vec3f(1.0f, 0.0f, 0.0f), 90.0f);
floor->setVisible(ini.readBool("visible", "floor"));
TheEngine::Instance().add(floor);
//Create Scalpel
g_lpScalpel = new AvatarScalpel();
g_lpScalpel->setVisible(false);
g_lpRing = new AvatarRing(TheTexManager::Instance().get("spin"));
//.........这里部分代码省略.........
示例14: main
/**
* Forward your program parameters directly from main to this function to start CPUnit.
*
* @param argc The number of arguments, including the program name.
* @param args The program arguments, including the program name.
* @return 0 if all tests succeed, and >0 elsewise.
*/
int main(const int argc, const char **args) {
CmdLineParser parser = get_cmd_line_parser();
parser.parse(argc-1, args+1);
return main(parser);
}
示例15: main
int main(int argc, char** argv)
{
if (argc < 2)
{
help();
return -1;
}
unsigned int thresh = 65536;
int timeout = 3600 * 24; // default wait for one day
CmdLineParser clp;
if (clp.parse(argc, argv) < 0)
{
help();
return -1;
}
for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
{
if (i->first == "w")
thresh = atoi(i->second.c_str());
else if (i->first == "t")
{
timeout = atoi(i->second.c_str());
if (timeout < 0)
timeout = INT_MAX;
}
else
{
help();
return -1;
}
}
Sector client;
if (Utility::login(client) < 0)
return -1;
list<string> filelist;
for (vector<string>::iterator i = clp.m_vParams.begin(); i < clp.m_vParams.end(); ++ i)
{
vector<string> fl;
fl.clear();
bool wc = WildCard::isWildCard(*i);
if (!wc)
{
SNode attr;
if (client.stat(*i, attr) < 0)
{
cerr << "ERROR: source file does not exist.\n";
return -1;
}
getFileList(*i, fl, client, thresh);
}
else
{
string path = *i;
string orig = path;
size_t p = path.rfind('/');
if (p == string::npos)
path = "/";
else
{
path = path.substr(0, p);
orig = orig.substr(p + 1, orig.length() - p);
}
vector<SNode> filelist;
int r = client.list(path, filelist);
if (r < 0)
cerr << "ERROR: " << r << " " << SectorError::getErrorMsg(r) << endl;
for (vector<SNode>::iterator i = filelist.begin(); i != filelist.end(); ++ i)
{
if (WildCard::match(orig, i->m_strName))
getFileList(path + "/" + i->m_strName, fl, client, thresh);
}
}
filelist.insert(filelist.end(), fl.begin(), fl.end());
}
int result = -1;
timeval t;
gettimeofday(&t, NULL);
int exp_time = t.tv_sec + timeout;
int interval = 1;
int total = -1;
int new_total = 0;
while (!filelist.empty())
{
new_total = 0;
for (list<string>::iterator i = filelist.begin(); i != filelist.end();)
//.........这里部分代码省略.........