Isis 3 Programmer Reference
Isis::InlineCalculator Class Reference

Provides a calculator for inline equations. More...

#include <InlineCalculator.h>

Inheritance diagram for Isis::InlineCalculator:
Inheritance graph
Collaboration diagram for Isis::InlineCalculator:
Collaboration graph

Public Member Functions

 InlineCalculator ()
 Constructs an InlineCalculator object by initializing the operator lookup list. More...
 
 InlineCalculator (const QString &equation)
 Constructs an InlineCalculator object by initializing the operator lookup list and compiles the given equation to prepare for evaluation. More...
 
virtual ~InlineCalculator ()
 Destroys the InlineCalculator object. More...
 
int size () const
 Accesses the number of functions, operators, variables, and scalars to be executed. More...
 
QString equation () const
 Accesses the string representation of the current equation, in postfix format. More...
 
bool compile (const QString &equation)
 Compiles the given equation for evaluation. More...
 
QVector< double > evaluate (CalculatorVariablePool *variablePool)
 Evaluate with a variable pool. More...
 
QVector< double > evaluate ()
 Evaluate compiled equation with existing variable pool. More...
 
void Negative ()
 Pops an element, negates it, then pushes the result. More...
 
void Multiply ()
 Pops two elements, multiplies them, then pushes the product on the stack. More...
 
void Add ()
 Pops two elements, adds them, then pushes the sum on the stack. More...
 
void Subtract ()
 Pops two elements, subtracts them, then pushes the difference on the stack. More...
 
void Divide ()
 Pops two, divides them, then pushes the quotient on the stack. More...
 
void Modulus ()
 Pops two elements, mods them, then pushes the result on the stack. More...
 
void Exponent ()
 Pops two elements, computes the power then pushes the result on the stack The exponent has to be a scalar. More...
 
void SquareRoot ()
 Pop an element, compute its square root, then push the root on the stack. More...
 
void AbsoluteValue ()
 Pop an element, compute its absolute value, then push the result on the stack. More...
 
void Log ()
 Pop an element, compute its log, then push the result on the stack. More...
 
void Log10 ()
 Pop an element, compute its base 10 log, then push the result on the stack. More...
 
void LeftShift ()
 Pop the top element, then perform a left shift with zero fill. More...
 
void RightShift ()
 Pop the top element, then perform a right shift with zero fill. More...
 
void MinimumPixel ()
 Pop two elements, then push the minimum on a pixel by pixel basis back on the stack. More...
 
void MaximumPixel ()
 Pop two elements, then push the maximum on a pixel by pixel basis back on the stack. More...
 
void MinimumLine ()
 Pop one element, then push the minimum on the stack. More...
 
void MaximumLine ()
 Pop one element, then push the maximum on the stack. More...
 
void Minimum2 ()
 Not implemented in Calculator.cpp. More...
 
void Maximum2 ()
 Not implemented in Calculator.cpp. More...
 
void GreaterThan ()
 Pop two elements off the stack and compare them to see where one is greater than the other, then push the results on the stack. More...
 
void LessThan ()
 Pop two elements off the stack and compare them to see where one is less than the other, then push the results on the stack. More...
 
void Equal ()
 Pop two elements off the stack and compare them to see where one is equal to the other, then push the results on the stack. More...
 
void LessThanOrEqual ()
 Pop two elements off the stack and compare them to see where one is less than or equal to the other, then push the results on the stack. More...
 
void GreaterThanOrEqual ()
 Pop two elements off the stack and compare them to see where one is greater than or equal to the other, then push the results on the stack. More...
 
void NotEqual ()
 Pop two elements off the stack and compare them to see where one is not equal to the other, then push the results on the stack. More...
 
void And ()
 Pop two elements, AND them, then push the result on the stack. More...
 
void Or ()
 Pop two elements, OR them, then push the result on the stack. More...
 
void Sine ()
 Pops one element and push the sine. More...
 
void Cosine ()
 Pops one element and push the cosine. More...
 
void Tangent ()
 Pops one element and push the tangent. More...
 
void Secant ()
 Pops one element and push the secant. More...
 
void Cosecant ()
 Pops one element and push the cosecant. More...
 
void Cotangent ()
 Pops one element and push the cotangent. More...
 
void Arcsine ()
 Pops one element and push the arcsine. More...
 
void Arccosine ()
 Pops one element and push the arccosine. More...
 
void Arctangent ()
 Pops one element and push the arctangent. More...
 
void Arctangent2 ()
 Pops two elements and push the arctangent. More...
 
void SineH ()
 Pops one element and push the hyperbolic sine. More...
 
void CosineH ()
 Pops one element and push the hyperbolic cosine. More...
 
