comparison ops
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 25 Jul 2011 13:15:51 +0000 (13:15 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 25 Jul 2011 13:15:51 +0000 (13:15 +0000)
git-svn-id: https://silmor.de/svn/softmagic/elam/trunk@750 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/elamfloatengine.cpp
src/elamintengine.cpp
src/elamstringengine.cpp

index a09554a..0216b0d 100644 (file)
@@ -94,6 +94,32 @@ static QVariant floatDiv(const QVariant &o1,const QVariant &o2,Engine&)
        return o1.toDouble()/d2;
 }
 
+static QVariant fltLt(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toDouble()<o2.toDouble();
+}
+static QVariant fltGt(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toDouble()>o2.toDouble();
+}
+static QVariant fltLe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toDouble()<=o2.toDouble();
+}
+static QVariant fltGe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toDouble()>=o2.toDouble();
+}
+static QVariant fltEq(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toDouble()==o2.toDouble();
+}
+static QVariant fltNe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toDouble()!=o2.toDouble();
+}
+
+
 static QVariant floatFunc(const QList<QVariant>&lf,Engine&)
 {
        if(lf.size()!=1)
@@ -125,6 +151,24 @@ void FloatEngine::configureFloatEngine(ELAM::Engine& eng)
        eng.unaryOperator("-").setCallback(floatMinus,fid);
        eng.unaryOperator("+").setCallback(floatPlus,fid);
        //binary
+        eng.binaryOperator("==",60).setCallback(fltEq,fid,fid);
+        eng.binaryOperator("==").setCallback(fltEq,fid,iid);
+        eng.binaryOperator("==").setCallback(fltEq,iid,fid);
+        eng.binaryOperator("!=",60).setCallback(fltNe,fid,fid);
+        eng.binaryOperator("!=").setCallback(fltNe,iid,fid);
+        eng.binaryOperator("!=").setCallback(fltNe,fid,iid);
+        eng.binaryOperator("<=",60).setCallback(fltLe,fid,fid);
+        eng.binaryOperator("<=").setCallback(fltLe,fid,iid);
+        eng.binaryOperator("<=").setCallback(fltLe,iid,fid);
+        eng.binaryOperator(">=",60).setCallback(fltGe,fid,fid);
+        eng.binaryOperator(">=").setCallback(fltGe,iid,fid);
+        eng.binaryOperator(">=").setCallback(fltGe,fid,iid);
+        eng.binaryOperator("<",60).setCallback(fltLt,fid,fid);
+        eng.binaryOperator("<").setCallback(fltLt,iid,fid);
+        eng.binaryOperator("<").setCallback(fltLt,fid,iid);
+        eng.binaryOperator(">",60).setCallback(fltGt,fid,fid);
+        eng.binaryOperator(">").setCallback(fltGt,iid,fid);
+        eng.binaryOperator(">").setCallback(fltGt,fid,iid);
        eng.binaryOperator("-",80).setCallback(floatMinus,fid,fid);
        eng.binaryOperator("-").setCallback(floatMinus,iid,fid);
        eng.binaryOperator("-").setCallback(floatMinus,fid,iid);
index 26e6ff3..f050df9 100644 (file)
@@ -102,6 +102,31 @@ static QVariant intNot(const QVariant&o,Engine&)
        return ~o.toLongLong();
 }
 
+static QVariant intLt(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toLongLong()<o2.toLongLong();
+}
+static QVariant intGt(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toLongLong()>o2.toLongLong();
+}
+static QVariant intLe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toLongLong()<=o2.toLongLong();
+}
+static QVariant intGe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toLongLong()>=o2.toLongLong();
+}
+static QVariant intEq(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toLongLong()==o2.toLongLong();
+}
+static QVariant intNe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toLongLong()!=o2.toLongLong();
+}
+
 
 int IntEngine::intParserPrio()
 {
@@ -123,6 +148,12 @@ void IntEngine::configureIntEngine(ELAM::Engine& eng)
        eng.unaryOperator("+").setCallback(intPlus,iid);
        eng.unaryOperator("~").setCallback(intNot,iid);
        //binaries
+        eng.binaryOperator("==",60).setCallback(intEq,iid,iid);
+        eng.binaryOperator("!=",60).setCallback(intNe,iid,iid);
+        eng.binaryOperator("<=",60).setCallback(intLe,iid,iid);
+        eng.binaryOperator(">=",60).setCallback(intGe,iid,iid);
+        eng.binaryOperator("<",60).setCallback(intLt,iid,iid);
+        eng.binaryOperator(">",60).setCallback(intGt,iid,iid);
        eng.binaryOperator("-",80).setCallback(intMinus,iid,iid);
        eng.binaryOperator("+",80).setCallback(intAdd,iid,iid);
        eng.binaryOperator("*",90).setCallback(intMult,iid,iid);
index 8ec10c4..559fb15 100644 (file)
@@ -143,6 +143,17 @@ static QVariant strAdd(const QVariant&o1,const QVariant&o2,Engine&)
        return o1.toString()+o2.toString();
 }
 
+//compare
+static QVariant strEq(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toString()==o2.toString();
+}
+static QVariant strNe(const QVariant&o1,const QVariant&o2,Engine&)
+{
+        return o1.toString()!=o2.toString();
+}
+
+
 int StringEngine::stringParserPrio()
 {
        return 50;
@@ -163,7 +174,13 @@ void StringEngine::configureStringEngine(Engine& eng)
        eng.setFunction("strlen",strlenFunc);
        eng.setFunction("concat",concatFunc);
        //operators
+        eng.binaryOperator("==",60).setCallback(strEq,sid,sid);
+        eng.binaryOperator("==").setCallback(strEq,aid,sid);
+        eng.binaryOperator("==").setCallback(strEq,sid,aid);
+        eng.binaryOperator("!=",60).setCallback(strNe,sid,sid);
+        eng.binaryOperator("!=").setCallback(strNe,sid,aid);
+        eng.binaryOperator("!=").setCallback(strNe,aid,sid);
        eng.binaryOperator("+",80).setCallback(strAdd,sid,sid);
-       eng.binaryOperator("+",80).setCallback(strAdd,aid,sid);
-       eng.binaryOperator("+",80).setCallback(strAdd,sid,aid);
+       eng.binaryOperator("+").setCallback(strAdd,aid,sid);
+       eng.binaryOperator("+").setCallback(strAdd,sid,aid);
 }