merge the two ELAM engines
authorKonrad Rosenbaum <konrad@silmor.de>
Wed, 21 Aug 2013 17:00:40 +0000 (19:00 +0200)
committerKonrad Rosenbaum <konrad@silmor.de>
Wed, 21 Aug 2013 17:00:40 +0000 (19:00 +0200)
src/misc/formula.cpp
src/misc/misc.pri
src/misc/msengine.cpp [deleted file]
src/misc/msengine.h [deleted file]
src/templates/odtrender.cpp

index 7a46a5a..98fa79c 100644 (file)
@@ -120,6 +120,7 @@ MElamEngine::MElamEngine(QObject* parent): Engine(parent)
        characterClasses().setNameClass(alpha,alpha+"0123456789.:");
        QString oc=characterClasses().operatorClass();
        characterClasses().setOperatorClass(oc.remove('.').remove(':'));
+        characterClasses().setAssignmentChars('\0','=');
        if(!characterClasses().isConsistent())
                qDebug()<<"Warning: built-in calculator is inconsistent.";
        //load default engines
@@ -128,6 +129,7 @@ MElamEngine::MElamEngine(QObject* parent): Engine(parent)
        BoolEngine::configureBoolEngine(*this);
        BoolEngine::configureLogicEngine(*this);
        StringEngine::configureStringEngine(*this);
+        configureReflection(*this);
        //add money class
        setFunction("toMoney",toMoneyFuncLoc);
        setFunction("toMoneyLocal",toMoneyFuncLoc);
@@ -139,6 +141,19 @@ MElamEngine::MElamEngine(QObject* parent): Engine(parent)
        setFunction("unix2date",unix2DateFunc);
        setFunction("unix2time",unix2TimeFunc);
        setFunction("unix2datetime",unix2DateTimeFunc);
