# HG changeset patch # User insilmaril # Date 1217430366 0 # Node ID 2513e153d48107baaf61be1c4e1ef05eb6afe92a # Parent cf274b28e5fe996e37f7959a068e525b26a7a6de removed unnecessary line diff -r cf274b28e5fe -r 2513e153d481 options.cpp --- a/options.cpp Wed Jul 30 14:42:03 2008 +0000 +++ b/options.cpp Wed Jul 30 15:06:06 2008 +0000 @@ -1,7 +1,8 @@ #include "options.h" + #include +#include -#include using namespace std; @@ -11,12 +12,20 @@ name=""; sName=""; lName=""; - type=SwitchOption; + type=Switch; sarg=""; active=false; } -void Option::set(const QString &n, const OptionType &t, const QString &s, const QString &l) +Option::Option (const QString &n, const Type &t, const QString &s, const QString &l) +{ + sName="-"+s; + lName="--"+l; + type=t; + name=n; +} + +void Option::set(const QString &n, const Type &t, const QString &s, const QString &l) { sName="-"+s; lName="--"+l; @@ -27,7 +36,7 @@ QString Option::getName () { return name; } QString Option::getShort () { return sName; } QString Option::getLong() { return lName; } -OptionType Option::getType() { return type; } +Option::Type Option::getType() { return type; } void Option::setArg(const QString& s) { sarg=s; } QString Option::getArg() { return sarg; } void Option::setActive() { active=true; } @@ -38,13 +47,7 @@ int Options::parse() { - QStringList arglist; - int i=0; - while (iargc()) - { - arglist.append (qApp->argv()[i]); - i++; - } + QStringList arglist=qApp->arguments(); // Get program name progname=arglist.first(); @@ -52,51 +55,50 @@ // Work through rest of options bool isFile; - OptionList::iterator itopt; - QStringList::iterator itarg; - itarg=arglist.begin(); - while (itarg!=arglist.end()) + for (int i=0; i< arglist.size(); ++i) { isFile=true; - if ((*itarg).left(1)=="-") + if (arglist[i].left(1)=="-") { // Compare given option to all defined options - itopt=optlist.begin(); - while (itopt!=optlist.end()) + for (int j=0; j < optlist.size(); ++j) { - if ((*itarg)==(*itopt).getShort() || - (*itarg)==(*itopt).getLong()) + if (arglist.at(i)==optlist.value(j).getShort() || + arglist.at(i)==optlist.value(j).getLong()) { - (*itopt).setActive(); + optlist[j].setActive(); isFile=false; - if ((*itopt).getType()==StringOption) + if (optlist[j].getType()==Option::String) { - itarg++; - if (itarg==arglist.end()) + i++; + if (i==arglist.size()) { - cout << "Error: argument to option missing\n"; + qWarning ("Error: argument to option missing"); return 1; } - (*itopt).setArg (*itarg); + optlist[j].setArg (arglist[i]); isFile=false; } break; } - itopt++; } if (isFile) { - cout << "Error: Unknown argument "<<*itarg<