void TangentH ()
 Pops one element and push the hyperbolic tangent. More...
 
void ArcsineH ()
 Pops one element and push the inverse hyperbolic sine. More...
 
void ArccosineH ()
 Pops one element and push the inverse hyperbolic cosine. More...
 
void ArctangentH ()
 Pops one element and push the inverse hyperbolic tangent. More...
 
void Push (double scalar)
 Push a scalar onto the stack. More...
 
void Push (Buffer &buff)
 Push a buffer onto the stack. More...
 
void Push (QVector< double > &vect)
 Push a vector onto the stack. More...
 
QVector< double > Pop (bool keepSpecials=false)
 Pop an element off the stack. More...
 
void PrintTop ()
 Print the vector at the top of the stack. More...
 
bool Empty ()
 Check if the stack is empty. More...
 
virtual void Clear ()
 Clear out the stack. More...
 

Protected Types

typedef FxBinderFxTypePtr
 Defintion for a FxTypePtr, a pointer to a function binder (FxBinder) More...
 

Protected Member Functions

void scalar (const QVariant &scalar)
 Pushes the given value onto the stack as a scalar. More...
 
void variable (const QVariant &variable)
 Pushes the given value onto the stack as a variable. More...
 
void floatModulus ()
 Pops the top two vectors off the current stack and performs the floatModulusOperator() on the corresponding components of these vectors. More...
 
void radians ()
 Pops the top vector off the current stack and converts from degrees to radians. More...
 
void degrees ()
 Pops the top vector off the current stack and converts from radians to degrees. More...
 
void logicalOr ()
 Pops the top two vectors off the current stack and performs a logical or on each pair. More...
 
void logicalAnd ()
 Pops the top two vectors off the current stack and performs a logical and on each pair. More...
 
void pi ()
 Pushes the PI constant onto the current stack. More...
 
void eConstant ()
 Pushes the Euler constant (e) onto the current stack. More...
 
virtual QString toPostfix (const QString &equation) const
 Converts the given string from infix to postfix format. More...
 
