Isis 3 Programmer Reference
Isis::CubeInfixToPostfix Class Reference

Converter for math equations. More...

#include <CubeInfixToPostfix.h>

Inheritance diagram for Isis::CubeInfixToPostfix:
Inheritance graph
Collaboration diagram for Isis::CubeInfixToPostfix:
Collaboration graph

Public Member Functions

 CubeInfixToPostfix ()
 Constructs a CubeInfixToPostfix converter.
 
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

bool isKnownSymbol (QString representation)
 This method will return true if it believes the argument represents a valid function or operator.
 
InfixOperatorfindOperator (QString representation)
 This method will return a pointer to the operator represented by 'representation.
 

Protected Attributes

QList< InfixOperator * > p_operators
 

Private Member Functions

void initialize ()
 This method is used to create functions that are specific to cubes.
 
void uninitialize ()
 This cleans the known operators/functions list.
 
QString formatFunctionCalls (QString equation)
 This method looks through equation for function calls, parenthesizes them, and calls itself again with each argument in order to parse any embedded functions.
 
QString cleanSpaces (QString equation)
 This function takes a space-delimited string and removes empty delimiters.
 
void closeParenthesis (QString &postfix, std::stack< InfixOperator > &theStack)
 This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore.
 
void addOperator (QString &postfix, const InfixOperator &op, std::stack< InfixOperator > &theStack)
 This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore.
 
bool isFunction (QString representation)
 This method will return true if 'representation' is a known function.
 
void checkArgument (QString funcName, int argNum, QString argument)
 

Detailed Description

Converter for math equations.

This class converts infix equations to postfix

Author
2007-08-21 Steven Lambright
History

2010-02-23 Steven Lambright Updated to use InfixOperator class method instead of direct access to member

2012-02-02 Jeff Anderson - Added the Initialize method and camera variables (phase, incidence, etc) for a cube

2012-02-09 Jeff Anderson - Modified to conform to ISIS programming standards

Definition at line 37 of file CubeInfixToPostfix.h.

Constructor & Destructor Documentation

◆ CubeInfixToPostfix()

Isis::CubeInfixToPostfix::CubeInfixToPostfix ( )

Constructs a CubeInfixToPostfix converter.

Author
janderson (2/2/2012)

Definition at line 19 of file CubeInfixToPostfix.cpp.

References initialize().

◆ ~CubeInfixToPostfix()

Isis::CubeInfixToPostfix::~CubeInfixToPostfix ( )
inline

Definition at line 40 of file CubeInfixToPostfix.h.

Member Function Documentation

◆ addOperator()

void Isis::InfixToPostfix::addOperator ( QString & postfix,
const InfixOperator & op,
std::stack< InfixOperator > & theStack )
privateinherited

This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore.

Parameters
postfixThe postix generated thus far
opThe operator
theStackThe operator stack

Definition at line 287 of file InfixToPostfix.cpp.

Referenced by Isis::InfixToPostfix::convert().

◆ checkArgument()

void Isis::InfixToPostfix::checkArgument ( QString funcName,
int argNum,
QString argument )
privateinherited

Definition at line 694 of file InfixToPostfix.cpp.

◆ cleanSpaces()

QString Isis::InfixToPostfix::cleanSpaces ( QString equation)
privateinherited

This function takes a space-delimited string and removes empty delimiters.

In order words, it compresses the spaces. This is used to keep strings small, clean, and remove the necessity to check for empty tokens constantly.

That is, if your string is "a b" the result will be "a b".

Parameters
equationA space-delimited string with excessive spaces
Returns
IString A space-delimited string with data between every pair of spaces

Definition at line 109 of file InfixToPostfix.cpp.

References Isis::IString::Token(), and Isis::IString::ToQt().

Referenced by Isis::InfixToPostfix::convert(), Isis::InfixToPostfix::formatFunctionCalls(), and Isis::InfixToPostfix::tokenizeEquation().

◆ closeParenthesis()

void Isis::InfixToPostfix::closeParenthesis ( QString & postfix,
std::stack< InfixOperator > & theStack )
privateinherited

This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore.

Parameters
postfixThe postix generated thus far
theStackThe operator stack

Definition at line 316 of file InfixToPostfix.cpp.

References Isis::IException::User.

Referenced by Isis::InfixToPostfix::convert().

◆ convert()

QString Isis::InfixToPostfix::convert ( const QString & infix)
inherited

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.

Parameters
infixThe infix equation
Returns
IString The postfix equation

Definition at line 139 of file InfixToPostfix.cpp.

