Isis 3.0 Programmer Reference
Back | Home
InlineInfixToPostfix.cpp
Go to the documentation of this file.
1 
25 #include "InlineInfixToPostfix.h"
26 
27 // Qt library
28 #include <QString>
29 #include <QVector>
30 
31 // other ISIS
32 #include "IException.h"
33 #include "IString.h"
34 
35 namespace Isis {
42  initialize();
43  }
44 
45 
50  }
51 
52 
61  bool InlineInfixToPostfix::isKnownSymbol(QString representation) {
62 
63  if ( representation.isEmpty() ) return (false);
64 
65  // not an empty string
66  if ( InfixToPostfix::isKnownSymbol(representation) ) {
67  return (true);
68  }
69 
70  // not known symbol from parent class
71  if ( isScalar(representation) ) {
72  return (false);
73  }
74 
75  // not scalar, the only thing left is a variable...
76  return isVariable(representation);
77  }
78 
79 
99  try {
100  return InfixToPostfix::findOperator(token);
101  }
102  catch(IException &e) {
103  if ( isVariable(token) ) {
104  // If the token is not a scalar, the isVariable() method will assume it's a variable.
105  // Then the token is added it to the variables list and an InfixFunction from this token
106  // is added to the operators.
107  // Now that is has been added to the operators list, we can call findOperator() again and
108  // should find this representation in the list.
109  return (findOperator(token));
110  }
111  else {
112  QString msg = "The token '" + token
113  + "' is not recognized as an operator, function or variable.";
114  throw IException(e, IException::User, msg, _FILEINFO_);
115  }
116  }
117 
118  }
119 
120 
126  p_operators.push_back(new InfixOperator(1, "%"));
127  p_operators.push_back(new InfixFunction("mod", 2));
128  p_operators.push_back(new InfixFunction("fmod", 2));
129 
130  p_operators.push_back(new InfixOperator(1, "&"));
131  p_operators.push_back(new InfixOperator(1, "and"));
132 
133  p_operators.push_back(new InfixOperator(1, "|"));
134  p_operators.push_back(new InfixOperator(1, "or"));
135  return;
136  }
137 
138 
149  bool InlineInfixToPostfix::exists(const QString &token) {
150  return (m_variables.contains(token, Qt::CaseInsensitive));
151  }
152 
153 
162  bool InlineInfixToPostfix::isScalar(const QString &token) {
163 
164  // NOTE: The following checks are commented out due to redundancy
165  // This is a private method only called from isKnownSymbol()
166  // and all of these conditions have already been checked.
167  // if (token.isEmpty()) return (false);
168  // if (InfixToPostfix::isKnownSymbol(token)) return (false);
169 
170  try {
171  Isis::toDouble(token);
172  return (true);
173  }
174  catch (IException &) {
175  return (false);
176  }
177  }
178 
179 
191  bool InlineInfixToPostfix::isVariable(const QString &token) {
192 
193  // NOTE: The following checks are commented out due to redundancy
194  // This is a private method only called from isKnownSymbol()
195  // and findOperator().
196  // All of these conditions have already been checked for
197  // isKnownSymbol().
198  // if (isScalar(token)) return (false);
199  // if (InfixToPostfix::isKnownSymbol(token)) return (false);
200 
201  if (token.isEmpty()) return (false);
202 
203  m_variables.push_back(token);
204  p_operators.push_back(new InfixFunction(token, 0));
205  return (true);
206  }
207 
208 } // Namespace Isis
209 
virtual InfixOperator * findOperator(QString representation)
This method will return a pointer to the operator represented by &#39;representation. ...
QStringList m_variables
The list of variables (represented as strings).
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
virtual InfixOperator * findOperator(QString element)
This method will first search the recognized list of operators and functions for the given token...
bool isVariable(const QString &str)
Determines whether the given token is a variable and, if so, appends it to the list of variables...
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
virtual ~InlineInfixToPostfix()
Destroys the InlineInfixToPostfix object.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:134
virtual bool isKnownSymbol(QString representation)
This method attempts to verify that the given argument is recognized as a valid function, operator, scalar, or variable.
bool isScalar(const QString &scalar)
Determines whether the given token represents a scalar value (i.e.
InlineInfixToPostfix()
Constructs an InlineInfixToPostfix object.
Converter for math equations.
Isis exception class.
Definition: IException.h:99
bool exists(const QString &str)
Determines whether the given string exists as a recognized variable.
void initialize()
Adds several infix operators and functions to the operator list that are not already recognized by th...
virtual bool isKnownSymbol(QString representation)
This method will return true if it believes the argument represents a valid function or operator...

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:36