Isis 3 Developer Reference
InfixToPostfix.h
Go to the documentation of this file.
1 
23 #ifndef INFIXTOPOSTFIX_H_
24 #define INFIXTOPOSTFIX_H_
25 
26 #include <stack>
27 #include <iostream>
28 
29 #include <QList>
30 #include <QString>
31 
32 namespace Isis {
33  class InfixOperator;
34  class InfixFunction;
35 
62  public:
64  virtual ~InfixToPostfix();
65 
66  QString convert(const QString &infix);
67  QString tokenizeEquation(const QString &equation);
68 
69  protected:
70 
71  virtual bool isKnownSymbol(QString representation);
72  virtual InfixOperator *findOperator(QString representation);
73 
75 
76  private:
77  void initialize();
78  void uninitialize();
79 
80  QString formatFunctionCalls(QString equation);
81  QString cleanSpaces(QString equation);
82 
83  void closeParenthesis(QString &postfix, std::stack<InfixOperator> &theStack);
84  void addOperator(QString &postfix, const InfixOperator &op, std::stack<InfixOperator> &theStack);
85  bool isFunction(QString representation);
86  void checkArgument(QString funcName, int argNum, QString argument);
87  };
88 
96  class InfixOperator {
97  public:
98  InfixOperator(int prec, QString inString, bool isFunc = false) {
99  m_precedence = prec;
100  m_inputString = inString;
101  m_outputString = inString;
102  m_isFunction = isFunc;
103  }
104 
105  InfixOperator(int prec, QString inString, QString outString,
106  bool isFunc = false) {
107  m_precedence = prec;
108  m_inputString = inString;
109  m_outputString = outString;
110  m_isFunction = isFunc;
111  }
112 
113  const QString &inputString() const {
114  return m_inputString;
115  }
116 
117  const QString &outputString() const {
118  return m_outputString;
119  }
120 
121  int precedence() const {
122  return m_precedence;
123  }
124 
125  bool isFunction() const {
126  return m_isFunction;
127  }
128 
129 
130  private:
131  int m_precedence;
132  QString m_inputString;
133  QString m_outputString;
134  bool m_isFunction;
135  };
136 
137 
145  class InfixFunction : public InfixOperator {
146  public:
147  InfixFunction(QString inString, int argCount) :
148  InfixOperator(-1, inString, true) {
149  m_numArguments = argCount;
150  }
151 
152  InfixFunction(QString inString, QString outString, int argCount) :
153  InfixOperator(-1, inString, outString, true) {
154  m_numArguments = argCount;
155  }
156 
157  int argumentCount() const {
158  return m_numArguments;
159  }
160 
161  private:
162  int m_numArguments;
163  };
164 };
165 
166 #endif
QString tokenizeEquation(const QString &equation)
This method will add spaces between all operators and numbers, making it possible to get each element...
Definition: InfixToPostfix.cpp:384
const QString & inputString() const
Definition: InfixToPostfix.h:113
QString convert(const QString &infix)
This method converts infix to postfix.
Definition: InfixToPostfix.cpp:154
virtual InfixOperator * findOperator(QString representation)
This method will return a pointer to the operator represented by &#39;representation. ...
Definition: InfixToPostfix.cpp:362
InfixFunction(QString inString, int argCount)
Definition: InfixToPostfix.h:147
bool isFunction() const
Definition: InfixToPostfix.h:125
InfixOperator(int prec, QString inString, QString outString, bool isFunc=false)
Definition: InfixToPostfix.h:105
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
Definition: InfixToPostfix.h:145
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
Definition: InfixToPostfix.h:96
InfixOperator(int prec, QString inString, bool isFunc=false)
Definition: InfixToPostfix.h:98
InfixFunction(QString inString, QString outString, int argCount)
Definition: InfixToPostfix.h:152
int argumentCount() const
Definition: InfixToPostfix.h:157
const QString & outputString() const
Definition: InfixToPostfix.h:117
Converter for math equations.
Definition: InfixToPostfix.h:61
Definition: BoxcarCachingAlgorithm.h:29
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
int precedence() const
Definition: InfixToPostfix.h:121
virtual ~InfixToPostfix()
Definition: InfixToPostfix.cpp:38
QList< InfixOperator * > p_operators
Definition: InfixToPostfix.h:74
InfixToPostfix()
Constructor.
Definition: InfixToPostfix.cpp:34
virtual bool isKnownSymbol(QString representation)
This method will return true if it believes the argument represents a valid function or operator...
Definition: InfixToPostfix.cpp:268