Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis Developer Reference
InfixToPostfix.h
Go to the documentation of this file.
1
5
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#include <QRegularExpression>
17
18namespace Isis {
19 class InfixOperator;
20 class InfixFunction;
21
48 public:
50 virtual ~InfixToPostfix();
51
52 QString convert(const QString &infix);
53 QString tokenizeEquation(const QString &equation);
54
55 protected:
56
57 virtual bool isKnownSymbol(QString representation);
58 virtual InfixOperator *findOperator(QString representation);
59
61
62 private:
63 void initialize();
64 void uninitialize();
65
66 QString formatFunctionCalls(QString equation);
67 QString cleanSpaces(QString equation);
68
69 void closeParenthesis(QString &postfix, std::stack<InfixOperator> &theStack);
70 void addOperator(QString &postfix, const InfixOperator &op, std::stack<InfixOperator> &theStack);
71 bool isFunction(QString representation);
72 void checkArgument(QString funcName, int argNum, QString argument);
73 };
74
83 public:
84 InfixOperator(int prec, QString inString, bool isFunc = false) {
85 m_precedence = prec;
86 m_inputString = inString;
87 m_outputString = inString;
88 m_isFunction = isFunc;
89 }
90
91 InfixOperator(int prec, QString inString, QString outString,
92 bool isFunc = false) {
93 m_precedence = prec;
94 m_inputString = inString;
95 m_outputString = outString;
96 m_isFunction = isFunc;
97 }
98
99 const QString &inputString() const {
100 return m_inputString;
101 }
102
103 const QString &outputString() const {
104 return m_outputString;
105 }
106
107 int precedence() const {
108 return m_precedence;
109 }
110
111 bool isFunction() const {
112 return m_isFunction;
113 }
114
115
116 private:
117 int m_precedence;
118 QString m_inputString;
119 QString m_outputString;
120 bool m_isFunction;
121 };
122
123
132 public:
133 InfixFunction(QString inString, int argCount) :
134 InfixOperator(-1, inString, true) {
135 m_numArguments = argCount;
136 }
137
138 InfixFunction(QString inString, QString outString, int argCount) :
139 InfixOperator(-1, inString, outString, true) {
140 m_numArguments = argCount;
141 }
142
143 int argumentCount() const {
144 return m_numArguments;
145 }
146
147 private:
148 int m_numArguments;
149 };
150};
151
152#endif
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
Definition InfixToPostfix.h:131
int argumentCount() const
Definition InfixToPostfix.h:143
InfixFunction(QString inString, int argCount)
Definition InfixToPostfix.h:133
InfixFunction(QString inString, QString outString, int argCount)
Definition InfixToPostfix.h:138
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
Definition InfixToPostfix.h:82
InfixOperator(int prec, QString inString, bool isFunc=false)
Definition InfixToPostfix.h:84
const QString & outputString() const
Definition InfixToPostfix.h:103
const QString & inputString() const
Definition InfixToPostfix.h:99
InfixOperator(int prec, QString inString, QString outString, bool isFunc=false)
Definition InfixToPostfix.h:91
bool isFunction() const
Definition InfixToPostfix.h:111
int precedence() const
Definition InfixToPostfix.h:107
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:60
This is free and unencumbered software released into the public domain.
Definition BoxcarCachingAlgorithm.h:13
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16