+        //legacy functions for ODF renderer
+        setFunction("cent2str",[](const QList<QVariant>&args,Engine&)->QVariant{
+                if(args.size()!=1)
+                        return Exception(Exception::ArgumentListError,"expected one argument to cent2str");
+                else
+                        return cent2str(args[0].toInt());
+        });
+        setFunction("str2cent",[](const QList<QVariant>&args,Engine&)->QVariant{
+                if(args.size()!=1)
+                        return Exception(Exception::ArgumentListError,"expected one argument to str2cent");
+                else
+                        return str2cent(args[0].toString());
+        });
        //register casts for nullable
        setAutoCast(qMetaTypeId<qlonglong>(),
                QList<int>()
index 926a3c1..9739a91 100644 (file)
@@ -4,7 +4,6 @@ HEADERS += \
        $$PWD/waitcursor.h \
        $$PWD/sclock.h \
        $$PWD/formula.h \
-       $$PWD/msengine.h \
        $$PWD/dommodel.h
 
 SOURCES += \
@@ -14,7 +13,6 @@ SOURCES += \
        $$PWD/waitcursor.cpp \
        $$PWD/sclock.cpp \
        $$PWD/formula.cpp \
-       $$PWD/msengine.cpp \
        $$PWD/dommodel.cpp
 
 INCLUDEPATH += $$PWD
diff --git a/src/misc/msengine.cpp b/src/misc/msengine.cpp
deleted file mode 100644 (file)
index 833bd01..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-// C++ Implementation: MSmoke ELAM Engine
-//
-//
-// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2012
-//
-// Copyright: See README/COPYING.GPL files that come with this distribution
-//
-//
-
-#include "msengine.h"
-
-#include "misc.h"
-
-#include <ELAM/IntEngine>
-#include <ELAM/BoolEngine>
-#include <ELAM/FloatEngine>
-#include <ELAM/StringEngine>
-
-
-using namespace ELAM;
-
-MSEngine::MSEngine(QObject* parent)
-       :Engine(parent)
-{
-       IntEngine::configureIntEngine(*this);
-       StringEngine::configureStringEngine(*this);
-       BoolEngine::configureBoolEngine(*this);
-       BoolEngine::configureLogicEngine(*this);
-       FloatEngine::configureFloatEngine(*this);
-       configureReflection(*this);
-       setFunction("cent2str",[](const QList<QVariant>&args,Engine&)->QVariant{
-               if(args.size()!=1)
-                       return Exception(Exception::ArgumentListError,"expected one argument to cent2str");
-               else
-                       return cent2str(args[0].toInt());
-       });
-       setFunction("str2cent",[](const QList<QVariant>&args,Engine&)->QVariant{
-               if(args.size()!=1)
-                       return Exception(Exception::ArgumentListError,"expected one argument to str2cent");
-               else
-                       return str2cent(args[0].toString());
-       });
-       setFunction("unix2time",[](const QList<QVariant>&args,Engine&)->QVariant{
-               if(args.size()!=1)
-                       return Exception(Exception::ArgumentListError,"expected one argument to unix2time");
-               else
-                       return unix2time(args[0].toInt());
-       });
-       setFunction("unix2date",[](const QList<QVariant>&args,Engine&)->QVariant{
-               if(args.size()!=1)
-                       return Exception(Exception::ArgumentListError,"expected one argument to unix2date");
-               else
-                       return unix2date(args[0].toInt());
-       });
-       setFunction("unix2dateTime",[](const QList<QVariant>&args,Engine&)->QVariant{
-               if(args.size()!=1)
-                       return Exception(Exception::ArgumentListError,"expected one argument to unix2dateTime");
-               else
-                       return unix2dateTime(args[0].toInt());
-       });
-}
-
-void MSEngine::enableLoopVars()
-{
-       CharacterClassSettings ccs=characterClasses();
-       //simplify assignment
-       ccs.setAssignmentChars('\0','=');
-       //remove :. from operators
-       QString str=ccs.operatorClass();
-       str.remove(':');str.remove('.');
-       ccs.setOperatorClass(str);
-       //add :. to variables
-       QPair<QString,QString>nc=ccs.nameClass();
-       if(!nc.second.contains(':'))nc.second+=":";
-       if(!nc.second.contains('.'))nc.second+=".";
-       ccs.setNameClass(nc);
-}
diff --git a/src/misc/msengine.h b/src/misc/msengine.h
deleted file mode 100644 (file)
index a8ae434..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// C++ Interface: MSmoke Elam Engine with specialized functions
-//
-//
-// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2012
-//
-// Copyright: See README/COPYING.GPL files that come with this distribution
-//
-//
-
-#ifndef MAGICSMOKE_MSENGINE_H
-#define MAGICSMOKE_MSENGINE_H
-
-#include <ELAM/Engine>
-
-///convenience ELAM engine that comes preconfigured for all types and with special MSmoke functions
-class MSEngine:public ELAM::Engine
-{
-       public:
-               ///instantiate the engine
-               explicit MSEngine(QObject*parent=0);
-               
-               ///moves the ":." chars from the operator class to the variable class to enable the
-               ///loop variable syntax, assignment becomes a simple "="
-               void enableLoopVars();
-};
-
-#endif
index 1d3cf2c..18e8ba8 100644 (file)
 #include <Unzip>
 #include <Zip>
 
-#include "msengine.h"
+#include "formula.h"
 using namespace ELAM;
 
-class MOdfEngine:public MSEngine
+class MOdfEngine:public MElamEngine
 {
        MOdtRenderer*parent;
        public:
@@ -48,7 +48,7 @@ class MOdfEngine:public MSEngine
                        if(parent->getVariable(v).isValid())
                                return true;
                        else
-                               return MSEngine::hasConstant(v);
+                               return MElamEngine::hasConstant(v);
                }
                QVariant getConstant(QString v)const
                {
@@ -56,7 +56,7 @@ class MOdfEngine:public MSEngine
                        if(vv.isValid())
                                return vv;
                        else
-                               return MSEngine::getConstant(v);
+                               return MElamEngine::getConstant(v);
                }
 };