References Isis::InfixToPostfix::addOperator(), Isis::InfixToPostfix::cleanSpaces(), Isis::InfixToPostfix::closeParenthesis(), Isis::InfixToPostfix::findOperator(), Isis::InfixToPostfix::isFunction(), Isis::InfixToPostfix::isKnownSymbol(), Isis::toDouble(), Isis::IString::Token(), Isis::InfixToPostfix::tokenizeEquation(), Isis::IString::ToQt(), and Isis::IException::User.

Referenced by Isis::InlineCalculator::toPostfix().

◆ findOperator()

InfixOperator * Isis::CubeInfixToPostfix::findOperator ( QString representation)
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).

Parameters
representationThe symbolic representation of the operator, such as '+'
Returns
InfixOperator* A pointer to the operator object that contains known information about the operator

Reimplemented from Isis::InfixToPostfix.

Definition at line 84 of file CubeInfixToPostfix.cpp.

References Isis::InfixToPostfix::findOperator(), Isis::InfixToPostfix::isFunction(), and Isis::IException::User.

◆ formatFunctionCalls()

QString Isis::InfixToPostfix::formatFunctionCalls ( QString equation)
privateinherited

This method looks through equation for function calls, parenthesizes them, and calls itself again with each argument in order to parse any embedded functions.

This ensures order of operations holds for cases like sin(.5)^2. This method might add too many parentheses, but that is harmless. This does not affect operators (excepting –) or numbers. Only functions. The input should be space-delimited.

Parameters
equationThe unparenthesized equation
Returns
IString The parenthesized equation

This code block is for multi-parameter functions. Functions with 1+ parameters are parsed here, excepting the negation (with no parentheses) which is done just above.

We figure out the arguments by looking for commas, outside of all parentheses, for each argument up until the last one. We look for an extra closing parenthesis for the last argument. When we figure out what an argument is, we recursively call FormatFunctionCalls to format any and all functionality inside of the argument.

Definition at line 479 of file InfixToPostfix.cpp.

References Isis::InfixToPostfix::cleanSpaces(), Isis::InfixToPostfix::findOperator(), Isis::InfixToPostfix::formatFunctionCalls(), Isis::InfixToPostfix::isFunction(), and Isis::IException::User.

Referenced by Isis::InfixToPostfix::formatFunctionCalls(), and Isis::InfixToPostfix::tokenizeEquation().

◆ initialize()

void Isis::CubeInfixToPostfix::initialize ( )
private

This method is used to create functions that are specific to cubes.

Moved the cubemin and cubemax functions out of the InfixToPostfix initialization method into this method

Author
janderson (2/2/2012)

Definition at line 30 of file CubeInfixToPostfix.cpp.

Referenced by CubeInfixToPostfix().

◆ isFunction()

bool Isis::InfixToPostfix::isFunction ( QString representation)
privateinherited

This method will return true if 'representation' is a known function.

Parameters
representationThe symbolic representation of a function, such as 'abs'
Returns
bool True if it's a known function, false otherwise

Definition at line 270 of file InfixToPostfix.cpp.

References Isis::InfixToPostfix::findOperator(), and Isis::InfixToPostfix::isKnownSymbol().

Referenced by Isis::InfixToPostfix::convert(), findOperator(), Isis::InfixToPostfix::formatFunctionCalls(), and isKnownSymbol().

◆ isKnownSymbol()

bool Isis::CubeInfixToPostfix::isKnownSymbol ( QString representation)
protectedvirtual

This method will return true if it believes the argument represents a valid function or operator.

Parameters
representationThe symbolic representation of the operator, such as 'sin'
Returns
bool True if it looks valid, false if it's not known

Reimplemented from Isis::InfixToPostfix.

Definition at line 64 of file CubeInfixToPostfix.cpp.

References Isis::InfixToPostfix::isFunction().

◆ tokenizeEquation()

QString Isis::InfixToPostfix::tokenizeEquation ( const QString & equation)
inherited

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).

Parameters
equationAn unformatted infix equation
Returns
IString A tokenized equation with additional parentheses

Definition at line 369 of file InfixToPostfix.cpp.

References Isis::InfixToPostfix::cleanSpaces(), and Isis::InfixToPostfix::formatFunctionCalls().

Referenced by Isis::InfixToPostfix::convert().

◆ uninitialize()

void Isis::InfixToPostfix::uninitialize ( )
privateinherited

This cleans the known operators/functions list.

Definition at line 89 of file InfixToPostfix.cpp.

Member Data Documentation

◆ p_operators

QList<InfixOperator *> Isis::InfixToPostfix::p_operators
protectedinherited

Definition at line 59 of file InfixToPostfix.h.


The documentation for this class was generated from the following files: