Isis 3 Developer Reference
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 
67  class InlineCalculator : public Calculator {
68 
69  public:
70 
72  InlineCalculator(const QString &equation);
73  virtual ~InlineCalculator();
74 
75  int size() const;
76 
77  QString equation() const;
78  bool compile(const QString &equation);
79 
82 
83  protected:
85  typedef FxBinder *FxTypePtr;
86 
87  // Implementations of local/new functions
88  void scalar(const QVariant &scalar);
89  void variable(const QVariant &variable);
90 
91  void floatModulus();
92  void radians();
93  void degrees();
94  void logicalOr();
95  void logicalAnd();
96  void pi();
97  void eConstant();
98 
99  virtual QString toPostfix(const QString &equation) const;
100  bool isScalar(const QString &scalar);
101  bool isVariable(const QString &str);
102 
103  // Derived classes can be added with these methods for customization.
104  // See FxBinder().
105  bool fxExists(const QString &fxname) const;
106  FxTypePtr addFunction(FxTypePtr function);
107 
108  virtual bool orphanTokenHandler(const QString &token);
109 
110  private:
115 
116  void pushVariables(CalculatorVariablePool *variablePool);
117  CalculatorVariablePool *variables();
118  void popVariables();
119 
120  FxTypePtr find(const QString &fxname);
121  void initialize();
122  void destruct();
123 
124  FxEqList m_functions;
125  FxPoolType m_fxPool;
126  QString m_equation;
127  QList<CalculatorVariablePool *> m_variablePoolList;
128 
129  };
130 
131 
140  public:
143 
144  virtual bool exists(const QString &variable) const;
145  virtual QVector<double> value(const QString &variable,
146  const int &index = 0) const;
147  virtual void add(const QString &key, QVector<double> &values);
148  };
149 
150 
158  class FxBinder {
159  public:
160  FxBinder(const QString &name);
161  virtual ~FxBinder();
162 
163  QString name() const;
164  void execute();
165  void operator()();
166 
171  virtual void dispatch() = 0;
172  virtual QVariant args();
173 
174  private:
175  QString m_name;
176  };
177 
178 
187  class InlineVoidFx : public FxBinder {
188  public:
190  typedef void (InlineCalculator::*calcOp)();
191 
192  InlineVoidFx(const QString &name, calcOp function,
193  InlineCalculator *calculator);
194  virtual ~InlineVoidFx();
195  void dispatch();
196 
197  private:
198  calcOp m_func;
199  InlineCalculator *m_calc;
200  };
201 
202 
211  class ParameterFx : public FxBinder {
212  public:
214  typedef void (InlineCalculator::*calcOp)(const QVariant &arg);
215 
216  ParameterFx(const QString &name, calcOp function,
217  InlineCalculator *calculator);
218  virtual ~ParameterFx();
219  void dispatch();
220 
221  private:
222  calcOp m_func;
223  InlineCalculator *m_calc;
224  };
225 
226 
235  class VoidFx : public FxBinder {
236  public:
238  typedef void (Calculator::*calcOp)();
239 
240  VoidFx(const QString &name, calcOp function,
241  InlineCalculator *calculator);
242  virtual ~VoidFx();
243  void dispatch();
244 
245  private:
246  calcOp m_func;
247  InlineCalculator *m_calc;
248  };
249 
250  // this is a global method, outside of all classes.
251  double floatModulusOperator(double a, double b);
252 
253 } // Namespace Isis
254 
255 #endif
bool fxExists(const QString &fxname) const
Determines whether the given function name exists in the current function pool.
Definition: InlineCalculator.cpp:478
void floatModulus()
Pops the top two vectors off the current stack and performs the floatModulusOperator() on the corresp...
Definition: InlineCalculator.cpp:362
virtual QVector< double > value(const QString &variable, const int &index=0) const
Return vector of doubles for Calculator functions.
Definition: InlineCalculator.cpp:708
CalculatorVariablePool()
Constructs a CalculatorVariablePool object.
Definition: InlineCalculator.cpp:676
void variable(const QVariant &variable)
Pushes the given value onto the stack as a variable.
Definition: InlineCalculator.cpp:326
void(InlineCalculator::* calcOp)()
Defines an InlineCalculator function that takes no arguments.
Definition: InlineCalculator.h:190
virtual void add(const QString &key, QVector< double > &values)
Add a parameter to the variable pool.
Definition: InlineCalculator.cpp:728
void(Calculator::* calcOp)()
Defines a Calculator function that takes no arguments.
Definition: InlineCalculator.h:238
void logicalOr()
Pops the top two vectors off the current stack and performs a logical or on each pair.
Definition: InlineCalculator.cpp:410
void dispatch()
Calls the function corresponding to this object using its stored InlineCalculator, InlineCalculator operator, and arguments.
Definition: InlineCalculator.cpp:851
This is a simple class to model a Calculator Variable Pool.
Definition: InlineCalculator.h:139
virtual ~FxBinder()
Destroys the FxBinder object.
Definition: InlineCalculator.cpp:747
FxBinder(const QString &name)
Constructs a function binder given a name.
Definition: InlineCalculator.cpp:740
void degrees()
Pops the top vector off the current stack and converts from radians to degrees.
Definition: InlineCalculator.cpp:392
int size() const
Accesses the number of functions, operators, variables, and scalars to be executed.
Definition: InlineCalculator.cpp:90
void logicalAnd()
Pops the top two vectors off the current stack and performs a logical and on each pair...
Definition: InlineCalculator.cpp:434
virtual ~InlineCalculator()
Destroys the InlineCalculator object.
Definition: InlineCalculator.cpp:78
Provides a calculator for inline equations.
Definition: InlineCalculator.h:67
virtual bool exists(const QString &variable) const
Returns true so the real error can be reported.
Definition: InlineCalculator.cpp:693
virtual bool orphanTokenHandler(const QString &token)
Default token handler if it is undefined during parsing/compilation.
Definition: InlineCalculator.cpp:529
FxBinder * FxTypePtr
Defintion for a FxTypePtr, a pointer to a function binder (FxBinder)
Definition: InlineCalculator.h:85
bool isScalar(const QString &scalar)
Determines whether the given string contains a scalar value (i.e.
Definition: InlineCalculator.cpp:272
InlineVoidFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs an InlineVoid function from the given name, InlineCalculator operator, and InlineCalculato...
Definition: InlineCalculator.cpp:798
virtual ~InlineVoidFx()
Destroys the InlineVoidFx object.
Definition: InlineCalculator.cpp:808
QVector< double > evaluate()
Evaluate compiled equation with existing variable pool.
Definition: InlineCalculator.cpp:235
bool compile(const QString &equation)
Compiles the given equation for evaluation.
Definition: InlineCalculator.cpp:123
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:352
QString equation() const
Accesses the string representation of the current equation, in postfix format.
Definition: InlineCalculator.cpp:102
QString name() const
The name assigned to this function binder.
Definition: InlineCalculator.cpp:756
virtual QString toPostfix(const QString &equation) const
Converts the given string from infix to postfix format.
Definition: InlineCalculator.cpp:258
bool isVariable(const QString &str)
Determines whether the given string is a variable.
Definition: InlineCalculator.cpp:292
void(InlineCalculator::* calcOp)(const QVariant &arg)
Defines an InlineCalculator function that takes arguments.
Definition: InlineCalculator.h:214
This is the parent class to the various function classes.
Definition: InlineCalculator.h:158
virtual ~ParameterFx()
Destroys the ParameterFx object.
Definition: InlineCalculator.cpp:842
This class is used to bind function names with corresponding Calculator functions that do not take pa...
Definition: InlineCalculator.h:235
void operator()()
Executes the function.
Definition: InlineCalculator.cpp:774
void pi()
Pushes the PI constant onto the current stack.
Definition: InlineCalculator.cpp:454
void radians()
Pops the top vector off the current stack and converts from degrees to radians.
Definition: InlineCalculator.cpp:377
ParameterFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs a Parameter function from the given name (containing the appropriate parameters), InlineCalculator operator, and InlineCalculator.
Definition: InlineCalculator.cpp:832
This class is used to bind function names with corresponding InlineCalculator functions that do not t...
Definition: InlineCalculator.h:187
virtual QVariant args()
Accesses the arguments for this function.
Definition: InlineCalculator.cpp:785
virtual ~VoidFx()
Destroys the VoidFx object.
Definition: InlineCalculator.cpp:874
void execute()
Executes the function.
Definition: InlineCalculator.cpp:765
void dispatch()
Calls the function corresponding to this object using its stored Calculator and Calculator operator...
Definition: InlineCalculator.cpp:882
VoidFx(const QString &name, calcOp function, InlineCalculator *calculator)
Constructs a Void function from the given name, Calculator operator, and Calculator.
Definition: InlineCalculator.cpp:864
Definition: BoxcarCachingAlgorithm.h:29
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
InlineCalculator()
Constructs an InlineCalculator object by initializing the operator lookup list.
Definition: InlineCalculator.cpp:58
void eConstant()
Pushes the Euler constant (e) onto the current stack.
Definition: InlineCalculator.cpp:463
virtual void dispatch()=0
This method defines how to execute this function.
FxTypePtr addFunction(FxTypePtr function)
Adds a function to the function pool.
Definition: InlineCalculator.cpp:495
~CalculatorVariablePool()
Destroys the CalculatorVariablePool object.
Definition: InlineCalculator.cpp:683
void scalar(const QVariant &scalar)
Pushes the given value onto the stack as a scalar.
Definition: InlineCalculator.cpp:311
void dispatch()
Calls the function corresponding to this object using its stored InlineCalculator and InlineCalculato...
Definition: InlineCalculator.cpp:816
This class is used to bind function names with corresponding Calculator functions that take a paramet...
Definition: InlineCalculator.h:211
Calculator for arrays.
Definition: Calculator.h:70