Isis 3 Programmer Reference
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 
135  p_operators.push_back(new InfixOperator(1, "|"));
136  p_operators.push_back(new InfixOperator(1, "or"));
137 
138  p_operators.push_back(new InfixOperator(1, "||"));
139  return;
140  }
141 
142 
153  bool InlineInfixToPostfix::exists(const QString &token) {
154  return (m_variables.contains(token, Qt::CaseInsensitive));
155  }
156 
157 
166  bool InlineInfixToPostfix::isScalar(const QString &token) {
167 
168  // NOTE: The following checks are commented out due to redundancy
169  // This is a private method only called from isKnownSymbol()
170  // and all of these conditions have already been checked.
171  // if (token.isEmpty()) return (false);
172  // if (InfixToPostfix::isKnownSymbol(token)) return (false);
173 
174  try {
175  Isis::toDouble(token);
176  return (true);
177  }
178  catch (IException &) {
179  return (false);
180  }
181  }
182 
183 
195  bool InlineInfixToPostfix::isVariable(const QString &token) {
196 
197  // NOTE: The following checks are commented out due to redundancy
198  // This is a private method only called from isKnownSymbol()
199  // and findOperator().
200  // All of these conditions have already been checked for
201  // isKnownSymbol().
202  // if (isScalar(token)) return (false);
203  // if (InfixToPostfix::isKnownSymbol(token)) return (false);
204 
205  if (token.isEmpty()) return (false);
206 
207  m_variables.push_back(token);
208  p_operators.push_back(new InfixFunction(token, 0));
209  return (true);
210  }
211 
212 } // Namespace Isis
213 
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:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
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:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
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...