libelam.*
-src/Makefile*
+Makefile*
.ctmp
*~
doc/source/
+*.o
+*.obj
+tests/parser/parsertest
+tests/eval/evaltest
+moc_*
INCLUDEPATH += .
DEPENDPATH += .
+
+QMAKE_CXXFLAGS+=-std=gnu++0x
\ No newline at end of file
ret<<QPair<QString,QString>( QVariant::typeToName((QVariant::Type)k[i].first), QVariant::typeToName((QVariant::Type)k[i].second));
return ret;
}
-void BinaryOperator::removeCallback ( BinaryOperatorCall c)
-{
- QList<QPair<int,int> > k=d->callmap.keys();
- for(int i=0;i<k.size();i++)
- if(d->callmap[k[i]]==c)
- d->callmap.remove(k[i]);
-}
void BinaryOperator::removeCallback ( QString t1, QString t2)
{
removeCallback( QVariant::nameToType(t1.toAscii().data()), QVariant::nameToType(t2.toAscii().data()));
#include "../dptr/dptr_base.h"
+#include <functional>
+
namespace ELAM {
class Engine;
\param op2 the right operand
\param engine the engine calling the operator
\returns the result of the operation*/
-typedef QVariant (*BinaryOperatorCall)(const QVariant&op1,const QVariant&op2,Engine&engine);
+typedef std::function<QVariant(const QVariant&op1,const QVariant&op2,Engine&engine)>BinaryOperatorCall;
/** \brief Wraps a particular binary operator.
\param type the type of variable to work on, this must be a type registered with QVariant, if this type is already known to the operator its callback is replaced
*/
void setCallback(BinaryOperatorCall callback,int type1,int type2);
+
+ ///convenience override to make the use of overloaded function pointers easier
+ void setCallback(QVariant(*fp)(const QVariant&,const QVariant&,Engine&),QString type1,QString type2)
+ {setCallback(BinaryOperatorCall(fp),type1,type2);}
+ ///convenience override to make the use of overloaded function pointers easier
+ void setCallback(QVariant(*fp)(const QVariant&,const QVariant&,Engine&),int type1,int type2)
+ {setCallback(BinaryOperatorCall(fp),type1,type2);}
+
/**returns the callback function attached to the type or NULL if there is none*/
BinaryOperatorCall getCallback(QString type1,QString type2)const;
/**returns the callback function attached to the type or NULL if there is none*/
BinaryOperatorCall getCallback(int type1,int type2)const;
- /**removes all types attached to this callback from the operator*/
- void removeCallback(BinaryOperatorCall);
///removes the type from this operators list
void removeCallback(QString,QString);
///removes the type from this operators list
{
LiteralParser parser;
QString start;
- int prio;
+ int prio,parserid;
//this operator is reversed, so that highest prio is in element 0 after qSort
bool operator<(const LiteralParser_s&l2)const
{return prio>l2.prio;}
};
QList<LiteralParser_s>parsers;
+ int nextparserid;
QMap<QString,UnaryOperator>unary;
struct BinaryOperator_s {
BinaryOperator_s(int p=1){prio=p;}
};
QList<CastFunc_s>casts;
QList<int>primtypes;
+ Private():nextparserid(1){}
};
DEFINE_DPTR(Engine);
d->funcs.remove(n);
}
-bool Engine::setLiteralParser ( ELAM::LiteralParser parser, QString startchars, int prio )
+int Engine::setLiteralParser ( ELAM::LiteralParser parser, QString startchars, int prio )
{
//base check
- if(parser==0 || startchars=="" || prio<0 || prio>100)
- return false;
+ if(parser==nullptr || startchars.isEmpty() || prio<0 || prio>100)
+ return 0;
//search for existing entry
- for(int i=0;i<d->parsers.size();i++){
+/* for(int i=0;i<d->parsers.size();i++){
if(d->parsers[i].parser==parser){
d->parsers[i].start=startchars;
d->parsers[i].prio=prio;
return true;
}
- }
+ }*/
//none found: create new entry
Private::LiteralParser_s s;
s.parser=parser;
s.prio=prio;
s.start=startchars;
+ s.parserid=d->nextparserid++;
d->parsers<<s;
- return true;
+ return s.parserid;
}
-void Engine::removeLiteralParser ( ELAM::LiteralParser parser )
+void Engine::removeLiteralParser ( int parser )
{
for(int i=0;i<d->parsers.size();i++)
- if(d->parsers[i].parser==parser){
+ if(d->parsers[i].parserid==parser){
d->parsers.removeAt(i);
return;
}
#include "../dptr/dptr_base.h"
+#include <functional>
+
namespace ELAM {
\param args the list of arguments that was given to the function, the implementation must check for length and type of the arguments
\param engine the engine calling the function
*/
-typedef QVariant (*Function)(const QList<QVariant>&args,Engine&engine);
+typedef std::function<QVariant(const QList<QVariant>&args,Engine&engine)>Function;
/**wraps the parser routine for a literal
If the parser does not find a valid literal according to its rules it must return an empty string.
*/
-typedef QPair<QString,QVariant> (*LiteralParser)(const QString&expr,Engine&engine,int start);
+typedef std::function<QPair<QString,QVariant>(const QString&expr,Engine&engine,int start)>LiteralParser;
/**Wraps a cast function to convert various types into another type.
\param orig the original value of any type
\param engine the engine calling the cast
\returns the converted value that conforms to the expected type*/
-typedef QVariant (*TypeCast)(const QVariant&orig,const Engine&engine);
+typedef std::function<QVariant(const QVariant&orig,const Engine&engine)>TypeCast;
/**The calculation engine of .
\param parser pointer to the parser routine
\param startchars characters that the literal can start with, at least some of those characters must be part of the literalStart class, the ones which are not part of it will be ignored when recognizing a literal - if none are part of the class the literal cannot be used until the class changes
\param prio a value between 0 and 100, parsers with higher values are preferred over those with lower values if they share a start character
- \returns true if the parser is (re-)registered successfully, or false if:
+ \returns >0 if the parser is registered successfully, or 0 if:
- the parser is null
- the start characters are empty
- the priority is outside the allowed range (0<=prio<=100)
+ A return value >0 can be used as an ID to remove the parser again with removeLiteralParser(int) .
+
If a parser function is registered a second time the new registration overwrites the old registration.
*/
- bool setLiteralParser(LiteralParser parser,QString startchars,int prio=50);
+ int setLiteralParser(LiteralParser parser,QString startchars,int prio=50);
///removes a parser function
- void removeLiteralParser(LiteralParser parser);
+ void removeLiteralParser(int parserid);
///sets/overrides the priority of an operator, creating the operator if it does not exist yet
void setBinaryOperatorPrio(QString name,int prio);
setCallback(callback,QVariant::nameToType(type.toAscii().data()));
}
-void UnaryOperator::removeCallback(UnaryOperatorCall cb)
-{
- if(cb==0)return;
- QList<int>k=d->callmap.keys(cb);
- for(int i=0;i<k.size();i++)
- d->callmap.remove(k[i]);
-}
-
void UnaryOperator::removeCallback(QString t)
{
removeCallback(QVariant::nameToType(t.toAscii().data()));
#include "../dptr/dptr_base.h"
+#include <functional>
+
namespace ELAM {
class Engine;
\param op the operand to be worked on
\param engine the engine calling the operator
\returns the result of the operation*/
-typedef QVariant (*UnaryOperatorCall)(const QVariant&op,Engine&engine);
+typedef std::function<QVariant(const QVariant&op,Engine&engine)>UnaryOperatorCall;
/** \brief Wraps a particular unary operator.
\param type the type of variable to work on, this must be a type registered with QVariant, if this type is already known to the operator its callback is replaced
*/
void setCallback(UnaryOperatorCall callback,int type);
+
+ ///convenience overload to make the use of overloaded function pointers easier
+ void setCallback(QVariant(*fp)(const QVariant&,Engine&),int type)
+ {setCallback(UnaryOperatorCall(fp),type);}
+ ///convenience overload to make the use of overloaded function pointers easier
+ void setCallback(QVariant(*fp)(const QVariant&,Engine&),QString type)
+ {setCallback(UnaryOperatorCall(fp),type);}
/**returns the callback function attached to the type or NULL if there is none*/
UnaryOperatorCall getCallback(QString type)const;
/**returns the callback function attached to the type or NULL if there is none*/
UnaryOperatorCall getCallback(int type)const;
- /**removes all types attached to this callback from the operator*/
- void removeCallback(UnaryOperatorCall);
///removes the type from this operators list
void removeCallback(QString);
///removes the type from this operators list
LIBS += -L../.. -lelam
SOURCES += eval.cpp
-HEADERS += eval.h
\ No newline at end of file
+HEADERS += eval.h
+
+QMAKE_CXXFLAGS+=-std=gnu++0x
\ No newline at end of file
LIBS += -L../.. -lelam
SOURCES += parser.cpp
-HEADERS += parser.h
\ No newline at end of file
+HEADERS += parser.h
+
+QMAKE_CXXFLAGS+=-std=gnu++0x
\ No newline at end of file