diff -r 5db8dfd30ea2 -r c2a05fa925a1 options.cpp --- a/options.cpp Thu Nov 23 16:18:26 2006 +0000 +++ b/options.cpp Fri Dec 08 20:18:56 2006 +0000 @@ -1,7 +1,8 @@ #include "options.h" + #include +#include -#include using namespace std; @@ -16,6 +17,14 @@ active=false; } +Option::Option (const QString &n, const OptionType &t, const QString &s, const QString &l) +{ + sName="-"+s; + lName="--"+l; + type=t; + name=n; +} + void Option::set(const QString &n, const OptionType &t, const QString &s, const QString &l) { sName="-"+s; @@ -40,7 +49,7 @@ { QStringList arglist; int i=0; - while (iargc()) + while ( i < qApp->argc()) { arglist.append (qApp->argv()[i]); i++; @@ -52,37 +61,32 @@ // Work through rest of options bool isFile; - OptionList::iterator itopt; - QStringList::iterator itarg; - itarg=arglist.begin(); - while (itarg!=arglist.end()) + for (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()==StringOption) { - 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) { @@ -90,12 +94,16 @@ return 1; } } else - filelist.append (*itarg); - itarg++; + filelist.append (arglist[i]); } return 0; } +void Options::add (Option o) +{ + optlist.append (o); +} + void Options::add (const QString &n, const OptionType &t=SwitchOption, const QString &s="", const QString &l="") { Option o; @@ -125,20 +133,15 @@ bool Options::isOn(const QString &s) { - OptionList::iterator it; - for ( it = optlist.begin(); it != optlist.end(); ++it ) - if ((*it).getName()==s && (*it).isActive() ) + for (int i=0; i