File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis Developer Reference
InlineCalculator.h
Go to the documentation of this file.
1 #ifndef InlineCalculator_h
2 #define InlineCalculator_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 // parent class
11 #include "Calculator.h"
12 
13 #include <QList>
14 #include <QMap>
15 #include <QString>
16 #include <QVector>
17 
18 class QVariant;
19 
20 namespace Isis {
21 
22  class CalculatorVariablePool;
23  class FxBinder;
24  class ParamaterFx;
25  class VoidFx;
26 
31  #define CALL_MEMBER_FN(object, ptrToMember) ((object).*(ptrToMember))
32 
49  class InlineCalculator : public Calculator {
50 
51  public:
52 
54  InlineCalculator(const QString &equation);
55  virtual ~InlineCalculator();
56 
57  int size() const;
58 
59  QString equation() const;
60  bool compile(const QString &equation);
61 
64 
65  protected:
67  typedef FxBinder *FxTypePtr;
68 
69  // Implementations of local/new functions
70  void scalar(const QVariant &scalar);
71  void variable(const QVariant &variable);
72 
73  void floatModulus();
74  void radians();
75  void degrees();
76  void logicalOr();
77  void logicalAnd();
78  void pi();
79  void eConstant();
80 
81  virtual QString toPostfix(const QString &equation) const;
82  bool isScalar(const QString &scalar);
83  bool isVariable(const QString &str);
84 
85  // Derived classes can be added with these methods for customization.
86  // See FxBinder().
87  bool fxExists(const QString &fxname) const;
89 
90  virtual bool orphanTokenHandler(const QString &token);
91 
92  private:
97 
98  void pushVariables(CalculatorVariablePool *variablePool);
99  CalculatorVariablePool *variables();
100  void popVariables();
101 
102  FxTypePtr find(const QString &fxname);
103  void initialize();
104  void destruct();
105 
106  FxEqList m_functions;
107  FxPoolType m_fxPool;
108  QString m_equation;
109  QList<CalculatorVariablePool *> m_variablePoolList;
110 
111  };
112 
113 
122  public:
125 
126  virtual bool exists(const QString &variable) const;
127  virtual QVector<double> value(const QString &variable,
128  const int &index = 0) const;
129  virtual void add(const QString &key, QVector<double> &values);
130  };
131 
132 
140  class FxBinder {
141  public:
142  FxBinder(const QString &name);
143  virtual ~FxBinder();
144 
145  QString name() const;
146  void execute();
147  void operator()();
148 
153  virtual void dispatch() = 0;
154  virtual QVariant args();
155 
156  private:
157  QString m_name;
158  };
159 
160 
169  class InlineVoidFx : public FxBinder {
170  public:
172  typedef void (InlineCalculator::*calcOp)();
173 
174  InlineVoidFx(const QString &name, calcOp function,
175  InlineCalculator *calculator);
176  virtual ~InlineVoidFx();
177  void dispatch();
178 
179  private:
180  calcOp m_func;
181  InlineCalculator *m_calc;
182  };
183 
184 
193  class ParameterFx : public FxBinder {
194  public:
196  typedef void (InlineCalculator::*calcOp)(const QVariant &arg);
197 
198  ParameterFx(const QString &name, calcOp function,
199  InlineCalculator *calculator);
200  virtual ~ParameterFx();
201  void dispatch();
202 
203  private:
204  calcOp m_func;
205  InlineCalculator *m_calc;
206  };
207 
208 
217  class VoidFx : public FxBinder {
218  public:
220  typedef void (Calculator::*calcOp)();
221 
222  VoidFx(const QString &name, calcOp function,
223  InlineCalculator *calculator);
224  virtual ~VoidFx();
225  void dispatch();
226 
227  private:
228  calcOp m_func;
229  InlineCalculator *m_calc;
230  };
231 
232  // this is a global method, outside of all classes.
233  double floatModulusOperator(double a, double b);
234 
235 } // Namespace Isis
236 
237 #endif
Isis::FxBinder::args
virtual QVariant args()
Accesses the arguments for this function.
Definition: InlineCalculator.cpp:768
Isis::Calculator::Push
void Push(double scalar)
Push a scalar onto the stack.
Definition: Calculator.cpp:893
Isis::Calculator::Arcsine
void Arcsine()
Pops one element and push the arcsine.
Definition: Calculator.cpp:767
Isis::Calculator::Cosine
void Cosine()
Pops one element and push the cosine.
Definition: Calculator.cpp:717
Isis::Calculator::Tangent
void Tangent()
Pops one element and push the tangent.
Definition: Calculator.cpp:727
Isis::FxBinder::~FxBinder
virtual ~FxBinder()
Destroys the FxBinder object.
Definition: InlineCalculator.cpp:730
Isis::Calculator::Add
void Add()
Pops two elements, adds them, then pushes the sum on the stack.
Definition: Calculator.cpp:330
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::Calculator::Cosecant
void Cosecant()
Pops one element and push the cosecant.
Definition: Calculator.cpp:737
Calculator.h
Isis::Calculator::Or
void Or()
Pop two elements, OR them, then push the result on the stack.
Definition: Calculator.cpp:693
Isis::FxBinder::FxBinder
FxBinder(const QString &name)
Constructs a function binder given a name.
Definition: InlineCalculator.cpp:723
Isis::ParameterFx::calcOp
void(InlineCalculator::* calcOp)(const QVariant &arg)
Defines an InlineCalculator function that takes arguments.
Definition: InlineCalculator.h:196
Isis::Calculator::Multiply
void Multiply()
Pops two elements, multiplies them, then pushes the product on the stack.
Definition: Calculator.cpp:317
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::Calculator::Modulus
void Modulus()
Pops two elements, mods them, then pushes the result on the stack.
Definition: Calculator.cpp:366
Isis::Calculator::Equal
void Equal()
Pop two elements off the stack and compare them to see where one is equal to the other,...
Definition: Calculator.cpp:617
Isis::InfixToPostfix::convert
QString convert(const QString &infix)
This method converts infix to postfix.
Definition: InfixToPostfix.cpp:139
Isis::ParameterFx::~ParameterFx
virtual ~ParameterFx()
Destroys the ParameterFx object.
Definition: InlineCalculator.cpp:825
Isis::InlineVoidFx::calcOp
void(InlineCalculator::* calcOp)()
Defines an InlineCalculator function that takes no arguments.
Definition: InlineCalculator.h:172
Isis::Calculator
Calculator for arrays.
Definition: Calculator.h:55
Isis::VoidFx::calcOp
void(Calculator::* calcOp)()
Defines a Calculator function that takes no arguments.
Definition: InlineCalculator.h:220
Isis::Calculator::Arctangent
void Arctangent()
Pops one element and push the arctangent.
Definition: Calculator.cpp:787
NaifStatus.h
Isis::InlineCalculator::logicalOr
void logicalOr()
Pops the top two vectors off the current stack and performs a logical or on each pair.
Definition: InlineCalculator.cpp:393
Isis::InlineCalculator::~InlineCalculator
virtual ~InlineCalculator()
Destroys the InlineCalculator object.
Definition: InlineCalculator.cpp:61
Isis::InlineCalculator::equation
QString equation() const
Accesses the string representation of the current equation, in postfix format.
Definition: InlineCalculator.cpp:85
Isis::InlineCalculator::variable
void variable(const QVariant &variable)
Pushes the given value onto the stack as a variable.
Definition: InlineCalculator.cpp:309
Isis::InlineCalculator::orphanTokenHandler
virtual bool orphanTokenHandler(const QString &token)
Default token handler if it is undefined during parsing/compilation.
Definition: InlineCalculator.cpp:512
Isis::InlineCalculator::eConstant
void eConstant()
Pushes the Euler constant (e) onto the current stack.
Definition: InlineCalculator.cpp:446
Isis::ParameterFx
This class is used to bind function names with corresponding Calculator functions that take a paramet...
Definition: InlineCalculator.h:193
Isis::InlineCalculator::FxTypePtr
FxBinder * FxTypePtr
Defintion for a FxTypePtr, a pointer to a function binder (FxBinder)
Definition: InlineCalculator.h:67
Isis::Calculator::Sine
void Sine()
Pops one element and push the sine.
Definition: Calculator.cpp:707
Isis::Calculator::Divide
void Divide()
Pops two, divides them, then pushes the quotient on the stack.
Definition: Calculator.cpp:354
Isis::ParameterFx::ParameterFx
ParameterFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs a Parameter function from the given name (containing the appropriate parameters),...
Definition: InlineCalculator.cpp:815
Isis::CalculatorVariablePool::~CalculatorVariablePool
~CalculatorVariablePool()
Destroys the CalculatorVariablePool object.
Definition: InlineCalculator.cpp:666
Isis::FxBinder::dispatch
virtual void dispatch()=0
This method defines how to execute this function.
QStringList
IString.h
Isis::InlineCalculator::floatModulus
void floatModulus()
Pops the top two vectors off the current stack and performs the floatModulusOperator() on the corresp...
Definition: InlineCalculator.cpp:345
Isis::Calculator::Subtract
void Subtract()
Pops two elements, subtracts them, then pushes the difference on the stack.
Definition: Calculator.cpp:342
Isis::IException::append
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
Definition: IException.cpp:409
Isis::InlineCalculator::radians
void radians()
Pops the top vector off the current stack and converts from degrees to radians.
Definition: InlineCalculator.cpp:360
InlineInfixToPostfix.h
Isis::floatModulusOperator
double floatModulusOperator(double a, double b)
Determines the remainder of the quotient a/b whose sign is the same as that of a.
Definition: InlineCalculator.cpp:335
Isis::InlineVoidFx::~InlineVoidFx
virtual ~InlineVoidFx()
Destroys the InlineVoidFx object.
Definition: InlineCalculator.cpp:791
Isis::Calculator::AbsoluteValue
void AbsoluteValue()
Pop an element, compute its absolute value, then push the result on the stack.
Definition: Calculator.cpp:407
Isis::InlineCalculator::evaluate
QVector< double > evaluate()
Evaluate compiled equation with existing variable pool.
Definition: InlineCalculator.cpp:218
Isis::CalculatorVariablePool::CalculatorVariablePool
CalculatorVariablePool()
Constructs a CalculatorVariablePool object.
Definition: InlineCalculator.cpp:659
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::InlineVoidFx::dispatch
void dispatch()
Calls the function corresponding to this object using its stored InlineCalculator and InlineCalculato...
Definition: InlineCalculator.cpp:799
Isis::InlineInfixToPostfix
A parser for converting equation strings to postfix.
Definition: InlineInfixToPostfix.h:34
Isis::Calculator::Cotangent
void Cotangent()
Pops one element and push the cotangent.
Definition: Calculator.cpp:757
Isis::Calculator::Log10
void Log10()
Pop an element, compute its base 10 log, then push the result on the stack.
Definition: Calculator.cpp:429
Isis::InlineCalculator
Provides a calculator for inline equations.
Definition: InlineCalculator.h:49
CALL_MEMBER_FN
#define CALL_MEMBER_FN(object, ptrToMember)
Macro for calling member functions.
Definition: InlineCalculator.h:31
Isis::InlineCalculator::size
int size() const
Accesses the number of functions, operators, variables, and scalars to be executed.
Definition: InlineCalculator.cpp:73
Isis::CalculatorVariablePool::add
virtual void add(const QString &key, QVector< double > &values)
Add a parameter to the variable pool.
Definition: InlineCalculator.cpp:711
Isis::InlineCalculator::degrees
void degrees()
Pops the top vector off the current stack and converts from radians to degrees.
Definition: InlineCalculator.cpp:375
Isis::CalculatorVariablePool::value
virtual QVector< double > value(const QString &variable, const int &index=0) const
Return vector of doubles for Calculator functions.
Definition: InlineCalculator.cpp:691
Isis::Calculator::SquareRoot
void SquareRoot()
Pop an element, compute its square root, then push the root on the stack.
Definition: Calculator.cpp:397
Isis::VoidFx::dispatch
void dispatch()
Calls the function corresponding to this object using its stored Calculator and Calculator operator.
Definition: InlineCalculator.cpp:865
Isis::Calculator::RightShift
void RightShift()
Pop the top element, then perform a right shift with zero fill.
Definition: Calculator.cpp:480
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::InlineCalculator::isVariable
bool isVariable(const QString &str)
Determines whether the given string is a variable.
Definition: InlineCalculator.cpp:275
Isis::InlineCalculator::fxExists
bool fxExists(const QString &fxname) const
Determines whether the given function name exists in the current function pool.
Definition: InlineCalculator.cpp:461
Isis::Calculator::Arccosine
void Arccosine()
Pops one element and push the arccosine.
Definition: Calculator.cpp:777
Isis::Calculator::LeftShift
void LeftShift()
Pop the top element, then perform a left shift with zero fill.
Definition: Calculator.cpp:441
Isis::CalculatorVariablePool
This is a simple class to model a Calculator Variable Pool.
Definition: InlineCalculator.h:121
Isis::Calculator::GreaterThanOrEqual
void GreaterThanOrEqual()
Pop two elements off the stack and compare them to see where one is greater than or equal to the othe...
Definition: Calculator.cpp:632
Isis::InlineVoidFx::InlineVoidFx
InlineVoidFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs an InlineVoid function from the given name, InlineCalculator operator, and InlineCalculato...
Definition: InlineCalculator.cpp:781
Isis::Calculator::LessThan
void LessThan()
Pop two elements off the stack and compare them to see where one is less than the other,...
Definition: Calculator.cpp:602
InlineCalculator.h
IException.h
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::Calculator::Pop
QVector< double > Pop(bool keepSpecials=false)
Pop an element off the stack.
Definition: Calculator.cpp:949
Isis::InlineCalculator::addFunction
FxTypePtr addFunction(FxTypePtr function)
Adds a function to the function pool.
Definition: InlineCalculator.cpp:478
Isis::Calculator::GreaterThan
void GreaterThan()
Pop two elements off the stack and compare them to see where one is greater than the other,...
Definition: Calculator.cpp:587
Isis::InlineVoidFx
This class is used to bind function names with corresponding InlineCalculator functions that do not t...
Definition: InlineCalculator.h:169
Isis::ParameterFx::dispatch
void dispatch()
Calls the function corresponding to this object using its stored InlineCalculator,...
Definition: InlineCalculator.cpp:834
Isis::Calculator::PerformOperation
void PerformOperation(QVector< double > &results, QVector< double >::iterator arg1Start, QVector< double >::iterator arg1End, double operation(double))
Performs the mathematical operations on each argument.
Definition: Calculator.cpp:1037
Isis::Calculator::LessThanOrEqual
void LessThanOrEqual()
Pop two elements off the stack and compare them to see where one is less than or equal to the other,...
Definition: Calculator.cpp:647
Isis::CalculatorVariablePool::exists
virtual bool exists(const QString &variable) const
Returns true so the real error can be reported.
Definition: InlineCalculator.cpp:676
Isis::E
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:39
Isis::InlineCalculator::isScalar
bool isScalar(const QString &scalar)
Determines whether the given string contains a scalar value (i.e.
Definition: InlineCalculator.cpp:255
QMap< QString, FxTypePtr >
Isis::Calculator::Arctangent2
void Arctangent2()
Pops two elements and push the arctangent.
Definition: Calculator.cpp:827
Isis::InlineCalculator::toPostfix
virtual QString toPostfix(const QString &equation) const
Converts the given string from infix to postfix format.
Definition: InlineCalculator.cpp:241
Isis::VoidFx::~VoidFx
virtual ~VoidFx()
Destroys the VoidFx object.
Definition: InlineCalculator.cpp:857
Isis::FxBinder::execute
void execute()
Executes the function.
Definition: InlineCalculator.cpp:748
Isis::FxBinder::operator()
void operator()()
Executes the function.
Definition: InlineCalculator.cpp:757
Isis::Calculator::Exponent
void Exponent()
Pops two elements, computes the power then pushes the result on the stack The exponent has to be a sc...
Definition: Calculator.cpp:382
Isis::Calculator::StackSize
int StackSize()
Returns the current stack size.
Definition: Calculator.cpp:874
QVector< double >
Isis::Calculator::Clear
virtual void Clear()
Clear out the stack.
Definition: Calculator.cpp:1021
Isis::Calculator::Log
void Log()
Pop an element, compute its log, then push the result on the stack.
Definition: Calculator.cpp:419
Isis::Calculator::Secant
void Secant()
Pops one element and push the secant.
Definition: Calculator.cpp:747
Isis::VoidFx
This class is used to bind function names with corresponding Calculator functions that do not take pa...
Definition: InlineCalculator.h:217
Isis::InlineCalculator::InlineCalculator
InlineCalculator()
Constructs an InlineCalculator object by initializing the operator lookup list.
Definition: InlineCalculator.cpp:41
Isis::InlineCalculator::compile
bool compile(const QString &equation)
Compiles the given equation for evaluation.
Definition: InlineCalculator.cpp:106
Isis::Calculator::MaximumPixel
void MaximumPixel()
Pop two elements, then push the maximum on a pixel by pixel basis back on the stack.
Definition: Calculator.cpp:572
Isis::FxBinder::name
QString name() const
The name assigned to this function binder.
Definition: InlineCalculator.cpp:739
Isis::VoidFx::VoidFx
VoidFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs a Void function from the given name, Calculator operator, and Calculator.
Definition: InlineCalculator.cpp:847
Isis::InlineCalculator::pi
void pi()
Pushes the PI constant onto the current stack.
Definition: InlineCalculator.cpp:437
Isis::InlineCalculator::logicalAnd
void logicalAnd()
Pops the top two vectors off the current stack and performs a logical and on each pair.
Definition: InlineCalculator.cpp:417
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Calculator::NotEqual
void NotEqual()
Pop two elements off the stack and compare them to see where one is not equal to the other,...
Definition: Calculator.cpp:662
Isis::Calculator::MinimumPixel
void MinimumPixel()
Pop two elements, then push the minimum on a pixel by pixel basis back on the stack.
Definition: Calculator.cpp:557
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126
Isis::Calculator::Negative
void Negative()
Pops an element, negates it, then pushes the result.
Definition: Calculator.cpp:307
Isis::InlineCalculator::scalar
void scalar(const QVariant &scalar)
Pushes the given value onto the stack as a scalar.
Definition: InlineCalculator.cpp:294
Isis::Calculator::And
void And()
Pop two elements, AND them, then push the result on the stack.
Definition: Calculator.cpp:679
Isis::FxBinder
This is the parent class to the various function classes.
Definition: InlineCalculator.h:140

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:11:23