1.1 --- a/options.cpp Tue Jun 06 14:58:11 2006 +0000
1.2 +++ b/options.cpp Wed Apr 25 16:02:54 2007 +0000
1.3 @@ -1,7 +1,8 @@
1.4 #include "options.h"
1.5 +
1.6 #include <iostream>
1.7 +#include <QApplication>
1.8
1.9 -#include <qapplication.h>
1.10
1.11 using namespace std;
1.12
1.13 @@ -16,6 +17,14 @@
1.14 active=false;
1.15 }
1.16
1.17 +Option::Option (const QString &n, const OptionType &t, const QString &s, const QString &l)
1.18 +{
1.19 + sName="-"+s;
1.20 + lName="--"+l;
1.21 + type=t;
1.22 + name=n;
1.23 +}
1.24 +
1.25 void Option::set(const QString &n, const OptionType &t, const QString &s, const QString &l)
1.26 {
1.27 sName="-"+s;
1.28 @@ -40,7 +49,7 @@
1.29 {
1.30 QStringList arglist;
1.31 int i=0;
1.32 - while (i<qApp->argc())
1.33 + while ( i < qApp->argc())
1.34 {
1.35 arglist.append (qApp->argv()[i]);
1.36 i++;
1.37 @@ -52,37 +61,32 @@
1.38
1.39 // Work through rest of options
1.40 bool isFile;
1.41 - OptionList::iterator itopt;
1.42 - QStringList::iterator itarg;
1.43 - itarg=arglist.begin();
1.44 - while (itarg!=arglist.end())
1.45 + for (i=0; i< arglist.size(); ++i)
1.46 {
1.47 isFile=true;
1.48 - if ((*itarg).left(1)=="-")
1.49 + if (arglist[i].left(1)=="-")
1.50 {
1.51 // Compare given option to all defined options
1.52 - itopt=optlist.begin();
1.53 - while (itopt!=optlist.end())
1.54 + for (int j=0; j < optlist.size(); ++j)
1.55 {
1.56 - if ((*itarg)==(*itopt).getShort() ||
1.57 - (*itarg)==(*itopt).getLong())
1.58 + if (arglist.at(i)==optlist.value(j).getShort() ||
1.59 + arglist.at(i)==optlist.value(j).getLong())
1.60 {
1.61 - (*itopt).setActive();
1.62 + optlist[j].setActive();
1.63 isFile=false;
1.64 - if ((*itopt).getType()==StringOption)
1.65 + if (optlist[j].getType()==StringOption)
1.66 {
1.67 - itarg++;
1.68 - if (itarg==arglist.end())
1.69 + i++;
1.70 + if (i==arglist.size())
1.71 {
1.72 - cout << "Error: argument to option missing\n";
1.73 + qWarning ("Error: argument to option missing");
1.74 return 1;
1.75 }
1.76 - (*itopt).setArg (*itarg);
1.77 + optlist[j].setArg (arglist[i]);
1.78 isFile=false;
1.79 }
1.80 break;
1.81 }
1.82 - itopt++;
1.83 }
1.84 if (isFile)
1.85 {
1.86 @@ -90,12 +94,16 @@
1.87 return 1;
1.88 }
1.89 } else
1.90 - filelist.append (*itarg);
1.91 - itarg++;
1.92 + filelist.append (arglist[i]);
1.93 }
1.94 return 0;
1.95 }
1.96
1.97 +void Options::add (Option o)
1.98 +{
1.99 + optlist.append (o);
1.100 +}
1.101 +
1.102 void Options::add (const QString &n, const OptionType &t=SwitchOption, const QString &s="", const QString &l="")
1.103 {
1.104 Option o;
1.105 @@ -125,20 +133,15 @@
1.106
1.107 bool Options::isOn(const QString &s)
1.108 {
1.109 - OptionList::iterator it;
1.110 - for ( it = optlist.begin(); it != optlist.end(); ++it )
1.111 - if ((*it).getName()==s && (*it).isActive() )
1.112 + for (int i=0; i<optlist.size(); ++i)
1.113 + if (optlist[i].getName()==s && optlist[i].isActive() )
1.114 return true;
1.115 return false;
1.116 }
1.117
1.118 QString Options::getArg(const QString &s)
1.119 {
1.120 - OptionList::iterator it;
1.121 - for ( it = optlist.begin(); it != optlist.end(); ++it )
1.122 - {
1.123 - if ((*it).getName()==s)
1.124 - return (*it).getArg();
1.125 - }
1.126 - return "";
1.127 + for (int i=0; i<optlist.size(); ++i)
1.128 + if (optlist[i].getName()==s) return optlist[i].getArg();
1.129 + return QString();
1.130 }