Isis Developer Reference
InfixToPostfix.h
Go to the documentation of this file.
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#ifndef INFIXTOPOSTFIX_H_
9#define INFIXTOPOSTFIX_H_
10
11#include <stack>
12#include <iostream>
13
14#include <QList>
15#include <QString>
16
17namespace Isis {
18 class InfixOperator;
19 class InfixFunction;
20
47 public:
49 virtual ~InfixToPostfix();
50
51 QString convert(const QString &infix);
52 QString tokenizeEquation(const QString &equation);
53
54 protected:
55
56 virtual bool isKnownSymbol(QString representation);
57 virtual InfixOperator *findOperator(QString representation);
58
59 QList<InfixOperator *> p_operators;
60
61 private:
62 void initialize();
63 void uninitialize();
64
65 QString formatFunctionCalls(QString equation);
66 QString cleanSpaces(QString equation);
67
68 void closeParenthesis(QString &postfix, std::stack<InfixOperator> &theStack);
69 void addOperator(QString &postfix, const InfixOperator &op, std::stack<InfixOperator> &theStack);
70 bool isFunction(QString representation);
71 void checkArgument(QString funcName, int argNum, QString argument);
72 };
73
82 public:
83 InfixOperator(int prec, QString inString, bool isFunc = false) {
84 m_precedence = prec;
85 m_inputString = inString;
86 m_outputString = inString;
87 m_isFunction = isFunc;
88 }
89
90 InfixOperator(int prec, QString inString, QString outString,
91 bool isFunc = false) {
92 m_precedence = prec;
93 m_inputString = inString;
94 m_outputString = outString;
95 m_isFunction = isFunc;
96 }
97
98 const QString &inputString() const {
99 return m_inputString;
100 }
101
102 const QString &outputString() const {
103 return m_outputString;
104 }
105
106 int precedence() const {
107 return m_precedence;
108 }
109
110 bool isFunction() const {
111 return m_isFunction;
112 }
113
114
115 private:
116 int m_precedence;
117 QString m_inputString;
118 QString m_outputString;
119 bool m_isFunction;
120 };
121
122
131 public:
132 InfixFunction(QString inString, int argCount) :
133 InfixOperator(-1, inString, true) {
134 m_numArguments = argCount;
135 }
136
137 InfixFunction(QString inString, QString outString, int argCount) :
138 InfixOperator(-1, inString, outString, true) {
139 m_numArguments = argCount;
140 }
141
142 int argumentCount() const {
143 return m_numArguments;
144 }
145
146 private:
147 int m_numArguments;
148 };
149};
150
151#endif
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
Definition InfixToPostfix.h:130
int argumentCount() const
Definition InfixToPostfix.h:142
InfixFunction(QString inString, int argCount)
Definition InfixToPostfix.h:132
InfixFunction(QString inString, QString outString, int argCount)
Definition InfixToPostfix.h:137
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
Definition InfixToPostfix.h:81
InfixOperator(int prec, QString inString, bool isFunc=false)
Definition InfixToPostfix.h:83
const QString & outputString() const
Definition InfixToPostfix.h:102
const QString & inputString() const
Definition InfixToPostfix.h:98
InfixOperator(int prec, QString inString, QString outString, bool isFunc=false)
Definition InfixToPostfix.h:90
bool isFunction() const
Definition InfixToPostfix.h:110
int precedence() const
Definition InfixToPostfix.h:106
Converter for math equations.
Definition InfixToPostfix.h:46
virtual InfixOperator * findOperator(QString representation)
This method will return a pointer to the operator represented by 'representation.
Definition InfixToPostfix.cpp:347
QString convert(const QString &infix)
This method converts infix to postfix.
Definition InfixToPostfix.cpp:139
virtual bool isKnownSymbol(QString representation)
This method will return true if it believes the argument represents a valid function or operator.
Definition InfixToPostfix.cpp:253
virtual ~InfixToPostfix()
Definition InfixToPostfix.cpp:23
InfixToPostfix()
Constructor.
Definition InfixToPostfix.cpp:19
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:369
QList< InfixOperator * > p_operators
Definition InfixToPostfix.h:59
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16