From: Konrad Rosenbaum Date: Thu, 2 Feb 2012 06:38:53 +0000 (+0100) Subject: some explicit markers; X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=2138d66a2d3803b3c5e36cee3f735c28daae008a;p=web%2Fkonrad%2Felam.git some explicit markers; some convenience type casts for pointers; removed overloads: they were more trouble than they were worth --- diff --git a/src/elambinary.h b/src/elambinary.h index 6166f45..f0972bc 100644 --- a/src/elambinary.h +++ b/src/elambinary.h @@ -24,6 +24,14 @@ class Engine; \returns the result of the operation*/ typedef std::functionBinaryOperatorCall; +/** Helper type to select the correct overload from several variants. +If your compiler complains that it cannot resolve an overloaded pointer when calling BinaryOperator::setCallback then cast to this type to help the compiler: +\code +myBinaryOp.setCallback(BinaryOperatorCall_FP(myFunction),type1,type2); +\endcode +*/ +typedef QVariant(*BinaryOperatorCall_FP)(const QVariant&op1,const QVariant&op2,Engine&engine); + /** \brief Wraps a particular binary operator. You can use the methods of this class to change the routines that handle the operator and the types on which it operates. Instances of this class are implicitly shared - meaning calls on a copy of an instance are also visible on the original and all other copies. @@ -49,13 +57,6 @@ class BinaryOperator */ 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*/ diff --git a/src/elamengine.h b/src/elamengine.h index 76c4d86..c849338 100644 --- a/src/elamengine.h +++ b/src/elamengine.h @@ -35,6 +35,14 @@ Functions must check their arguments for validity before they start calculating. */ typedef std::function&args,Engine&engine)>Function; +/** Helper type to select the correct overload from several variants. +If your compiler complains that it cannot resolve an overloaded pointer when calling Engine::setFunction then cast to this type to help the compiler: +\code +myEngine.setFunction("hellofunc",Function_FP(myFunction)); +\endcode +*/ +typedef QVariant(*Function_FP)(const QList&args,Engine&engine); + /**wraps the parser routine for a literal \param expr the original expression string @@ -48,12 +56,28 @@ If the parser does not find a valid literal according to its rules it must retur */ typedef std::function(const QString&expr,Engine&engine,int start)>LiteralParser; +/** Helper type to select the correct overload from several variants. +If your compiler complains that it cannot resolve an overloaded pointer when calling Engine::setLiteralParser then cast to this type to help the compiler: +\code +myEngine.setLiteralParser(Function_FP(myDecimal),"123456789"); +\endcode +*/ +typedef QPair(*LiteralParser_FP)(const QString&expr,Engine&engine,int start); + /**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 std::functionTypeCast; +/** Helper type to select the correct overload from several variants. +If your compiler complains that it cannot resolve an overloaded pointer when calling Engine::setAutoCast then cast to this type to help the compiler: +\code +myEngine.setAutoCast(targetType,QList()<()<",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); + eng.binaryOperator("-",80).setCallback(BinaryOperatorCall_FP(floatMinus),fid,fid); + eng.binaryOperator("-").setCallback(BinaryOperatorCall_FP(floatMinus),iid,fid); + eng.binaryOperator("-").setCallback(BinaryOperatorCall_FP(floatMinus),fid,iid); eng.binaryOperator("+",80).setCallback(floatAdd,fid,fid); eng.binaryOperator("+").setCallback(floatAdd,iid,fid); eng.binaryOperator("+").setCallback(floatAdd,fid,iid); diff --git a/src/elamintengine.cpp b/src/elamintengine.cpp index f050df9..f4e329e 100644 --- a/src/elamintengine.cpp +++ b/src/elamintengine.cpp @@ -144,7 +144,7 @@ void IntEngine::configureIntEngine(ELAM::Engine& eng) //cast eng.setFunction("int",intFunc); //unaries - eng.unaryOperator("-").setCallback(intMinus,iid); + eng.unaryOperator("-").setCallback(UnaryOperatorCall_FP(intMinus),iid); eng.unaryOperator("+").setCallback(intPlus,iid); eng.unaryOperator("~").setCallback(intNot,iid); //binaries @@ -154,7 +154,7 @@ void IntEngine::configureIntEngine(ELAM::Engine& eng) 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(BinaryOperatorCall_FP(intMinus),iid,iid); eng.binaryOperator("+",80).setCallback(intAdd,iid,iid); eng.binaryOperator("*",90).setCallback(intMult,iid,iid); eng.binaryOperator("/",90).setCallback(intDiv,iid,iid); diff --git a/src/elamunary.h b/src/elamunary.h index 387e288..f79af2c 100644 --- a/src/elamunary.h +++ b/src/elamunary.h @@ -23,6 +23,14 @@ class Engine; \returns the result of the operation*/ typedef std::functionUnaryOperatorCall; +/** Helper type to select the correct overload from several variants. +If your compiler complains that it cannot resolve an overloaded pointer when calling UnaryOperator::setCallback then cast to this type to help the compiler: +\code +myUnaryOp.setCallback(UnaryOperatorCall_FP(myFunction),type); +\endcode +*/ +typedef QVariant(*UnaryOperatorCall_FP)(const QVariant&op,Engine&engine); + /** \brief Wraps a particular unary operator. You can use the methods of this class to change the routines that handle the operator and the types on which it operates. Instances of this class are implicitly shared - meaning calls on a copy of an instance are also visible on the original and all other copies. @@ -53,12 +61,6 @@ class UnaryOperator */ 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*/