本文整理汇总了C++中CmdLineArgs类的典型用法代码示例。如果您正苦于以下问题:C++ CmdLineArgs类的具体用法?C++ CmdLineArgs怎么用?C++ CmdLineArgs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CmdLineArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseArgs
bool ConsoleExampleRunner::parseArgs(const CmdLineArgs &args) {
unsigned int length = args.GetCount();
for(unsigned int i = 0; i < length; ++i) {
std::string arg = args.GetArg(i);
if (arg != "-r") {
m_exampleName = arg;
}
else {
if (i+1 < length) {
++i;
m_rendererName = args.GetArg(i);
}
else
{
showError("missing argument for parameter -r");
return false;
}
}
}
if (m_rendererName.empty())
m_rendererName = m_defaultRendererName;
return true;
}
示例2: main
int main(int argc, char **argv)
{
const QString errorstr = "Fatal error from the ALSA sequencer. "
"This usually happens when the kernel doesn't have ALSA support, "
"or the device node (/dev/snd/seq) doesn't exists, "
"or the kernel module (snd_seq) is not loaded. "
"Please check your ALSA/MIDI configuration.";
CmdLineArgs args;
args.setUsage("[port]");
args.addOptionalArgument("port", "Source MIDI port");
args.parse(argc, argv);
try {
test = new QDumpMIDI();
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
QVariant portName = args.getArgument("port");
if (!portName.isNull())
test->subscribe(portName.toString());
test->run();
} catch (const SequencerError& ex) {
cerr << errorstr + " Returned error was: " + ex.qstrError() << endl;
} catch (...) {
cerr << errorstr << endl;
}
delete test;
return 0;
}
示例3: load
TreeMapArgs TreeMapArgs::load(CmdLineArgs& argv) {
TreeMapArgs tool_args;
if (!argv.empty()) {
tool_args.map_nameid = argv[0];
argv = argv.subspan(1);
}
return tool_args;
}
示例4: main
int main()
{
CmdLineArgs javaArgs;
javaArgs.push_back("checkSignature");
javaArgs.push_back(std::string(pk));
javaArgs.push_back(std::string(msg));
javaArgs.push_back(std::string(res));
std::string signVerificationMsg =
getCommandOutPut("/usr/bin/java", javaArgs, NULL, 0);
std::cout << signVerificationMsg << std::endl;
return 0;
}
示例5: getString
int getString(CmdLineArgs a, int idx, TCHAR* str){
int iRet=0;
if(a.size()<idx+1)
return 0;
wcscpy(a[idx+1], str);
return wcslen(str);
}
示例6: main
int main(int argc, char **argv)
{
const QString errorstr = "Fatal error from the ALSA sequencer. "
"This usually happens when the kernel doesn't have ALSA support, "
"or the device node (/dev/snd/seq) doesn't exists, "
"or the kernel module (snd_seq) is not loaded. "
"Please check your ALSA/MIDI configuration.";
CmdLineArgs args;
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
args.setUsage("[options] port [bpm]");
args.addRequiredArgument("port", "Destination, MIDI port identifier");
args.addOptionalArgument("bpm", "Tempo, in beats per minute (default=120)");
args.parse(argc, argv);
try {
metronome = new Metronome();
QVariant port = args.getArgument("port");
if (!port.isNull())
metronome->subscribe(port.toString());
QVariant bpm = args.getArgument("bpm");
metronome->play(bpm.toString());
} catch (const SequencerError& ex) {
cerr << errorstr + " Returned error was: " + ex.qstrError() << endl;
} catch (...) {
cerr << errorstr << endl;
}
delete metronome;
return 0;
}
示例7: ATLAS_RunIfOnCmdLine
// starts the Atlas UI if an "-editor" switch is found on the command line.
// this is the alternative to starting the main menu and clicking on
// the editor button; it is much faster because it's called during early
// init and therefore skips GUI setup.
// notes:
// - GUI init still runs, but some GUI setup will be skipped since
// ATLAS_IsRunning() will return true.
bool ATLAS_RunIfOnCmdLine(const CmdLineArgs& args, bool force)
{
if (force || args.Has("editor"))
{
ATLAS_Run(args, ATLAS_NO_GUI);
return true;
}
return false;
}
示例8: home
Paths::Paths(const CmdLineArgs& args)
{
m_root = Root(args.GetArg0());
#ifdef INSTALLED_DATADIR
m_rdata = OsPath(STRINGIZE(INSTALLED_DATADIR))/"";
#else
m_rdata = m_root/"data"/"";
#endif
const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad";
// everything is a subdirectory of the root
if(!subdirectoryName)
{
m_data = m_rdata;
m_config = m_data/"config"/"";
m_cache = m_data/"cache"/"";
m_logs = m_root/"logs"/"";
}
else
{
#if OS_WIN
const OsPath appdata = wutil_AppdataPath() / subdirectoryName/"";
m_data = appdata/"data"/"";
m_config = appdata/"config"/"";
m_cache = appdata/"cache"/"";
m_logs = appdata/"logs"/"";
#else
const char* envHome = getenv("HOME");
ENSURE(envHome);
const OsPath home(envHome);
const OsPath xdgData = XDG_Path("XDG_DATA_HOME", home, home/".local/share/") / subdirectoryName;
const OsPath xdgConfig = XDG_Path("XDG_CONFIG_HOME", home, home/".config/" ) / subdirectoryName;
const OsPath xdgCache = XDG_Path("XDG_CACHE_HOME", home, home/".cache/" ) / subdirectoryName;
m_data = xdgData/"";
m_cache = xdgCache/"";
m_config = xdgConfig/"config"/"";
m_logs = xdgConfig/"logs"/"";
#endif
}
}
示例9: main
int main(int argc, char *argv[])
{
int rc = 0;
CmdLineArgs check;
DbMigrat dbMigrat;
Db db;
// check the command line arguments
rc = check.CmdLineArgsCheck1(argc, argv, db);
if (rc != 0)
{
return rc;
}
cout << "\nTHIS SAMPLE SHOWS HOW TO MIGRATE A DATABASE." << endl;
dbMigrat.Migrate(db);
return 0;
} // main
示例10: main
int main(int argc, char *argv[])
{
QSpyWrk spy;
CmdLineArgs args;
args.setUsage("[options] file");
args.addOption('v', "verbose", "Verbose output");
args.addRequiredArgument("file", "Input WRK file name");
args.parse(argc, argv);
QVariant verbose = args.getOption("verbose");
if (!verbose.isNull())
spy.setVerbosity(true);
QVariantList files = args.getArguments("file");
QStringList fileNames;
foreach(const QVariant& a, files) {
QFileInfo f(a.toString());
if (f.exists())
fileNames += f.canonicalFilePath();
else
cout << "File not found: " << a.toString() << endl;
}
示例11: ProcessCommandLineArgs
static void ProcessCommandLineArgs(const CmdLineArgs& args)
{
// TODO: all these options (and the ones processed elsewhere) should
// be documented somewhere for users.
// Handle "-conf=key:value" (potentially multiple times)
std::vector<CStr> conf = args.GetMultiple("conf");
for (size_t i = 0; i < conf.size(); ++i)
{
CStr name_value = conf[i];
if (name_value.Find(':') != -1)
{
CStr name = name_value.BeforeFirst(":");
CStr value = name_value.AfterFirst(":");
g_ConfigDB.SetValueString(CFG_COMMAND, name, value);
}
}
if (args.Has("g"))
{
g_Gamma = args.Get("g").ToFloat();
if (g_Gamma == 0.0f)
g_Gamma = 1.0f;
}
// if (args.Has("listfiles"))
// trace_enable(true);
if (args.Has("profile"))
g_ConfigDB.SetValueString(CFG_COMMAND, "profile", args.Get("profile"));
if (args.Has("quickstart"))
{
g_Quickstart = true;
g_DisableAudio = true; // do this for backward-compatibility with user expectations
}
if (args.Has("nosound"))
g_DisableAudio = true;
if (args.Has("shadows"))
g_ConfigDB.SetValueString(CFG_COMMAND, "shadows", "true");
if (args.Has("xres"))
g_ConfigDB.SetValueString(CFG_COMMAND, "xres", args.Get("xres"));
if (args.Has("yres"))
g_ConfigDB.SetValueString(CFG_COMMAND, "yres", args.Get("yres"));
if (args.Has("vsync"))
g_ConfigDB.SetValueString(CFG_COMMAND, "vsync", "true");
if (args.Has("ooslog"))
g_ConfigDB.SetValueString(CFG_COMMAND, "ooslog", "true");
if (args.Has("serializationtest"))
g_ConfigDB.SetValueString(CFG_COMMAND, "serializationtest", "true");
}
示例12: getCommandOutPut
std::string getCommandOutPut(const std::string& cmd, CmdLineArgs& cmdArgs,
unsigned char* stdinput, const unsigned stdinputlength)
{
int outfd[2];
int infd[2];
int oldstdin, oldstdout;
pipe(outfd); // Where the parent is going to write to
pipe(infd); // From where parent is going to read
oldstdin = dup(0); // Save current stdin
oldstdout = dup(1); // Save stdout
close(0);
close(1);
dup2(outfd[0], 0); // Make the read end of outfd pipe as stdin
dup2(infd[1], 1); // Make the write end of infd as stdout
if(!fork()) {
//std::cerr<< "No. of cmd args : " << cmdArgs.size() << std::endl;
char **argv = new char*[2 + cmdArgs.size()];
argv[0] = (char*) cmd.c_str();
int i = 1;
for(CmdLineArgs::iterator itr = cmdArgs.begin(); itr != cmdArgs.end(); ++itr) {
argv[i++] = (char*) itr->c_str();
std::cerr << "Arg : \n" << itr->c_str() << "\n";
}
argv[i] = 0;
close(outfd[0]); // Not required for the child
close(outfd[1]);
close(infd[0]);
close(infd[1]);
execv(argv[0],argv);
}
else {
close(0); close(1);
dup2(oldstdin, 0);
dup2(oldstdout, 1);
close(outfd[0]); // These are being used by the child
close(infd[1]);
if( stdinput && stdinputlength ) {
write(outfd[1],stdinput, stdinputlength ); // Write to childâs stdin
close(outfd[1]);
}
char input[1024] = { 0 };
int bytesRead = 0;
std::string retVal;
while( bytesRead = read(infd[0], input, 1024) ) {
retVal += std::string(input);
memset(input, 0, sizeof(input));
}
//char input[1024] = { 0 };
//input[read(infd[0], input, 1024)] = 0; // Read from childâs stdout
//std::string retVal(input);
return retVal;
}
}
示例13: if
void CNWNX2App::parseNWNCmdLine()
{
CmdLineArgs args;
for (int i = 0; i < args.size(); i++)
{
if (stricmp(args[i], "-port") == 0)
{
dlg.m_intServerPort = atoi(args[i+1]);
i++;
}
else if (stricmp(args[i], "-module") == 0)
{
dlg.m_strModuleName = args[i+1];
i++;
}
else if (stricmp(args[i], "-processwatchdog") == 0)
{
if (atoi(args[i+1]) == 0)
dlg.m_boolWatchdogProcess = false;
else
dlg.m_boolWatchdogProcess = true;
i++;
}
else if (stricmp(args[i], "-processinterval") == 0)
{
dlg.m_intUpdateIntervalProcess = atoi(args[i+1]);
i++;
}
else if (stricmp(args[i], "-gamespywatchdog") == 0)
{
if (atoi(args[i+1]) == 0)
dlg.m_boolWatchdogGamespy = false;
else
dlg.m_boolWatchdogGamespy = true;
i++;
}
else if (stricmp(args[i], "-gamespyinterval") == 0)
{
dlg.m_intUpdateIntervalGamespy = atoi(args[i+1]);
i++;
}
else if (stricmp(args[i], "-gamespyretries") == 0)
{
dlg.m_intGamespyRetries = atoi(args[i+1]);
i++;
}
else if (stricmp(args[i], "-oldgamespyprotocol") == 0)
{
if (atoi(args[i+1]) == 1)
dlg.m_boolOldGamespyProtocol = true;
i++;
}
else if (stricmp(args[i], "-publicserver") == 0)
{
if (atoi(args[i+1]) == 0)
dlg.m_boolWatchdogGamespy = false;
strcat(cmdline, args[i]);
strcat(cmdline, " ");
}
else if (stricmp(args[i], "-restartdelay") == 0)
{
dlg.m_intRestartDelay = atoi(args[i+1]);
i++;
}
else
{
strcat(cmdline, args[i]);
strcat(cmdline, " ");
}
}
char port[6];
itoa(dlg.m_intServerPort, port, 10);
strcat(cmdline, "-port ");
strcat(cmdline, port);
if (dlg.m_strModuleName != "")
{
strcat(cmdline, " -module ");
strcat(cmdline, dlg.m_strModuleName);
}
}
示例14: main
int main(int argc, char* argv[])
{
int NoProtect = 0;
AllowLinear = true;
double MaxMSE = 4.0;
CmdLineArgs args;
if (args.size() == 1)
{
Usage();
return 1;
}
const char* InputDir = NULL;
const char* OutputFilename = "Textures.xpr";
for (unsigned int i = 1; i < args.size(); ++i)
{
if (!stricmp(args[i], "-help") || !stricmp(args[i], "-h") || !stricmp(args[i], "-?"))
{
Usage();
return 1;
}
else if (!stricmp(args[i], "-input") || !stricmp(args[i], "-i"))
{
InputDir = args[++i];
}
else if (!stricmp(args[i], "-output") || !stricmp(args[i], "-o"))
{
OutputFilename = args[++i];
}
else if (!stricmp(args[i], "-noprotect") || !stricmp(args[i], "-p"))
{
NoProtect = 1;
}
else if (!stricmp(args[i], "-onlyswizzled") || !stricmp(args[i], "-s"))
{
AllowLinear = false;
}
else if (!stricmp(args[i], "-quality") || !stricmp(args[i], "-q"))
{
++i;
if (!stricmp(args[i], "min"))
{
MaxMSE = DBL_MAX;
}
else if (!stricmp(args[i], "low"))
{
MaxMSE = 20.0;
}
else if (!stricmp(args[i], "normal"))
{
MaxMSE = 4.0;
}
else if (!stricmp(args[i], "high"))
{
MaxMSE = 1.5;
}
else if (!stricmp(args[i], "max"))
{
MaxMSE = 0.0;
}
else
{
printf("Unrecognised quality setting: %s\n", args[i]);
}
}
else
{
printf("Unrecognised command line flag: %s\n", args[i]);
}
}
// Initialize DirectDraw
pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if (pD3D == NULL)
{
puts("Cannot init D3D");
return 1;
}
HRESULT hr;
D3DDISPLAYMODE dispMode;
D3DPRESENT_PARAMETERS presentParams;
pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dispMode);
ZeroMemory(&presentParams, sizeof(presentParams));
presentParams.Windowed = TRUE;
presentParams.hDeviceWindow = GetConsoleWindow();
presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
presentParams.BackBufferWidth = 8;
presentParams.BackBufferHeight = 8;
presentParams.BackBufferFormat = dispMode.Format;
hr = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &pD3DDevice);
if (FAILED(hr))
{
printf("Cannot init D3D device: %08x\n", hr);
//.........这里部分代码省略.........
示例15: home
Paths::Paths(const CmdLineArgs& args)
{
m_root = Root(args.GetArg0());
m_rdata = RootData(args.GetArg0());
const char* subdirectoryName = args.Has("writableRoot")? 0 : "0ad";
if(!subdirectoryName)
{
// Note: if writableRoot option is passed to the game, then
// all the data is a subdirectory of the root
m_gameData = m_rdata;
m_userData = m_gameData;
m_config = m_gameData / "config"/"";
m_cache = m_gameData / "cache"/"";
m_logs = m_root / "logs"/"";
}
else // OS-specific path handling
{
#if OS_ANDROID
const OsPath appdata = OsPath("/sdcard/0ad/appdata");
// We don't make the game vs. user data distinction on Android
m_gameData = appdata/"data"/"";
m_userData = m_gameData;
m_config = appdata/"config"/"";
m_cache = appdata/"cache"/"";
m_logs = appdata/"logs"/"";
#elif OS_WIN
/* For reasoning behind our Windows paths, see the discussion here:
* http://www.wildfiregames.com/forum/index.php?showtopic=14759
*
* Summary:
* 1. Local appdata: for bulky unfriendly data like the cache,
* which can be recreated if deleted; doesn't need backing up.
* 2. Roaming appdata: for slightly less unfriendly data like config
* files that might theoretically be shared between different
* machines on a domain.
* 3. Personal / My Documents: for data explicitly created by the user,
* and which should be visible and easily accessed. We use a non-
* localized My Games subfolder for improved organization.
*/
// %localappdata%/0ad/
const OsPath localAppdata = wutil_LocalAppdataPath() / subdirectoryName/"";
// %appdata%/0ad/
const OsPath roamingAppData = wutil_RoamingAppdataPath() / subdirectoryName/"";
// My Documents/My Games/0ad/
const OsPath personalData = wutil_PersonalPath() / "My Games" / subdirectoryName/"";
m_cache = localAppdata / "cache"/"";
m_gameData = roamingAppData / "data"/"";
m_userData = personalData/"";
m_config = roamingAppData / "config"/"";
m_logs = localAppdata / "logs"/"";
#elif OS_MACOSX
/* For reasoning behind our OS X paths, see the discussion here:
* http://www.wildfiregames.com/forum/index.php?showtopic=15511
*
* Summary:
* 1. Application Support: most data associated with the app
* should be stored here, with few exceptions (e.g. temporary
* data, cached data, and managed media files).
* 2. Caches: used for non-critial app data that can be easily
* regenerated if this directory is deleted. It is not
* included in backups by default.
*
* Note: the paths returned by osx_Get*Path are not guaranteed to exist,
* but that's OK since we always create them on demand.
*/
// We probably want to use the same subdirectoryName regardless
// of whether running a bundle or from SVN. Apple recommends using
// company name, bundle name or bundle identifier.
OsPath appSupportPath; // ~/Library/Application Support/0ad
OsPath cachePath; // ~/Library/Caches/0ad
{
std::string path = osx_GetAppSupportPath();
ENSURE(!path.empty());
appSupportPath = OsPath(path) / subdirectoryName;
}
{
std::string path = osx_GetCachesPath();
ENSURE(!path.empty());
cachePath = OsPath(path) / subdirectoryName;
}
// We don't make the game vs. user data distinction on OS X
m_gameData = appSupportPath /"";
m_userData = m_gameData;
m_cache = cachePath/"";
m_config = appSupportPath / "config"/"";
//.........这里部分代码省略.........