Isis Developer Reference
|
Converter for math equations. More...
#include <InfixToPostfix.h>
Public Member Functions | |
InfixToPostfix () | |
Constructor. | |
virtual | ~InfixToPostfix () |
QString | convert (const QString &infix) |
This method converts infix to postfix. | |
QString | tokenizeEquation (const QString &equation) |
This method will add spaces between all operators and numbers, making it possible to get each element of the equation one by one. | |
Protected Member Functions | |
virtual bool | isKnownSymbol (QString representation) |
This method will return true if it believes the argument represents a valid function or operator. | |
virtual InfixOperator * | findOperator (QString representation) |
This method will return a pointer to the operator represented by 'representation. | |
Protected Attributes | |
QList< InfixOperator * > | p_operators |
Converter for math equations.
This class converts infix equations to postfix
Isis::InfixToPostfix::InfixToPostfix | ( | ) |
Constructor.
|
virtual |
QString Isis::InfixToPostfix::convert | ( | const QString & | infix | ) |
This method converts infix to postfix.
It uses an enhanced verion of the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore. First, we prep the equation with TokenizeEquation and then parse through it using the known-good algorithm.
infix | The infix equation |
References _FILEINFO_, findOperator(), isKnownSymbol(), Isis::toDouble(), Isis::IString::Token(), tokenizeEquation(), Isis::IString::ToQt(), and Isis::IException::User.
Referenced by Isis::InlineCalculator::toPostfix().
|
protectedvirtual |
This method will return a pointer to the operator represented by 'representation.
' Because in this model a function is an operator, this will return a pointer to functions as well (in a base class pointer).
representation | The symbolic representation of the operator, such as '+' |
Reimplemented in Isis::InlineInfixToPostfix, and Isis::CubeInfixToPostfix.
References _FILEINFO_, p_operators, and Isis::IException::User.
Referenced by convert(), Isis::InlineInfixToPostfix::findOperator(), and Isis::CubeInfixToPostfix::findOperator().
|
protectedvirtual |
This method will return true if it believes the argument represents a valid function or operator.
representation | The symbolic representation of the operator, such as 'sin' |
Reimplemented in Isis::CubeInfixToPostfix, and Isis::InlineInfixToPostfix.
References p_operators.
Referenced by convert(), and Isis::InlineInfixToPostfix::isKnownSymbol().
QString Isis::InfixToPostfix::tokenizeEquation | ( | const QString & | equation | ) |
This method will add spaces between all operators and numbers, making it possible to get each element of the equation one by one.
It will also parse out the function calls, adding parenthesis where needed so the user doesn't have to. The result is an equation ready for parsing (but NOT fully parenthesized, just enough to make sure our algorithm makes no mistakes).
equation | An unformatted infix equation |
Referenced by convert().
|
protected |