From 3bbb4e08e25332bd1823a65e5ca9c3ca86a10b27 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Wed, 1 Feb 2012 19:03:41 +0100 Subject: [PATCH] add C++11 support; add some more ignore patterns to ignore generated unit tests --- .gitignore | 7 ++++++- src/elam.pro | 2 ++ src/elambinary.cpp | 7 ------- src/elambinary.h | 14 +++++++++++--- src/elamengine.cpp | 21 ++++++++++++--------- src/elamengine.h | 16 ++++++++++------ src/elamunary.cpp | 8 -------- src/elamunary.h | 13 ++++++++++--- tests/eval/eval.pro | 4 +++- tests/parser/parser.pro | 4 +++- 10 files changed, 57 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index ef87747..76a0152 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ libelam.* -src/Makefile* +Makefile* .ctmp *~ doc/source/ +*.o +*.obj +tests/parser/parsertest +tests/eval/evaltest +moc_* diff --git a/src/elam.pro b/src/elam.pro index 03d8718..982c04b 100644 --- a/src/elam.pro +++ b/src/elam.pro @@ -35,3 +35,5 @@ SOURCES += \ INCLUDEPATH += . DEPENDPATH += . + +QMAKE_CXXFLAGS+=-std=gnu++0x \ No newline at end of file diff --git a/src/elambinary.cpp b/src/elambinary.cpp index 7a7d182..2687ab1 100644 --- a/src/elambinary.cpp +++ b/src/elambinary.cpp @@ -91,13 +91,6 @@ QList< QPair< QString, QString > > BinaryOperator::getTypeNames() const ret<( QVariant::typeToName((QVariant::Type)k[i].first), QVariant::typeToName((QVariant::Type)k[i].second)); return ret; } -void BinaryOperator::removeCallback ( BinaryOperatorCall c) -{ - QList > k=d->callmap.keys(); - for(int i=0;icallmap[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())); diff --git a/src/elambinary.h b/src/elambinary.h index 63d426a..6166f45 100644 --- a/src/elambinary.h +++ b/src/elambinary.h @@ -12,6 +12,8 @@ #include "../dptr/dptr_base.h" +#include + namespace ELAM { class Engine; @@ -20,7 +22,7 @@ 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::functionBinaryOperatorCall; /** \brief Wraps a particular binary operator. @@ -46,13 +48,19 @@ class BinaryOperator \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 diff --git a/src/elamengine.cpp b/src/elamengine.cpp index c7b7dc2..824637a 100644 --- a/src/elamengine.cpp +++ b/src/elamengine.cpp @@ -23,12 +23,13 @@ class DPTR_CLASS_NAME(Engine):public DPtr { 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;} }; QListparsers; + int nextparserid; QMapunary; struct BinaryOperator_s { BinaryOperator_s(int p=1){prio=p;} @@ -45,6 +46,7 @@ class DPTR_CLASS_NAME(Engine):public DPtr }; QListcasts; QListprimtypes; + Private():nextparserid(1){} }; DEFINE_DPTR(Engine); @@ -244,32 +246,33 @@ void Engine::removeFunction(QString n) 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;iparsers.size();i++){ +/* for(int i=0;iparsers.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<parsers.size();i++) - if(d->parsers[i].parser==parser){ + if(d->parsers[i].parserid==parser){ d->parsers.removeAt(i); return; } diff --git a/src/elamengine.h b/src/elamengine.h index 9e45738..76c4d86 100644 --- a/src/elamengine.h +++ b/src/elamengine.h @@ -17,6 +17,8 @@ #include "../dptr/dptr_base.h" +#include + namespace ELAM { @@ -31,7 +33,7 @@ Functions must check their arguments for validity before they start calculating. \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&args,Engine&engine); +typedef std::function&args,Engine&engine)>Function; /**wraps the parser routine for a literal @@ -44,13 +46,13 @@ The string representation of the literal must be verbatim from expr, so that the If the parser does not find a valid literal according to its rules it must return an empty string. */ -typedef QPair (*LiteralParser)(const QString&expr,Engine&engine,int start); +typedef std::function(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::functionTypeCast; /**The calculation engine of . @@ -179,16 +181,18 @@ class Engine:public QObject \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); diff --git a/src/elamunary.cpp b/src/elamunary.cpp index 2fbbf19..3cfef6e 100644 --- a/src/elamunary.cpp +++ b/src/elamunary.cpp @@ -100,14 +100,6 @@ void UnaryOperator::setCallback(UnaryOperatorCall callback, QString type) setCallback(callback,QVariant::nameToType(type.toAscii().data())); } -void UnaryOperator::removeCallback(UnaryOperatorCall cb) -{ - if(cb==0)return; - QListk=d->callmap.keys(cb); - for(int i=0;icallmap.remove(k[i]); -} - void UnaryOperator::removeCallback(QString t) { removeCallback(QVariant::nameToType(t.toAscii().data())); diff --git a/src/elamunary.h b/src/elamunary.h index b42c29f..387e288 100644 --- a/src/elamunary.h +++ b/src/elamunary.h @@ -12,6 +12,8 @@ #include "../dptr/dptr_base.h" +#include + namespace ELAM { class Engine; @@ -19,7 +21,7 @@ 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::functionUnaryOperatorCall; /** \brief Wraps a particular unary operator. @@ -50,13 +52,18 @@ class UnaryOperator \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 diff --git a/tests/eval/eval.pro b/tests/eval/eval.pro index 9900a09..57f87bc 100644 --- a/tests/eval/eval.pro +++ b/tests/eval/eval.pro @@ -7,4 +7,6 @@ DEPENDPATH += $$INCLUDEPATH ../.. 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 diff --git a/tests/parser/parser.pro b/tests/parser/parser.pro index 1633f3c..9fd3bc2 100644 --- a/tests/parser/parser.pro +++ b/tests/parser/parser.pro @@ -7,4 +7,6 @@ DEPENDPATH += $$INCLUDEPATH ../.. 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 -- 1.7.2.5