diff -r 053b8645e3e9 -r 67cfa6e6b863 api.cpp --- a/api.cpp Wed Oct 18 10:45:00 2006 +0000 +++ b/api.cpp Tue Oct 24 15:36:38 2006 +0000 @@ -11,13 +11,13 @@ { com=""; paramList.clear(); - errorString=""; - noErr=true; + resetError(); } -void API::parseCommand (const QString &s) +void API::parseInput (const QString &s) { initCommand(); + input=s; QRegExp re; int pos; @@ -75,32 +75,76 @@ return paramList; } -QString API::errorDesc() +int API::paramCount() { - return errorString; + return paramList.count(); } -bool API::error() + +QString API::errorMessage() { - // invert noErr - return (noErr) ?false:true; + QString l; + switch (errLevel) + { + case NoError: l="No Error"; + case Warning: l="Warning"; + case Aborted: l="Aborted"; + } + return QString ("Error Level: %1\n Command: %2\nDescription: %3") + .arg(l).arg(com).arg(errDescription); } -void API::setError(const QString &e) +QString API::errorDescription() { - noErr=false; - errorString=e; + return errDescription; +} + +ErrorLevel API::errorLevel() +{ + return errLevel; +} + +void API::setError(ErrorLevel level, const QString &description) +{ + errDescription=description; + errLevel=level; +} + +void API::resetError () +{ + errMessage=""; + errDescription=""; + errLevel=NoError; +} + + +bool API::checkParamCount (QList plist) +{ + QStringList expList; + QString expected; + for (int i=0; i paramList.count()) { - errorString =QString("Parameter index %1 is outside of parameter list").arg(index); - noErr=false; + errLevel=Aborted; + errDescription=QString("Parameter index %1 is outside of parameter list").arg(index); + return false; } else { paramList[index].toInt (&ok, 10); if (!ok) { - errorString=QString("Parameter %1 is not an integer").arg(index); - noErr=false; - } else - noErr=true; + errLevel=Aborted; + errDescription=QString("Parameter %1 is not an integer").arg(index); + return false; + } } - return noErr; + return true; } int API::parInt (bool &ok,const uint &index) @@ -145,3 +190,26 @@ ok=true; return r; } + +bool API::parBool (bool &ok,const int &index) +{ + // return the bool at index, this could be also stored in + // a variable later + QString r; + ok=true; + /* + QRegExp re("\"(.*)\""); + int pos=re.search (paramList[index]); + if (pos>=0) + r=re.cap (1); + else + r=""; + */ + if (paramList[index]=="true") + return true; + else if (paramList[index]=="false") + return false; + ok=false; + return ok; +} +