# HG changeset patch
# User insilmaril
# Date 1122114389 0
# Node ID fd7f08a85971f4778e7583138a87e390ac2e0568
# Parent  16b250a57c1730019468be3ea50f5b925a04c69c
updated api.*

diff -r 16b250a57c17 -r fd7f08a85971 api.cpp
--- a/api.cpp	Fri Jul 22 15:38:06 2005 +0000
+++ b/api.cpp	Sat Jul 23 10:26:29 2005 +0000
@@ -2,11 +2,22 @@
 
 #include <qregexp.h>
 
-void API::parseCommand (const QString &s,QString &command,QString
-&param)
+API::API()
 {
-	param="";
-	command="";
+	initCommand();
+}
+
+void API::initCommand()
+{
+	com="";
+	paramList.clear();
+	errorString="";
+	noErr=true;
+}
+
+void API::parseCommand (const QString &s)
+{
+	initCommand();
 	QRegExp re;
 	int pos;
 
@@ -15,24 +26,95 @@
 	re.setMinimal (true);
 	pos=re.search (s);
 	if (pos>=0)
-		command=re.cap(1);
+		com=re.cap(1);
 
 	// Get parameters
 	re.setPattern ("\\((.*)\\)");
 	pos=re.search (s);
 	if (pos>=0)
-		param=re.cap (1);
+	{
+		QString s=re.cap(1);
+		paramList=QStringList::split(",",s);
+	}	
 }
 
-void API::getString (const QString &s, QString &rs)
+QString API::command()
 {
-	// return the string in s, this could be also stored in
+	return com;
+}
+
+QStringList API::parameters()
+{
+	return paramList;
+}
+
+QString API::errorDesc()
+{
+	return errorString;
+}
+
+bool API::error()
+{
+	// invert noErr
+	return (noErr) ?false:true;
+}
+
+void API::setError(const QString &e)
+{
+	noErr=false;
+	errorString=e;
+}
+
+bool API::checkParamCount (const uint &expected)
+{
+	if (paramList.count()!=expected)
+	{
+		errorString=QString("expected %1 parameters, but got %2").arg(expected).arg(paramList.count());
+		return false;
+	} 
+	return true;
+}
+
+bool API::checkParamIsInt(const uint &index)
+{
+	bool ok;
+	if (index > paramList.count())
+	{
+		errorString =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);
+			return false;
+		}
+		return true;
+	}	
+}
+
+int API::parInt (bool &ok,const uint &index)
+{
+	if (checkParamIsInt (index))
+	{
+		return paramList[index].toInt (&ok, 10);
+	}
+	ok=false;
+	return 0;
+}
+
+QString API::parString (bool &ok,const uint &index)
+{
+	// return the string at index, this could be also stored in
 	// a variable later
+	QString r;
 	QRegExp re("\"(.*)\"");
-	int pos=re.search (s);
+	int pos=re.search (paramList[index]);
 	if (pos>=0)
-		rs=re.cap (1);
+		r=re.cap (1);
 	else	
-		rs="";
-
-}
\ No newline at end of file
+		r="";
+	ok=true;
+	return r;
+}