Isis 3.0 Programmer Reference
Back | Home
InlineCalculator.h
Go to the documentation of this file.
1 #ifndef InlineCalculator_h
2 #define InlineCalculator_h
3 
28 // parent class
29 #include "Calculator.h"
30 
31 #include <QList>
32 #include <QMap>
33 #include <QString>
34 #include <QVector>
35 
36 class QVariant;
37 
38 namespace Isis {
39 
40  class CalculatorVariablePool;
41  class FxBinder;
42  class ParamaterFx;
43  class VoidFx;
44 
49  #define CALL_MEMBER_FN(object, ptrToMember) ((object).*(ptrToMember))
50 
66  class InlineCalculator : public Calculator {
67 
68  public:
69 
71  InlineCalculator(const QString &equation);
72  virtual ~InlineCalculator();
73 
74  int size() const;
75 
76  QString equation() const;
77  bool compile(const QString &equation);
78 
81 
82  protected:
84  typedef FxBinder *FxTypePtr;
85 
86  // Implementations of local/new functions
87  void scalar(const QVariant &scalar);
88  void variable(const QVariant &variable);
89 
90  void floatModulus();
91  void radians();
92  void degrees();
93  void pi();
94  void eConstant();
95 
96  virtual QString toPostfix(const QString &equation) const;
97  bool isScalar(const QString &scalar);
98  bool isVariable(const QString &str);
99 
100  // Derived classes can be added with these methods for customization.
101  // See FxBinder().
102  bool fxExists(const QString &fxname) const;
103  FxTypePtr addFunction(FxTypePtr function);
104 
105  virtual bool orphanTokenHandler(const QString &token);
106 
107  private:
112 
113  void pushVariables(CalculatorVariablePool *variablePool);
115  void popVariables();
116 
117  FxTypePtr find(const QString &fxname);
118  void initialize();
119  void destruct();
120 
123  QString m_equation;
125 
126  };
127 
128 
137  public:
140 
141  virtual bool exists(const QString &variable) const;
142  virtual QVector<double> value(const QString &variable,
143  const int &index = 0) const;
144  virtual void add(const QString &key, QVector<double> &values);
145  };
146 
147 
155  class FxBinder {
156  public:
157  FxBinder(const QString &name);
158  virtual ~FxBinder();
159 
160  QString name() const;
161  void execute();
162  void operator()();
163 
168  virtual void dispatch() = 0;
169  virtual QVariant args();
170 
171  private:
172  QString m_name;
173  };
174 
175 
184  class InlineVoidFx : public FxBinder {
185  public:
187  typedef void (InlineCalculator::*calcOp)();
188 
189  InlineVoidFx(const QString &name, calcOp function,
190  InlineCalculator *calculator);
191  virtual ~InlineVoidFx();
192  void dispatch();
193 
194  private:
197  };
198 
199 
208  class ParameterFx : public FxBinder {
209  public:
211  typedef void (InlineCalculator::*calcOp)(const QVariant &arg);
212 
213  ParameterFx(const QString &name, calcOp function,
214  InlineCalculator *calculator);
215  virtual ~ParameterFx();
216  void dispatch();
217 
218  private:
221  };
222 
223 
232  class VoidFx : public FxBinder {
233  public:
235  typedef void (Calculator::*calcOp)();
236 
237  VoidFx(const QString &name, calcOp function,
238  InlineCalculator *calculator);
239  virtual ~VoidFx();
240  void dispatch();
241 
242  private:
245  };
246 
247  // this is a global method, outside of all classes.
248  double floatModulusOperator(double a, double b);
249 
250 } // Namespace Isis
251 
252 #endif
QList< CalculatorVariablePool * > m_variablePoolList
The list of variable pool pointers.
virtual QString toPostfix(const QString &equation) const
Converts the given string from infix to postfix format.
void floatModulus()
Pops the top two vectors off the current stack and performs the floatModulusOperator() on the corresp...
CalculatorVariablePool()
Constructs a CalculatorVariablePool object.
void variable(const QVariant &variable)
Pushes the given value onto the stack as a variable.
virtual void add(const QString &key, QVector< double > &values)
Add a parameter to the variable pool.
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.
FxBinder(const QString &name)
Constructs a function binder given a name.
void degrees()
Pops the top vector off the current stack and converts from radians to degrees.
void(InlineCalculator::* calcOp)()
Defines an InlineCalculator function that takes no arguments.
InlineCalculator * m_calc
The Calculator used to evaluate this function.
virtual ~InlineCalculator()
Destroys the InlineCalculator object.
bool fxExists(const QString &fxname) const
Determines whether the given function name exists in the current function pool.
Provides a calculator for inline equations.
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.
FxBinder * FxTypePtr
Defintion for a FxTypePtr, a pointer to a function binder (FxBinder)
int size() const
Accesses the number of functions, operators, variables, and scalars to be executed.
bool isScalar(const QString &scalar)
Determines whether the given string contains a scalar value (i.e.
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.
void(Calculator::* calcOp)()
Defines a Calculator function that takes no arguments.
virtual ~InlineVoidFx()
Destroys the InlineVoidFx object.
QVector< double > evaluate()
Evaluate compiled equation with existing variable pool.
bool compile(const QString &equation)
Compiles the given equation for evaluation.
QVector< FxTypePtr > FxEqList
Definition for a FxEqList, a vector of function type pointers.
QMap< QString, FxTypePtr > FxPoolType
Definition for a FxPoolType, a map between a string and function type pointer.
double floatModulusOperator(double a, double b)
Determines the remainder of the quotient a/b whose sign is the same as that of a. ...
InlineCalculator * m_calc
The InlineCalculator used to evaluate this function.
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.
QString equation() const
Accesses the string representation of the current equation, in postfix format.
virtual QVector< double > value(const QString &variable, const int &index=0) const
Return vector of doubles for Calculator functions.
This is the parent class to the various function classes.
FxEqList m_functions
The list of pointers to function equations for the calculator.
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.
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.
void radians()
Pops the top vector off the current stack and converts from degrees to radians.
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.
QString name() const
The name assigned to this function binder.
This class is used to bind function names with corresponding InlineCalculator functions that do not t...
virtual bool exists(const QString &variable) const
Returns true so the real error can be reported.
virtual QVariant args()
Accesses the arguments for this function.
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.
InlineCalculator()
Constructs an InlineCalculator object by initializing the operator lookup list.
QString m_equation
The equation to be evaluated.
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.
~CalculatorVariablePool()
Destroys the CalculatorVariablePool object.
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...
void(InlineCalculator::* calcOp)(const QVariant &arg)
Defines an InlineCalculator function that takes arguments.
This class is used to bind function names with corresponding Calculator functions that take a paramet...
Calculator for arrays.
Definition: Calculator.h:66
CalculatorVariablePool * variables()
Accesses the last variable pool in the current pool list.

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 ISIS Support Center
File Modified: 07/12/2023 23:20:35