32 #include <QStringList> 37 #include <boost/foreach.hpp> 127 tokenOps = tokenOps.simplified();
130 QString error =
"Errors parsing inline equation[" +
equation +
"].";
138 while ( !tokenList.isEmpty() ) {
139 QString token = tokenList.takeFirst();
140 if ( !token.isEmpty() ) {
166 error =
"Equation element (" + token +
") invalid - token not recognized.";
184 return (nerrors == 0);
214 "Calculation with variable pool failed.",
242 QString msg =
"Too many operands in the equation [" +
m_equation +
"].";
273 if (
scalar.isEmpty())
return (
false);
329 if (variablePool->
exists(key)) {
336 QString error =
"Could not find variable [" + key +
"] in variable pool.";
380 BOOST_FOREACH(
double d, degree) {
381 result.push_back(d * rpd_c());
395 BOOST_FOREACH(
double r,
radians) {
396 result.push_back(r * dpr_c());
414 if ( inputA.size() != inputB.size() ) {
415 QString msg =
"Failed performing logical or operation, " 416 "input vectors are of differnet lengths.";
419 for (
int i = 0; i < inputA.size(); i++) {
420 results.push_back( inputA[i] || inputB[i] );
438 if ( inputA.size() != inputB.size() ) {
439 QString msg =
"Failed performing logical and operation, " 440 "input vectors are of differnet lengths.";
443 for (
int i = 0; i < inputA.size(); i++) {
444 results.push_back( inputA[i] && inputB[i] );
498 m_fxPool.insert(function->name(),
function);
501 QString msg =
"Function operator [" +
function->name() +
502 "] exists! Cannot replace existing functions in the pool :-(";
558 "Request for nonexistent variable pool.",
586 FxPoolType::iterator fx =
m_fxPool.find(fxname);
587 if (
m_fxPool.end() == fx )
return NULL;
709 const int &index)
const {
710 QString mess =
"No implementation in Calculator variable pool to provide " 711 " value for variable [" + variable +
"].";
729 QString mess =
"No implementation in Calculator variable pool to add " 730 " value for variable [" + key +
"].";
786 return (QVariant(
m_name));
void LessThanOrEqual()
Pop two elements off the stack and compare them to see where one is less than or equal to the other...
void And()
Pop two elements, AND them, then push the result on the stack.
void Divide()
Pops two, divides them, then pushes the quotient on the stack.
QList< CalculatorVariablePool * > m_variablePoolList
The list of variable pool pointers.
bool fxExists(const QString &fxname) const
Determines whether the given function name exists in the current function pool.
void Multiply()
Pops two elements, multiplies them, then pushes the product on the stack.
void floatModulus()
Pops the top two vectors off the current stack and performs the floatModulusOperator() on the corresp...
void NotEqual()
Pop two elements off the stack and compare them to see where one is not equal to the other...
void GreaterThan()
Pop two elements off the stack and compare them to see where one is greater than the other...
virtual QVector< double > value(const QString &variable, const int &index=0) const
Return vector of doubles for Calculator functions.
void LeftShift()
Pop the top element, then perform a left shift with zero fill.
CalculatorVariablePool()
Constructs a CalculatorVariablePool object.
void Arctangent()
Pops one element and push the arctangent.
void variable(const QVariant &variable)
Pushes the given value onto the stack as a variable.
void Arctangent2()
Pops two elements and push the arctangent.
virtual void add(const QString &key, QVector< double > &values)
Add a parameter to the variable pool.
void logicalOr()
Pops the top two vectors off the current stack and performs a logical or on each pair.
QString m_name
Name of function.
void dispatch()
Calls the function corresponding to this object using its stored InlineCalculator, InlineCalculator operator, and arguments.
This is a simple class to model a Calculator Variable Pool.
virtual ~FxBinder()
Destroys the FxBinder object.
void MinimumPixel()
Pop two elements, then push the minimum on a pixel by pixel basis back on the stack.
FxBinder(const QString &name)
Constructs a function binder given a name.
A parser for converting equation strings to postfix.
void degrees()
Pops the top vector off the current stack and converts from radians to degrees.
int size() const
Accesses the number of functions, operators, variables, and scalars to be executed.
void Or()
Pop two elements, OR them, then push the result on the stack.
QString convert(const QString &infix)
This method converts infix to postfix.
void Arccosine()
Pops one element and push the arccosine.
void LessThan()
Pop two elements off the stack and compare them to see where one is less than the other...
void logicalAnd()
Pops the top two vectors off the current stack and performs a logical and on each pair...
InlineCalculator * m_calc
The Calculator used to evaluate this function.
void Modulus()
Pops two elements, mods them, then pushes the result on the stack.
virtual ~InlineCalculator()
Destroys the InlineCalculator object.
void GreaterThanOrEqual()
Pop two elements off the stack and compare them to see where one is greater than or equal to the othe...
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
Namespace for the standard library.
void Cotangent()
Pops one element and push the cotangent.
QVector< double > Pop(bool keepSpecials=false)
Pop an element off the stack.
Provides a calculator for inline equations.
virtual bool exists(const QString &variable) const
Returns true so the real error can be reported.
virtual bool orphanTokenHandler(const QString &token)
Default token handler if it is undefined during parsing/compilation.
FxPoolType m_fxPool
The map between function names and equation lists.
bool isScalar(const QString &scalar)
Determines whether the given string contains a scalar value (i.e.
double toDouble(const QString &string)
Global function to convert from a string to a double.
This error is for when a programmer made an API call that was illegal.
void Negative()
Pops an element, negates it, then pushes the result.
void Log()
Pop an element, compute its log, then push the result on the stack.
InlineVoidFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs an InlineVoid function from the given name, InlineCalculator operator, and InlineCalculato...
InlineCalculator * m_calc
The InlineCalculator used to evaluate this function.
virtual ~InlineVoidFx()
Destroys the InlineVoidFx object.
void Arcsine()
Pops one element and push the arcsine.
QVector< double > evaluate()
Evaluate compiled equation with existing variable pool.
bool compile(const QString &equation)
Compiles the given equation for evaluation.
void PerformOperation(QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, double operation(double))
Performs the mathematical operations on each argument.
double floatModulusOperator(double a, double b)
Determines the remainder of the quotient a/b whose sign is the same as that of a. ...
QString equation() const
Accesses the string representation of the current equation, in postfix format.
void SquareRoot()
Pop an element, compute its square root, then push the root on the stack.
QString name() const
The name assigned to this function binder.
virtual QString toPostfix(const QString &equation) const
Converts the given string from infix to postfix format.
InlineCalculator * m_calc
The InlineCalculator used to evaluate this function.
void Add()
Pops two elements, adds them, then pushes the sum on the stack.
bool isVariable(const QString &str)
Determines whether the given string is a variable.
void popVariables()
Removes the last variable pool in the current variable pool list.
int StackSize()
Returns the current stack size.
#define _FILEINFO_
Macro for the filename and line number.
This is the parent class to the various function classes.
void Subtract()
Pops two elements, subtracts them, then pushes the difference on the stack.
A type of error that could only have occurred due to a mistake on the user's part (e...
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.
FxEqList m_functions
The list of pointers to function equations for the calculator.
A type of error that cannot be classified as any of the other error types.
virtual ~ParameterFx()
Destroys the ParameterFx object.
This class is used to bind function names with corresponding Calculator functions that do not take pa...
calcOp m_func
The InlineCalculator operator that takes parameters.
void destruct()
Discard of all the function pool and class resources.
void operator()()
Executes the function.
void initialize()
Adds the recognized functions to the function pool.
#define CALL_MEMBER_FN(object, ptrToMember)
Macro for calling member functions.
void Push(double scalar)
Push a scalar onto the stack.
calcOp m_func
The Calculator operator that takes no parameters.
void pushVariables(CalculatorVariablePool *variablePool)
Push the given variable pool onto the current variable pool list.
void pi()
Pushes the PI constant onto the current stack.
const double E
Sets some basic constants for use in ISIS programming.
void radians()
Pops the top vector off the current stack and converts from degrees to radians.
virtual void Clear()
Clear out the stack.
void AbsoluteValue()
Pop an element, compute its absolute value, then push the result on the stack.
FxTypePtr find(const QString &fxname)
Gets a pointer to the function from the current pool that corresponds to the given function name...
ParameterFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs a Parameter function from the given name (containing the appropriate parameters), InlineCalculator operator, and InlineCalculator.
calcOp m_func
The InlineCalculator operator that takes no parameters.
void MaximumPixel()
Pop two elements, then push the maximum on a pixel by pixel basis back on the stack.
void Secant()
Pops one element and push the secant.
This class is used to bind function names with corresponding InlineCalculator functions that do not t...
void Sine()
Pops one element and push the sine.
void RightShift()
Pop the top element, then perform a right shift with zero fill.
virtual QVariant args()
Accesses the arguments for this function.
void Tangent()
Pops one element and push the tangent.
virtual ~VoidFx()
Destroys the VoidFx object.
void execute()
Executes the function.
void dispatch()
Calls the function corresponding to this object using its stored Calculator and Calculator operator...
VoidFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs a Void function from the given name, Calculator operator, and Calculator.
Namespace for ISIS/Bullet specific routines.
InlineCalculator()
Constructs an InlineCalculator object by initializing the operator lookup list.
QString m_equation
The equation to be evaluated.
void Cosecant()
Pops one element and push the cosecant.
void eConstant()
Pushes the Euler constant (e) onto the current stack.
virtual void dispatch()=0
This method defines how to execute this function.
FxTypePtr addFunction(FxTypePtr function)
Adds a function to the function pool.
void Log10()
Pop an element, compute its base 10 log, then push the result on the stack.
void Exponent()
Pops two elements, computes the power then pushes the result on the stack The exponent has to be a sc...
~CalculatorVariablePool()
Destroys the CalculatorVariablePool object.
void Cosine()
Pops one element and push the cosine.
void scalar(const QVariant &scalar)
Pushes the given value onto the stack as a scalar.
void dispatch()
Calls the function corresponding to this object using its stored InlineCalculator and InlineCalculato...
This class is used to bind function names with corresponding Calculator functions that take a paramet...
CalculatorVariablePool * variables()
Accesses the last variable pool in the current pool list.