本文整理汇总了C++中ArgumentList::getSwitch方法的典型用法代码示例。如果您正苦于以下问题:C++ ArgumentList::getSwitch方法的具体用法?C++ ArgumentList::getSwitch怎么用?C++ ArgumentList::getSwitch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentList
的用法示例。
在下文中一共展示了ArgumentList::getSwitch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
bool verbose = false;
/* Argomenti passati all'eseguibile */
ArgumentList args = ArgumentList(argc, argv);
if ( argc < 2 || argc > 3 ) {
cerr << "Utilizzo: " << args.getFirst() << " [-v] <file_istanza_tsp>" << endl;
cerr << "\t-v : verboso." << endl << endl;
return -1;
}
else {
cout << args.getFirst() << endl;
}
/* Istanza del problema */
TSPInstance< w_type > *problema = new TSPInstance< w_type >;
/* Loader dell'istanza */
TSPReader< w_type > *reader = new TSPReader< w_type >(problema);
/* Nome del file da cui caricare l'istanza */
string filename = "";
/* Soluzione del problema */
vector< vertice * > *soluzione;
verbose = args.getSwitch("-v");
filename = args.getFirst();
reader->setInputFile(filename);
if ( ! reader->read() ) {
cerr << "Impossibile leggere l'istanza." << endl;
delete problema;
delete reader;
return -1;
}
if ( verbose ) {
cout << "Istanza caricata, sta per essere eseguito l'algoritmo di risoluzione." << endl;
}
soluzione = new vector< vertice * >;
christofides(problema->getGrafo(), soluzione);
stampaDimensioneCircuito(*soluzione);
cout << endl;
stampaCostoCircuito(*soluzione, *(problema->getGrafo()));
delete soluzione;
delete problema;
delete reader;
return 0;
}
示例2: main
int main(int argc, char *argv[])
{
ArgumentList *argList = new ArgumentList(argc, argv);
#if QT_VERSION < 0x050000
QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif
QString packagesToInstall;
QString arg;
for (int c=1; c<argc; c++)
{
arg = argv[c];
if (arg.contains("pkg.tar*"))
{
packagesToInstall += arg + ",";
}
}
QtSingleApplication app( StrConstants::getApplicationName(), argc, argv );
if (app.isRunning())
{
if (argList->getSwitch("-sysupgrade"))
{
app.sendMessage("SYSUPGRADE");
}
else if (argList->getSwitch("-sysupgrade-noconfirm"))
{
app.sendMessage("SYSUPGRADE_NOCONFIRM");
}
else if (argList->getSwitch("-close"))
{
app.sendMessage("CLOSE");
}
else if (argList->getSwitch("-hide"))
{
app.sendMessage("HIDE");
}
else if (!packagesToInstall.isEmpty())
{
app.sendMessage(packagesToInstall);
}
else
{
app.sendMessage("RAISE");
}
return 0;
}
//This sends a message just to awake the socket-based QtSingleApplication engine
app.sendMessage("RAISE");
QTranslator appTranslator;
appTranslator.load(":/resources/translations/octopi_" +
QLocale::system().name());
app.installTranslator(&appTranslator);
if (argList->getSwitch("-help")){
std::cout << StrConstants::getApplicationCliHelp().toLatin1().data() << std::endl;
return(0);
}
else if (argList->getSwitch("-version")){
std::cout << "\n" << StrConstants::getApplicationName().toLatin1().data() <<
" " << StrConstants::getApplicationVersion().toLatin1().data() << "\n" << std::endl;
return(0);
}
if (UnixCommand::isRootRunning() && !WMHelper::isKDERunning()){
QMessageBox::critical( 0, StrConstants::getApplicationName(), StrConstants::getErrorRunningWithRoot());
return ( -2 );
}
MainWindow w;
app.setActivationWindow(&w);
app.setQuitOnLastWindowClosed(false);
#if QT_VERSION < 0x050000
#ifndef NO_GTK_STYLE
if (!argList->getSwitch("-style"))
{
if (UnixCommand::getLinuxDistro() == ectn_MANJAROLINUX &&
(!WMHelper::isKDERunning() && (!WMHelper::isRazorQtRunning())))
{
app.setStyle(new QGtkStyle());
}
else if(UnixCommand::getLinuxDistro() != ectn_CHAKRA)
{
app.setStyle(new QCleanlooksStyle());
}
}
#endif
#endif
if (argList->getSwitch("-sysupgrade-noconfirm"))
{
w.setCallSystemUpgradeNoConfirm();
}
//.........这里部分代码省略.........
示例3: main
int main(int argc, char *argv[])
{
ArgumentList *argList = new ArgumentList(argc, argv);
QString packagesToInstall;
QString arg;
for (int c=1; c<argc; c++)
{
arg = argv[c];
if (arg.contains(QRegExp("pkg.tar.[gz|xz]")))
{
packagesToInstall += arg + ",";
}
}
QtSingleApplication app( StrConstants::getApplicationName(), argc, argv );
if (app.isRunning())
{
if (argList->getSwitch("-sysupgrade"))
{
app.sendMessage("SYSUPGRADE");
}
else if (argList->getSwitch("-sysupgrade-noconfirm"))
{
app.sendMessage("SYSUPGRADE_NOCONFIRM");
}
else if (argList->getSwitch("-close"))
{
app.sendMessage("CLOSE");
}
else if (argList->getSwitch("-hide"))
{
app.sendMessage("HIDE");
}
else if (!packagesToInstall.isEmpty())
{
app.sendMessage(packagesToInstall);
}
else
{
app.sendMessage("RAISE");
}
return 0;
}
else if (UnixCommand::isAppRunning("octopi", false))
return 0;
//This sends a message just to enable the socket-based QtSingleApplication engine
app.sendMessage("RAISE");
QTranslator appTranslator;
bool success = appTranslator.load(":/resources/translations/octopi_" +
QLocale::system().name());
if (!success)
{
appTranslator.load(":/resources/translations/octopi_en.qm");
}
app.installTranslator(&appTranslator);
if (argList->getSwitch("-help")) {
std::cout << StrConstants::getApplicationCliHelp().toLatin1().data() << std::endl;
return(0);
}
else if (argList->getSwitch("-version")) {
std::cout << "\n" << StrConstants::getApplicationName().toLatin1().data() <<
" " << StrConstants::getApplicationVersion().toLatin1().data() << "\n" << std::endl;
return(0);
}
if (UnixCommand::isRootRunning() && !WMHelper::isKDERunning()) {
QMessageBox::critical( 0, StrConstants::getApplicationName(), StrConstants::getErrorRunningWithRoot());
return ( -2 );
}
MainWindow w;
app.setActivationWindow(&w);
app.setQuitOnLastWindowClosed(false);
if (argList->getSwitch("-sysupgrade-noconfirm"))
{
w.setCallSystemUpgradeNoConfirm();
}
else if (argList->getSwitch("-sysupgrade"))
{
w.setCallSystemUpgrade();
}
if (argList->getSwitch("-d"))
{
//If user chooses to switch debug info on...
w.turnDebugInfoOn();
}
if (!packagesToInstall.isEmpty())
{
QStringList packagesToInstallList =
packagesToInstall.split(",", QString::SkipEmptyParts);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[]) {
bool verbose = false;
unsigned int distribuzione[21] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
double maxB = 0.5, minB = std::numeric_limits< double >::max(), averageB = 0, tempB = 1.0;
/* Argomenti passati all'eseguibile */
ArgumentList args = ArgumentList(argc, argv);
if ( argc < 2 || argc > 3 ) {
cerr << "Utilizzo: " << args.getFirst() << " [-v] <file_istanza_tsp>" << endl;
cerr << "\t-v : verboso." << endl << endl;
return -1;
}
else {
cout << endl << args.getFirst() << endl << endl;
}
/* Istanza del problema */
TSPInstance< w_type > *problema = new TSPInstance< w_type >;
/* Loader dell'istanza */
TSPReader< w_type > *reader = new TSPReader< w_type >(problema);
/* Nome del file da cui caricare l'istanza */
string filename = "";
istringstream converter;
verbose = args.getSwitch("-v");
filename = args.getFirst();
reader->setInputFile(filename);
if ( ! reader->read() ) {
cerr << "Impossibile leggere l'istanza." << endl;
delete problema;
delete reader;
return -1;
}
if ( verbose ) {
cout << "Istanza caricata, sta per essere eseguito l'algoritmo di calcolo della beta metricita' del grafo." << endl;
}
unsigned int counter = ((problema->getGrafo())->numVertici() * ((problema->getGrafo())->numVertici() - 1) * ((problema->getGrafo())->numVertici() - 2)) / 2;
for ( Grafo< w_type >::vertice_iterator x = (problema->getGrafo())->lista_vertici.begin(); x != --((problema->getGrafo())->lista_vertici.end()); x++ ) {
Grafo< w_type >::vertice_iterator temp = x;
for ( Grafo< w_type >::vertice_iterator y = ++temp; y != --((problema->getGrafo())->lista_vertici.end()); y++ ) {
temp = y;
for ( Grafo< w_type >::vertice_iterator z = ++temp; z != (problema->getGrafo())->lista_vertici.end(); z++ ) {
w_type xy = (problema->getGrafo())->getPesoArcoCompreso(*x, *y), xz = (problema->getGrafo())->getPesoArcoCompreso(*x, *z), yz = (problema->getGrafo())->getPesoArcoCompreso(*y, *z);
/* Primo vincolo */
tempB = 1.01;
while ( static_cast< double >(xy) < static_cast< double >(tempB * (xz + yz)) && tempB >= 0 ) {
tempB -= 0.01;
}
if ( tempB > maxB ) {
maxB = tempB;
}
if ( tempB < minB ) {
minB = tempB;
}
distribuzione[mappaDistribuzione(tempB)] += 1;
if ( mappaDistribuzione(tempB) != 20 ) {
averageB += tempB;
}
/* Secondo vincolo */
tempB = 1.01;
while ( static_cast< double >(xz) < static_cast< double >(tempB * (xy + yz)) && tempB >= 0 ) {
tempB -= 0.01;
}
if ( tempB > maxB ) {
maxB = tempB;
}
if ( tempB < minB ) {
minB = tempB;
}
distribuzione[mappaDistribuzione(tempB)] += 1;
if ( mappaDistribuzione(tempB) != 20 ) {
averageB += tempB;
}
/* Terzo vincolo */
tempB = 1.01;
while ( static_cast< double >(yz) < static_cast< double >(tempB * (xz + xy)) && tempB >= 0 ) {
tempB -= 0.01;
}
if ( tempB > maxB ) {
maxB = tempB;
}
if ( tempB < minB ) {
minB = tempB;
}
distribuzione[mappaDistribuzione(tempB)] += 1;
if ( mappaDistribuzione(tempB) != 20 ) {
averageB += tempB;
}
}
}
}
//.........这里部分代码省略.........
示例5: main
int main(int argc, char *argv[])
{
bool debugInfo = false;
ArgumentList *argList = new ArgumentList(argc, argv);
if (argList->getSwitch("-d"))
{
//If user chooses to switch debug info on...
debugInfo = true;
}
if (debugInfo)
qDebug() << QString("Octopi Notifier - " + StrConstants::getApplicationVersion() +
" (" + StrConstants::getQtVersion() + ")");
if (UnixCommand::isAppRunning("octopi-notifier"))
{
qDebug() << "Aborting notifier as another instance is already running!";
return (-1);
}
if (!QFile::exists(ctn_PACMANHELPER_BINARY))
{
qDebug() << "Aborting notifier as 'pacmanhelper' binary could not be found! [" << ctn_PACMANHELPER_BINARY << "]";
return (-2);
}
if (!QFile::exists(ctn_DBUS_PACMANHELPER_SERVICE))
{
qDebug() << "Aborting notifier as 'pacmanhelper' DBus service could not be found! [" << ctn_DBUS_PACMANHELPER_SERVICE << "]";
return (-3);
}
QApplication a(argc, argv);
#if QT_VERSION < 0x050000
#ifndef NO_GTK_STYLE
QApplication::setGraphicsSystem(QLatin1String("raster"));
if(!WMHelper::isKDERunning() && (!WMHelper::isLXQTRunning()) && (!WMHelper::isRazorQtRunning()))
{
qApp->setStyle(new QGtkStyle());
}
else
qApp->setStyle(new QCleanlooksStyle);
#endif
#endif
QTranslator appTranslator;
appTranslator.load(":/resources/translations/octopi_" +
QLocale::system().name());
a.installTranslator(&appTranslator);
a.setQuitOnLastWindowClosed(false);
MainWindow w;
QResource::registerResource("./resources.qrc");
if (debugInfo)
w.turnDebugInfoOn();
return a.exec();
}
示例6: main
int main(int argc, char *argv[]) {
unsigned int n = 0;
double beta = 0.0;
bool verbose = false, correggi = false, shortest = false, l1 = false, l2 = false, linf = false, endpoint = false, interval = false;
w_type maxPeso = 100000;
string outfile = "";
istringstream converter;
GrafoNonOrientatoBetaMetrico_ListaArchi< w_type > grafo;
TSPInstance< w_type > problema;
TSPWriter< w_type > *writer;
ArgumentList args = ArgumentList(argc, argv);
if ( argc < 7 || argc > 9 ) {
cerr << "Utilizzo: " << args.getFirst() << " [-c] [-v] [-s|-e|-l1|-l2|-li] -n <nodi> -b <beta> <outfile>" << endl;
cerr << "\t-c\t : correggi se non beta metrico;" << endl;
cerr << "\t-i\t : metrica intervallo (base, base*2beta);" << endl;
cerr << "\t-s\t : metrica shortest path;" << endl;
cerr << "\t-e\t : metrica endpoint;" << endl;
cerr << "\t-l1\t : metrica spazio l1;" << endl;
cerr << "\t-l2\t : metrica spazio l2;" << endl;
cerr << "\t-li\t : metrica spazio linf;" << endl;
cerr << "\t-v\t : verboso." << endl << endl;
return -1;
}
else {
cout << args.getFirst() << endl;
}
verbose = args.getSwitch("-v");
correggi = args.getSwitch("-c");
shortest = args.getSwitch("-s");
interval = args.getSwitch("-i");
endpoint = args.getSwitch("-e");
l1 = args.getSwitch("-l1");
l2 = args.getSwitch("-l2");
linf = args.getSwitch("-li");
converter.str(args.getSwitchArgument("-n"));
converter >> n;
converter.clear();
converter.str(args.getSwitchArgument("-b"));
converter >> beta;
if ( n < 2 || beta < 0.5 ) {
cerr << "Il numero di nodi del grafo dev'essere maggiore di 2 ed il valore di beta >= 0.5" << endl;
return -1;
}
outfile = args.getFirst();
grafo.clear();
problema.clear();
grafo.setBeta(beta);
srand(time(NULL));
if ( interval ) {
/* Metrica intervall (base, base*2beta) */
grafo.generaRandom(n);
}
else if ( shortest ) {
/* Metrica shortest path */
for ( unsigned int i(0); i < n; i++ ) {
vertice *temp = grafo.aggiungiVertice();
temp->setKey(i);
}
for ( Grafo< w_type >::vertice_iterator x = grafo.lista_vertici.begin(); x != --(grafo.lista_vertici.end()); x++ ) {
Grafo< w_type >::vertice_iterator temp = x;
for ( Grafo< w_type >::vertice_iterator y = ++temp; y != grafo.lista_vertici.end(); y++ ) {
grafo.aggiungiArco(*x, *y, static_cast< w_type >(1.0 + (maxPeso * (rand() / (RAND_MAX + 1.0)))));
}
}
map< pair<vertice*, vertice*>, w_type > distanze = FloydWarshall(grafo);
for ( Grafo< w_type >::vertice_iterator x = grafo.lista_vertici.begin(); x != --(grafo.lista_vertici.end()); x++ ) {
Grafo< w_type >::vertice_iterator temp = x;
for ( Grafo< w_type >::vertice_iterator y = ++temp; y != grafo.lista_vertici.end(); y++ ) {
if ( distanze[pair<vertice*, vertice*>(*x, *y)] < grafo.getPesoArcoCompreso(*x, *y) ) {
(grafo.getArcoCompreso(*x, *y))->costo = distanze[pair<vertice*, vertice*>(*x, *y)];
}
}
}
}
else if ( endpoint ) {
/* Metrica endpoint */
double beta = grafo.getBeta();
double betaC = (pow(beta, 2.0) - pow(1 - beta, 2.0)) / (beta * (1 - beta));
double betaN = (1 - beta) / beta;
double betaNx = beta / (1 - beta);
arco< w_type > *tempArco = 0, *minArco = 0, *maxArco = 0;
for ( unsigned int i(0); i < n; i++ ) {
vertice *temp = grafo.aggiungiVertice();
temp->setKey(i);
}
//.........这里部分代码省略.........
示例7: main
int main(int argc, char *argv[]) {
bool verbose = false;
unsigned int intervalli = 10;
/* Argomenti passati all'eseguibile */
ArgumentList args = ArgumentList(argc, argv);
if ( argc < 4 || argc > 5 ) {
cerr << "Utilizzo: " << args.getFirst() << " [-v] -k <intervalli> <file_istanza_tsp>" << endl;
cerr << "\t-k: numero di intervalli;" << endl;
cerr << "\t-v : verboso." << endl << endl;
return -1;
}
else {
cout << endl << args.getFirst() << endl << endl;
}
/* Istanza del problema */
TSPInstance< w_type > *problema = new TSPInstance< w_type >;
/* Loader dell'istanza */
TSPReader< w_type > *reader = new TSPReader< w_type >(problema);
/* Nome del file da cui caricare l'istanza */
string filename = "";
istringstream converter;
verbose = args.getSwitch("-v");
converter.str(args.getSwitchArgument("-k"));
converter >> intervalli;
filename = args.getFirst();
reader->setInputFile(filename);
if ( ! reader->read() ) {
cerr << "Impossibile leggere l'istanza." << endl;
delete problema;
delete reader;
return -1;
}
if ( verbose ) {
cout << "Istanza caricata, sta per essere eseguito l'algoritmo di calcolo della distribuzione dei pesi." << endl;
}
/* Mappa contenente gli intervalli di distribuzione dei pesi e le percentuali */
map< double, double > *distribuzione = new map< double, double >();
/* Dimensioni di un intervallo */
double dimBlocco = 0;
/* Peso minimo e massimo di un arco */
w_type min = std::numeric_limits< w_type >::max(), max = std::numeric_limits< w_type >::min();
for ( Grafo< w_type >::arco_const_iterator e = (problema->getGrafo())->lista_archi.begin(); e != (problema->getGrafo())->lista_archi.end(); e++ ) {
if ( (*e)->costo < min ) {
min = (*e)->costo;
}
if ( (*e)->costo > max ) {
max = (*e)->costo;
}
}
if ( verbose ) {
cout << "Il peso minimo di un arco e' " << min << " mentre il peso massimo e' " << max << endl;
}
dimBlocco = (max - min) / static_cast< double >(intervalli);
for ( unsigned int i(0); i <= intervalli; i++ ) {
distribuzione->insert(pair< double, unsigned int >(min + (i * dimBlocco), 0));
}
for ( Grafo< w_type >::arco_const_iterator e = (problema->getGrafo())->lista_archi.begin(); e != (problema->getGrafo())->lista_archi.end(); e++ ) {
for ( unsigned int i(1); i <= intervalli; i++ ) {
if ( min + (i * dimBlocco) > (*e)->costo ) {
((distribuzione->find(min + ((i - 1) * dimBlocco)))->second)++;
break;
}
}
}
for ( map< double, double >::iterator i = (distribuzione->begin())++; i != distribuzione->end(); i++ ) {
(*i).second = static_cast< double >(((*i).second * 100)) / (problema->getGrafo())->numArchi();
}
cout << endl;
for ( map< double, double >::iterator i = (distribuzione->begin())++; i != --(distribuzione->end()); i++ ) {
cout << fixed << setprecision (2) << "Da " << (*(--i)).first << " a " << (*(++i)).first << ": " << (*i).second << "%" << endl;
}
cout << endl;
return 0;
}