bool isScalar (const QString &scalar)
 Determines whether the given string contains a scalar value (i.e. More...
 
bool isVariable (const QString &str)
 Determines whether the given string is a variable. More...
 
bool fxExists (const QString &fxname) const
 Determines whether the given function name exists in the current function pool. More...
 
FxTypePtr addFunction (FxTypePtr function)
 Adds a function to the function pool. More...
 
virtual bool orphanTokenHandler (const QString &token)
 Default token handler if it is undefined during parsing/compilation. More...
 
void PerformOperation (QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, double operation(double))
 Performs the mathematical operations on each argument. More...
 
void PerformOperation (QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, QVector< double >::iterator arg2Start, QVector< double >::iterator arg2End, double operation(double, double))
 Performs the mathematical operation on each pair of arguments, or a set of agruments against a single argument. More...
 
int StackSize ()
 Returns the current stack size. More...
 

Private Types

typedef QVector< FxTypePtrFxEqList
 Definition for a FxEqList, a vector of function type pointers. More...
 
typedef QMap< QString, FxTypePtrFxPoolType
 Definition for a FxPoolType, a map between a string and function type pointer. More...
 

Private Member Functions

void pushVariables (CalculatorVariablePool *variablePool)
 Push the given variable pool onto the current variable pool list. More...
 
CalculatorVariablePoolvariables ()
 Accesses the last variable pool in the current pool list. More...
 
void popVariables ()
 Removes the last variable pool in the current variable pool list. More...
 
FxTypePtr find (const QString &fxname)
 Gets a pointer to the function from the current pool that corresponds to the given function name. More...
 
void initialize ()
 Adds the recognized functions to the function pool. More...
 
void destruct ()
 Discard of all the function pool and class resources. More...
 

Private Attributes

FxEqList m_functions
 The list of pointers to function equations for the calculator. More...
 
FxPoolType m_fxPool
 The map between function names and equation lists. More...
 
QString m_equation
 The equation to be evaluated. More...
 
QList< CalculatorVariablePool * > m_variablePoolList
 The list of variable pool pointers. More...
 
QStack< QVector< double > > * p_valStack
 The current stack of arguments. More...
 

Detailed Description

Provides a calculator for inline equations.

A calculator with the ability to parse infix equations with embedded variables and scalars, known as an inline equation.

Author
2012-07-15 Kris Becker
History:
2012-07-15 Kris Becker - Original version.
History:
2015-03-18 Jeannie Backer - Brought class files closer to ISIS coding standards.
History:
2015-03-24 Jeffrey Covington and Jeannie Backer - Improved documentation.
History:
2016-02-21 Kristin Berry - Added unit test and minor coding standard updates. Fixes #2401.
History:
2017-01-09 Jesse Mapel - Added logical and, or operators. Fixes #4581.

Definition at line 49 of file InlineCalculator.h.

Member Typedef Documentation

◆ FxEqList

Definition for a FxEqList, a vector of function type pointers.

Definition at line 94 of file InlineCalculator.h.

◆ FxPoolType

Definition for a FxPoolType, a map between a string and function type pointer.

Definition at line 96 of file InlineCalculator.h.

◆ FxTypePtr

Defintion for a FxTypePtr, a pointer to a function binder (FxBinder)

Definition at line 67 of file InlineCalculator.h.

Constructor & Destructor Documentation

◆ InlineCalculator() [1/2]

Isis::InlineCalculator::InlineCalculator ( )

Constructs an InlineCalculator object by initializing the operator lookup list.

Definition at line 41 of file InlineCalculator.cpp.

References initialize().

◆ InlineCalculator() [2/2]

Isis::InlineCalculator::InlineCalculator ( const QString &  equation)

Constructs an InlineCalculator object by initializing the operator lookup list and compiles the given equation to prepare for evaluation.

Parameters
equationA string representing an equation in infix format.

Definition at line 52 of file InlineCalculator.cpp.

References compile(), equation(), and initialize().

◆ ~InlineCalculator()

Isis::InlineCalculator::~InlineCalculator ( )
virtual

Destroys the InlineCalculator object.

Definition at line 61 of file InlineCalculator.cpp.

References destruct().

Member Function Documentation

◆ AbsoluteValue()

void Isis::Calculator::AbsoluteValue ( )
inherited

Pop an element, compute its absolute value, then push the result on the stack.

Definition at line 407 of file Calculator.cpp.

Referenced by initialize().

◆ Add()

void Isis::Calculator::Add ( )
inherited

Pops two elements, adds them, then pushes the sum on the stack.

Definition at line 330 of file Calculator.cpp.

References Isis::AddOperator().

Referenced by initialize().

◆ addFunction()

InlineCalculator::FxTypePtr Isis::InlineCalculator::addFunction ( InlineCalculator::FxTypePtr  function)
protected

Adds a function to the function pool.

Once in the pool, functions cannot be overwritten. This method will throw an exception if we attempt to add a function with the same name as one already in the pool.

Parameters
functionThe function type pointer to be added to the pool
Returns
InlineCalculator::FxTypePtr The function type pointer that has been added to the pool.
Exceptions
IException::Programmer"Function operator exists! Cannot replace existing functions in the pool"

Definition at line 478 of file InlineCalculator.cpp.

References find(), m_fxPool, and Isis::IException::Programmer.

Referenced by compile(), and initialize().

◆ And()

void Isis::Calculator::And ( )
inherited

Pop two elements, AND them, then push the result on the stack.

Definition at line 679 of file Calculator.cpp.

References Isis::BitwiseAndOperator().

Referenced by initialize().

◆ Arccosine()

void Isis::Calculator::Arccosine ( )
inherited

Pops one element and push the arccosine.

Definition at line 777 of file Calculator.cpp.

Referenced by initialize().

◆ ArccosineH()

void Isis::Calculator::ArccosineH ( )
inherited

Pops one element and push the inverse hyperbolic cosine.

Definition at line 807 of file Calculator.cpp.

◆ Arcsine()

void Isis::Calculator::Arcsine ( )
inherited

Pops one element and push the arcsine.

Definition at line 767 of file Calculator.cpp.

Referenced by initialize().

◆ ArcsineH()

void Isis::Calculator::ArcsineH ( )
inherited

Pops one element and push the inverse hyperbolic sine.

Definition at line 797 of file Calculator.cpp.

◆ Arctangent()

void Isis::Calculator::Arctangent ( )
inherited

Pops one element and push the arctangent.

Definition at line 787 of file Calculator.cpp.

Referenced by initialize().

◆ Arctangent2()

void Isis::Calculator::Arctangent2 ( )
inherited

Pops two elements and push the arctangent.

Definition at line 827 of file Calculator.cpp.

Referenced by initialize().

◆ ArctangentH()

void Isis::Calculator::ArctangentH ( )
inherited

Pops one element and push the inverse hyperbolic tangent.

Definition at line 817 of file Calculator.cpp.

◆ Clear()

void Isis::Calculator::Clear ( )
virtualinherited

Clear out the stack.

Reimplemented in Isis::CubeCalculator.

Definition at line 1021 of file Calculator.cpp.

Referenced by compile(), and popVariables().

◆ compile()

bool Isis::InlineCalculator::compile ( const QString &  equation)

Compiles the given equation for evaluation.

This method first converts the given infix equation into a postfix equation for evaluation and saves the postfix formatted string. It then ensures that the equation is ready for evaluation by parsing and verifying that all tokens are recognized.

Parameters
equationA string representing an equation to be compiled, in infix format.
Returns
bool Indicates whether the compilation was successful.
Exceptions
IException::User"Error parsing inline equation. Equation element invalid - token not recognized."

Definition at line 106 of file InlineCalculator.cpp.

References addFunction(), Isis::IException::append(), Isis::Calculator::Clear(), equation(), find(), isScalar(), isVariable(), m_equation, m_functions, orphanTokenHandler(), scalar(), toPostfix(), Isis::IException::User, and variable().

Referenced by InlineCalculator().

◆ Cosecant()

void Isis::Calculator::Cosecant ( )
inherited

Pops one element and push the cosecant.

Definition at line 737 of file Calculator.cpp.

References Isis::CosecantOperator().

Referenced by initialize().

◆ Cosine()

void Isis::Calculator::Cosine ( )
inherited

Pops one element and push the cosine.

Definition at line 717 of file Calculator.cpp.

Referenced by initialize().

◆ CosineH()

void Isis::Calculator::CosineH ( )
inherited

Pops one element and push the hyperbolic cosine.

Definition at line 850 of file Calculator.cpp.

◆ Cotangent()

void Isis::Calculator::Cotangent ( )
inherited

Pops one element and push the cotangent.

Definition at line 757 of file Calculator.cpp.

References Isis::CotangentOperator().

Referenced by initialize().

◆ degrees()

void Isis::InlineCalculator::degrees ( )
protected

Pops the top vector off the current stack and converts from radians to degrees.

The result is then pushed back onto the stack.

Definition at line 375 of file InlineCalculator.cpp.

References Isis::Calculator::Pop(), Isis::Calculator::Push(), and radians().

Referenced by initialize().

◆ destruct()

void Isis::InlineCalculator::destruct ( )
private

Discard of all the function pool and class resources.

Definition at line 645 of file InlineCalculator.cpp.

References m_functions, and m_fxPool.

Referenced by ~InlineCalculator().

◆ Divide()

void Isis::Calculator::Divide ( )
inherited

Pops two, divides them, then pushes the quotient on the stack.

Definition at line 354 of file Calculator.cpp.

References Isis::DivideOperator().

Referenced by initialize().

◆ eConstant()

void Isis::InlineCalculator::eConstant ( )
protected

Pushes the Euler constant (e) onto the current stack.

Definition at line 446 of file InlineCalculator.cpp.

References Isis::E, and Isis::Calculator::Push().

Referenced by initialize().

◆ Empty()

bool Isis::Calculator::Empty ( )
inherited

Check if the stack is empty.

Returns
bool True if the stack is empty

Definition at line 1013 of file Calculator.cpp.

◆ Equal()

void Isis::Calculator::Equal ( )
inherited

Pop two elements off the stack and compare them to see where one is equal to the other, then push the results on the stack.

Definition at line 617 of file Calculator.cpp.

References Isis::EqualOperator().

Referenced by initialize().

◆ equation()

QString Isis::InlineCalculator::equation ( ) const

Accesses the string representation of the current equation, in postfix format.

This equation is most commonly entered using infix, but it is reformatted to postfix when set.

Returns
QString A string representing the equation, in postfix.

Definition at line 85 of file InlineCalculator.cpp.

References m_equation.

Referenced by compile(), InlineCalculator(), and toPostfix().

◆ evaluate() [1/2]

QVector< double > Isis::InlineCalculator::evaluate ( )

Evaluate compiled equation with existing variable pool.

This executes the operands to provide the result of the equation. The currently stored variable pool, refernenced via variables(), is used to provide the variables utilized in the equation.

This is reentrant and as long as the variable pool is unchanged between succesive calls, they all should return the same result.

Returns
QVector < double > Result of the stored equation.
Exceptions
IException::Unknown"Too many operands in the equation."

Definition at line 218 of file InlineCalculator.cpp.

References m_equation, m_functions, Isis::Calculator::Pop(), Isis::Calculator::StackSize(), and Isis::IException::Unknown.

Referenced by evaluate().

◆ evaluate() [2/2]

QVector< double > Isis::InlineCalculator::evaluate ( CalculatorVariablePool variablePool)

Evaluate with a variable pool.

This method accepts a varible resource pool, stores it off for evaluation and then executes the operands to provide the result of the equation. It stores the variable pool for subsequent runs that should yield identical results when operator() is invoked.

Parameters
variablePoolKeyword resource for variables substituted at run time of the equation
Returns
QVector < double > Result of the stored equation given the resource.
Exceptions
IException::Programmer"Calculation with variable pool failed."

Definition at line 187 of file InlineCalculator.cpp.

References evaluate(), popVariables(), Isis::IException::Programmer, and pushVariables().

◆ Exponent()

void Isis::Calculator::Exponent ( )
inherited

Pops two elements, computes the power then pushes the result on the stack The exponent has to be a scalar.

Exceptions
Isis::iException::Math

Definition at line 382 of file Calculator.cpp.

Referenced by initialize().

◆ find()

InlineCalculator::FxTypePtr Isis::InlineCalculator::find ( const QString &  fxname)
private

Gets a pointer to the function from the current pool that corresponds to the given function name.

This method returns null if no function with the given name is found.

Parameters
fxnameA string containing the name of the function to be found.
Returns
InlineCalculator::FxTypePtr A pointer to the corresponding function type, if found.

Definition at line 568 of file InlineCalculator.cpp.

References m_fxPool.

Referenced by addFunction(), and compile().

◆ floatModulus()

void Isis::InlineCalculator::floatModulus ( )
protected

Pops the top two vectors off the current stack and performs the floatModulusOperator() on the corresponding components of these vectors.

The result is then pushed back onto the stack.

Definition at line 345 of file InlineCalculator.cpp.

References Isis::floatModulusOperator(), Isis::Calculator::PerformOperation(), Isis::Calculator::Pop(), and Isis::Calculator::Push().

Referenced by initialize().

◆ fxExists()

bool Isis::InlineCalculator::fxExists ( const QString &  fxname) const
protected

Determines whether the given function name exists in the current function pool.

Parameters
fxnameA string containing the name of the function we are looking for in the pool.
Returns
bool Indicates whether the pool contains the given function.

Definition at line 461 of file InlineCalculator.cpp.

References m_fxPool.

◆ GreaterThan()

void Isis::Calculator::GreaterThan ( )
inherited

Pop two elements off the stack and compare them to see where one is greater than the other, then push the results on the stack.

Definition at line 587 of file Calculator.cpp.

References Isis::GreaterThanOperator().

Referenced by initialize().

◆ GreaterThanOrEqual()

void Isis::Calculator::GreaterThanOrEqual ( )
inherited

Pop two elements off the stack and compare them to see where one is greater than or equal to the other, then push the results on the stack.

Definition at line 632 of file Calculator.cpp.

References Isis::GreaterThanOrEqualOperator().

Referenced by initialize().

◆ initialize()

◆ isScalar()

bool Isis::InlineCalculator::isScalar ( const QString &  scalar)
protected

Determines whether the given string contains a scalar value (i.e.

can be converted to a double precision value).

Parameters
scalarA string to be checked.
Returns
bool Indicates whether the given string is a scalar value.

Definition at line 255 of file InlineCalculator.cpp.

References scalar(), and Isis::toDouble().

Referenced by compile(), and isVariable().

◆ isVariable()

bool Isis::InlineCalculator::isVariable ( const QString &  str)
protected

Determines whether the given string is a variable.

If the string is empty or scalar, this method returns false. Otherwise, it is assumed to be a variable and this method returns true.

Parameters
strA string to be checked.
Returns
bool Indicates whether the given string is a variable.

Definition at line 275 of file InlineCalculator.cpp.

References isScalar().

Referenced by compile().

◆ LeftShift()

void Isis::Calculator::LeftShift ( )
inherited

Pop the top element, then perform a left shift with zero fill.

Exceptions
Isis::iException::Math

Definition at line 441 of file Calculator.cpp.

Referenced by initialize().

◆ LessThan()

void Isis::Calculator::LessThan ( )
inherited

Pop two elements off the stack and compare them to see where one is less than the other, then push the results on the stack.

Definition at line 602 of file Calculator.cpp.

References Isis::LessThanOperator().

Referenced by initialize().

◆ LessThanOrEqual()

void Isis::Calculator::LessThanOrEqual ( )
inherited

Pop two elements off the stack and compare them to see where one is less than or equal to the other, then push the results on the stack.

Definition at line 647 of file Calculator.cpp.

References Isis::LessThanOrEqualOperator().

Referenced by initialize().

◆ Log()

void Isis::Calculator::Log ( )
inherited

Pop an element, compute its log, then push the result on the stack.

Exceptions
Isis::iException::Math

Definition at line 419 of file Calculator.cpp.

Referenced by initialize().

◆ Log10()

void Isis::Calculator::Log10 ( )
inherited

Pop an element, compute its base 10 log, then push the result on the stack.

Definition at line 429 of file Calculator.cpp.

Referenced by initialize().

◆ logicalAnd()

void Isis::InlineCalculator::logicalAnd ( )
protected

Pops the top two vectors off the current stack and performs a logical and on each pair.

Exceptions
IException::Unknown"Failed performing logical and operation, " "input vectors are of differnet lengths."

Definition at line 417 of file InlineCalculator.cpp.

References Isis::Calculator::Pop(), Isis::Calculator::Push(), and Isis::IException::Unknown.

Referenced by initialize().

◆ logicalOr()

void Isis::InlineCalculator::logicalOr ( )
protected

Pops the top two vectors off the current stack and performs a logical or on each pair.

Exceptions
IException::Unknown"Failed performing logical or operation, " "input vectors are of differnet lengths."

Definition at line 393 of file InlineCalculator.cpp.

References Isis::Calculator::Pop(), Isis::Calculator::Push(), and Isis::IException::Unknown.

Referenced by initialize().

◆ Maximum2()

void Isis::Calculator::Maximum2 ( )
inherited

Not implemented in Calculator.cpp.

◆ MaximumLine()

void Isis::Calculator::MaximumLine ( )
inherited

Pop one element, then push the maximum on the stack.

Definition at line 537 of file Calculator.cpp.

References Isis::IsSpecial().

◆ MaximumPixel()

void Isis::Calculator::MaximumPixel ( )
inherited

Pop two elements, then push the maximum on a pixel by pixel basis back on the stack.

Definition at line 572 of file Calculator.cpp.

References Isis::MaximumOperator().

Referenced by initialize().

◆ Minimum2()

void Isis::Calculator::Minimum2 ( )
inherited

Not implemented in Calculator.cpp.

◆ MinimumLine()

void Isis::Calculator::MinimumLine ( )
inherited

Pop one element, then push the minimum on the stack.

Definition at line 518 of file Calculator.cpp.

References Isis::IsSpecial().

◆ MinimumPixel()

void Isis::Calculator::MinimumPixel ( )
inherited

Pop two elements, then push the minimum on a pixel by pixel basis back on the stack.

Definition at line 557 of file Calculator.cpp.

References Isis::MinimumOperator().

Referenced by initialize().

◆ Modulus()

void Isis::Calculator::Modulus ( )
inherited

Pops two elements, mods them, then pushes the result on the stack.

Definition at line 366 of file Calculator.cpp.

References Isis::ModulusOperator().

Referenced by initialize().

◆ Multiply()

void Isis::Calculator::Multiply ( )
inherited

Pops two elements, multiplies them, then pushes the product on the stack.

Definition at line 317 of file Calculator.cpp.

References Isis::MultiplyOperator().

Referenced by initialize().

◆ Negative()

void Isis::Calculator::Negative ( )
inherited

Pops an element, negates it, then pushes the result.

Definition at line 307 of file Calculator.cpp.

References Isis::NegateOperator().

Referenced by initialize().

◆ NotEqual()

void Isis::Calculator::NotEqual ( )
inherited

Pop two elements off the stack and compare them to see where one is not equal to the other, then push the results on the stack.

Definition at line 662 of file Calculator.cpp.

References Isis::NotEqualOperator().

Referenced by initialize().

◆ Or()

void Isis::Calculator::Or ( )
inherited

Pop two elements, OR them, then push the result on the stack.

Definition at line 693 of file Calculator.cpp.

References Isis::BitwiseOrOperator().

Referenced by initialize().

◆ orphanTokenHandler()

bool Isis::InlineCalculator::orphanTokenHandler ( const QString &  token)
protectedvirtual

Default token handler if it is undefined during parsing/compilation.

This method provides the default handling of an undefined token found while compiling an equation. Users may code their own handler that, for example, could provide additional further functionality.

If the virtualized reimplementation is unable to process it, it can throw an exception which will be caught, recorded and compiling will continue until all tokens are processed. If the optional implementation cannot handle it, return false from your version and an exception will be thrown for you.

Parameters
tokenCharacter representation of the token. This could be an undefined constant, function or soemthing else that occurs in the equation that is not resolved when this is called.
Returns
bool True if it is handled, false if it cannot (which is an error and an exception will be invoked).

Definition at line 512 of file InlineCalculator.cpp.

Referenced by compile().

◆ PerformOperation() [1/2]

void Isis::Calculator::PerformOperation ( QVector< double > &  results,
QVector< double >::iterator  arg1Start,
QVector< double >::iterator  arg1End,
double   operationdouble 
)
protectedinherited

Performs the mathematical operations on each argument.

Parameters
results[out] The results of the performed operation
arg1StartThe first argument to have the operation done on
arg1EndOne argument beyond the final argument to have the operation done upon
operationThe operation to be done on all arguments

Definition at line 1037 of file Calculator.cpp.

Referenced by floatModulus().

◆ PerformOperation() [2/2]

void Isis::Calculator::PerformOperation ( QVector< double > &  results,
QVector< double >::iterator  arg1Start,
QVector< double >::iterator  arg1End,
QVector< double >::iterator  arg2Start,
QVector< double >::iterator  arg2End,
double   operationdouble, double 
)
protectedinherited

Performs the mathematical operation on each pair of arguments, or a set of agruments against a single argument.

Parameters
results[out] The results of the performed operation
arg1StartThe first of the primary argument to have the operation done on
arg1EndOne arguement beyond the final primary argument to have the operation done upon
arg2StartThe first of the secondaty argument to have the operation done on
arg2EndOne arguement beyond the final secondary argument to have the operation done upon
operationThe operation to be done on all pairs of arguments

Definition at line 1066 of file Calculator.cpp.

◆ pi()

void Isis::InlineCalculator::pi ( )
protected

Pushes the PI constant onto the current stack.

Definition at line 437 of file InlineCalculator.cpp.

References Isis::Calculator::Push().

Referenced by initialize().

◆ Pop()

QVector< double > Isis::Calculator::Pop ( bool  keepSpecials = false)
inherited

Pop an element off the stack.

Parameters
keepSpecialsIf true, special pixels will be preserved; otherwise, they will be mapped to double values
Returns
The top of the stack, which gets popped

Definition at line 949 of file Calculator.cpp.

References Isis::Hrs, Isis::Lrs, and Isis::Null.

Referenced by degrees(), evaluate(), floatModulus(), logicalAnd(), logicalOr(), and radians().

◆ popVariables()

void Isis::InlineCalculator::popVariables ( )
private

Removes the last variable pool in the current variable pool list.

Definition at line 549 of file InlineCalculator.cpp.

References Isis::Calculator::Clear(), and m_variablePoolList.

Referenced by evaluate().

◆ PrintTop()

void Isis::Calculator::PrintTop ( )
inherited

Print the vector at the top of the stack.

Definition at line 989 of file Calculator.cpp.

◆ Push() [1/3]

void Isis::Calculator::Push ( Buffer buff)
inherited

Push a buffer onto the stack.

Parameters
buffThe buffer that will be pushed on the stack

Definition at line 905 of file Calculator.cpp.

References Isis::IsHisPixel(), Isis::IsHrsPixel(), Isis::IsLisPixel(), Isis::IsLrsPixel(), Isis::IsNullPixel(), Isis::IsSpecial(), and Isis::Buffer::size().

◆ Push() [2/3]

void Isis::Calculator::Push ( double  scalar)
inherited

Push a scalar onto the stack.

Parameters
scalarThe scalar that will be pushed on the stack

Definition at line 893 of file Calculator.cpp.

Referenced by degrees(), eConstant(), floatModulus(), logicalAnd(), logicalOr(), pi(), radians(), scalar(), and variable().

◆ Push() [3/3]

void Isis::Calculator::Push ( QVector< double > &  vect)
inherited

Push a vector onto the stack.

Parameters
vectThe vector that will be pushed on the stack

Definition at line 883 of file Calculator.cpp.

◆ pushVariables()

void Isis::InlineCalculator::pushVariables ( CalculatorVariablePool variablePool)
private

Push the given variable pool onto the current variable pool list.

Parameters
variablePoolA pointer to the CalculatorVariablePool object to be pushed onto the current list.

Definition at line 523 of file InlineCalculator.cpp.

References m_variablePoolList.

Referenced by evaluate().

◆ radians()

void Isis::InlineCalculator::radians ( )
protected

Pops the top vector off the current stack and converts from degrees to radians.

The result is then pushed back onto the stack.

Definition at line 360 of file InlineCalculator.cpp.

References Isis::Calculator::Pop(), and Isis::Calculator::Push().

Referenced by degrees(), and initialize().

◆ RightShift()

void Isis::Calculator::RightShift ( )
inherited

Pop the top element, then perform a right shift with zero fill.

Exceptions
Isis::iException::Math

Definition at line 480 of file Calculator.cpp.

Referenced by initialize().

◆ scalar()

void Isis::InlineCalculator::scalar ( const QVariant &  scalar)
protected

Pushes the given value onto the stack as a scalar.

This method adds the given variant value to the stack as a scalar.

Parameters
scalarQVariant containing the scalar. Usually a QString.

Definition at line 294 of file InlineCalculator.cpp.

References Isis::Calculator::Push(), and Isis::toDouble().

Referenced by compile(), and isScalar().

◆ Secant()

void Isis::Calculator::Secant ( )
inherited

Pops one element and push the secant.

Definition at line 747 of file Calculator.cpp.

References Isis::SecantOperator().

Referenced by initialize().

◆ Sine()

void Isis::Calculator::Sine ( )
inherited

Pops one element and push the sine.

Definition at line 707 of file Calculator.cpp.

Referenced by initialize().

◆ SineH()

void Isis::Calculator::SineH ( )
inherited

Pops one element and push the hyperbolic sine.

Definition at line 840 of file Calculator.cpp.

◆ size()

int Isis::InlineCalculator::size ( ) const

Accesses the number of functions, operators, variables, and scalars to be executed.

Returns
int The number of functions, operators, variables, and scalars stored in the Calculator.

Definition at line 73 of file InlineCalculator.cpp.

References m_functions.

◆ SquareRoot()

void Isis::Calculator::SquareRoot ( )
inherited

Pop an element, compute its square root, then push the root on the stack.

Exceptions
Isis::iException::Math

Definition at line 397 of file Calculator.cpp.

Referenced by initialize().

◆ StackSize()

int Isis::Calculator::StackSize ( )
protectedinherited

Returns the current stack size.

Get the current stack size.

Returns
int Number of arguments in the stack

Definition at line 874 of file Calculator.cpp.

Referenced by evaluate().

◆ Subtract()

void Isis::Calculator::Subtract ( )
inherited

Pops two elements, subtracts them, then pushes the difference on the stack.

Definition at line 342 of file Calculator.cpp.

References Isis::SubtractOperator().

Referenced by initialize().

◆ Tangent()

void Isis::Calculator::Tangent ( )
inherited

Pops one element and push the tangent.

Definition at line 727 of file Calculator.cpp.

Referenced by initialize().

◆ TangentH()

void Isis::Calculator::TangentH ( )
inherited

Pops one element and push the hyperbolic tangent.

Definition at line 860 of file Calculator.cpp.

◆ toPostfix()

QString Isis::InlineCalculator::toPostfix ( const QString &  equation) const
protectedvirtual

Converts the given string from infix to postfix format.

Parameters
equationA string representing an infix equation.
Returns
QString A string representing the given equation converted to postfix format.

Definition at line 241 of file InlineCalculator.cpp.

References Isis::InfixToPostfix::convert(), and equation().

Referenced by compile().

◆ variable()

void Isis::InlineCalculator::variable ( const QVariant &  variable)
protected

Pushes the given value onto the stack as a variable.

This method adds the given variant value to the stack as a variable.

Parameters
variableQVariant containing the name of the variable. Usually a QString.
Exceptions
IException::User"Could not find variable in variable pool."

Definition at line 309 of file InlineCalculator.cpp.

References Isis::CalculatorVariablePool::exists(), Isis::Calculator::Push(), Isis::IException::User, Isis::CalculatorVariablePool::value(), and variables().

Referenced by compile().

◆ variables()

CalculatorVariablePool * Isis::InlineCalculator::variables ( )
private

Accesses the last variable pool in the current pool list.

If the list is empty, an error will be thrown.

Returns
CalculatorVariablePool The last variable pool in the current list.
Exceptions
IException::Programmer"Request for nonexistent variable pool.",

Definition at line 536 of file InlineCalculator.cpp.

References m_variablePoolList, and Isis::IException::Programmer.

Referenced by variable().

Member Data Documentation

◆ m_equation

QString Isis::InlineCalculator::m_equation
private

The equation to be evaluated.

Definition at line 108 of file InlineCalculator.h.

Referenced by compile(), equation(), and evaluate().

◆ m_functions

FxEqList Isis::InlineCalculator::m_functions
private

The list of pointers to function equations for the calculator.

Definition at line 106 of file InlineCalculator.h.

Referenced by compile(), destruct(), evaluate(), and size().

◆ m_fxPool

FxPoolType Isis::InlineCalculator::m_fxPool
private

The map between function names and equation lists.

Definition at line 107 of file InlineCalculator.h.

Referenced by addFunction(), destruct(), find(), and fxExists().

◆ m_variablePoolList

QList<CalculatorVariablePool *> Isis::InlineCalculator::m_variablePoolList
private

The list of variable pool pointers.

Definition at line 109 of file InlineCalculator.h.

Referenced by popVariables(), pushVariables(), and variables().

◆ p_valStack

QStack< QVector<double> >* Isis::Calculator::p_valStack
privateinherited

The current stack of arguments.

Definition at line 135 of file Calculator.h.


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