Expression.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
45 #ifndef EXPRESSION__HPP
46 #define EXPRESSION__HPP
47 
48 #include <iostream>
49 #include <string>
50 #include <list>
51 #include <map>
52 
53 #include "RinexObsHeader.hpp"
54 #include "RinexObsData.hpp"
55 #include "ObsEpochMap.hpp"
56 #include "Exception.hpp"
57 
58 namespace gnsstk
59 {
61 
62 
86  NEW_EXCEPTION_CLASS(ExpressionException, Exception);
87 
88  class Expression
89  {
90  public:
91 
95  Expression(void);
96 
101  Expression(const std::string& str);
102 
108  Expression(const Expression& rhs);
109 
111  ~Expression(void);
112 
114  Expression& operator=(const Expression& rhs);
115 
116 
126  bool set(const std::string name, double value);
127 
138  bool set(const char* name, double value)
139  { return set (std::string(name),value); }
140 
149  bool setGPSConstants(void);
150 
158  bool setRinexObs(const RinexObsData::RinexObsTypeMap& rotm);
159 
160  bool setSvObsEpoch(const SvObsEpoch& soe);
161 
166  bool canEvaluate(void);
167 
174  double evaluate(void)
175  { return root->getValue(); }
176 
180  void print(std::ostream& ostr) const {root->print(ostr);}
181 
182  private:
183  // Represents a node of any type in an expression tree.
184  class ExpNode {
185  public:
186 
187  virtual ~ExpNode() {}
188 
192  virtual double getValue() = 0;
193 
194 
195  // Write out this node to a stream
196  virtual std::ostream& print(std::ostream& ostr) =0;
197 
198  }; // end class ExpNode
199 
200 
201  // Represents a node that holds a number.
202  class ConstNode : public ExpNode {
203  public:
204  // Constructor. Create a node to hold val.
205  ConstNode( double theNum ): number(theNum) {}
206 
210  double getValue()
211  { return number; }
212 
213  std::ostream& print(std::ostream& ostr) {
214  ostr << number;
215  return ostr;
216  }
217 
218  double number; // The number in the node.
219  }; // end class ConstNode
220 
221  // Represents a node that holds a variable
222  class VarNode : public ExpNode {
223  public:
224  // Constructor.
225 
226  VarNode(std::string theName ): name(theName), hasValue(false)
227  {}
228 
232  double getValue();
233 
234  std::ostream& print(std::ostream& ostr) {
235  ostr << name;
236  return ostr;
237  }
238 
239  std::string name; // The name of the varaible
240  bool hasValue;
241 
242  void setValue(double newValue);
243 
244  private:
245  double value;
246 
247 
248  }; // end class VarNode
249 
250  // Represents a node that holds an operator.
251  class BinOpNode : public ExpNode {
252  public:
253 
254  // Constructor. Create a node to hold the given data.
255  BinOpNode( const std::string& theOp, ExpNode *theLeft, ExpNode *theRight ):
256  op(theOp), left(theLeft), right(theRight){}
257 
261  double getValue();
262 
263  std::ostream& print(std::ostream& ostr);
264 
265  std::string op; // The operator.
266  ExpNode *left; // The left operand.
267  ExpNode *right; // The right operand.
268 
269  }; // end class BinOpNode
270 
271  // Represents a node that holds a function of a signle variable
272  class FuncOpNode : public ExpNode {
273  public:
274 
275  // Constructor. Create a node to hold the given data.
276  FuncOpNode( const std::string& theOp, ExpNode *theRight ):
277  op(theOp), right(theRight){}
278 
282  double getValue();
283 
284  std::ostream& print(std::ostream& ostr);
285 
286  std::string op; // The operator.
287  ExpNode *right; // The right operand.
288 
289  }; // end class FuncOpNode
290 
291  // This class is used internally, during construction of an Expression,
292  // to generate ExpNodes.
293  class Token
294  {
295  public:
296 
297  Token(std::string value, int relPriority,
298  bool isOperator);
299 
300  std::string getValue(void) {return value;}
301 
302  int getPriority(void) {return priority;}
303 
304  void setUsed(void) {used=true;}
305  bool getUsed(void) {return used;}
306 
307  ExpNode * getNode(void) {return expNode;}
308  void setNode(ExpNode *newNode) {expNode = newNode; }
309 
311  bool getResolved(void) {return resolved;}
312 
313  bool getOperator(void) {return isOperator;}
315 
316  std::string getArgumentPattern(void) {return argumentPattern;}
318 
319  void print(std::ostream& ostr);
320 
321  private:
322 
323  std::string value;
325  bool resolved;
326 
327  int priority;
329  bool used; // has the node of this token been used (linked to?)
330 
331  std::string argumentPattern;
332  };
333 
334  void setExpression(const std::string& newExpression);
335  void dumpLists(void);
336 
337  void defineOperators(void);
338  void tokenize(const std::string& str);
339  void buildExpressionTree(void);
340 
341  int countResolvedTokens(void);
342 
343  static std::map<std::string,int> operatorMap;
344  static std::map<std::string,std::string> argumentPatternMap;
345  static bool operatorsDefined;
346 
347  std::list<Token> tList;
348  std::list<ExpNode *> eList;
350  }; // End class expression
351 
352 
353 } // End namespace gnsstk
354 
355 #endif // EXPRESSION_HPP
gnsstk::Expression::VarNode
Definition: Expression.hpp:222
gnsstk::Expression::Token::getPriority
int getPriority(void)
Definition: Expression.hpp:302
gnsstk::Expression::ExpNode::~ExpNode
virtual ~ExpNode()
Definition: Expression.hpp:187
gnsstk::Expression::Token::getResolved
bool getResolved(void)
Definition: Expression.hpp:311
gnsstk::Expression::VarNode::hasValue
bool hasValue
Definition: Expression.hpp:240
gnsstk::Expression::tokenize
void tokenize(const std::string &str)
Definition: Expression.cpp:266
gnsstk::Expression::FuncOpNode::op
std::string op
Definition: Expression.hpp:286
gnsstk::Expression::BinOpNode
Definition: Expression.hpp:251
gnsstk::Expression::Token::getValue
std::string getValue(void)
Definition: Expression.hpp:300
gnsstk::Expression::FuncOpNode::FuncOpNode
FuncOpNode(const std::string &theOp, ExpNode *theRight)
Definition: Expression.hpp:276
gnsstk::Expression::set
bool set(const std::string name, double value)
Definition: Expression.cpp:533
gnsstk::Expression::ConstNode::ConstNode
ConstNode(double theNum)
Definition: Expression.hpp:205
gnsstk::Expression::~Expression
~Expression(void)
Destructor.
Definition: Expression.cpp:259
gnsstk::Expression::setExpression
void setExpression(const std::string &newExpression)
Definition: Expression.cpp:168
gnsstk::Expression::root
ExpNode * root
Definition: Expression.hpp:349
gnsstk::Expression::FuncOpNode::getValue
double getValue()
Definition: Expression.cpp:78
gnsstk::Expression::Token::argumentPattern
std::string argumentPattern
Definition: Expression.hpp:331
gnsstk::Expression::ConstNode::number
double number
Definition: Expression.hpp:218
gnsstk::Expression::VarNode::value
double value
Definition: Expression.hpp:245
ObsEpochMap.hpp
gnsstk::Expression::evaluate
double evaluate(void)
Definition: Expression.hpp:174
gnsstk::Expression::countResolvedTokens
int countResolvedTokens(void)
Definition: Expression.cpp:395
gnsstk::Expression::Token::getUsed
bool getUsed(void)
Definition: Expression.hpp:305
gnsstk::Expression::BinOpNode::getValue
double getValue()
Definition: Expression.cpp:60
gnsstk::Expression::setRinexObs
bool setRinexObs(const RinexObsData::RinexObsTypeMap &rotm)
Definition: Expression.cpp:599
gnsstk::Expression::Token::Token
Token(std::string value, int relPriority, bool isOperator)
Definition: Expression.cpp:132
gnsstk::Expression::FuncOpNode::right
ExpNode * right
Definition: Expression.hpp:287
gnsstk::Expression::ExpNode::print
virtual std::ostream & print(std::ostream &ostr)=0
gnsstk::Expression::BinOpNode::op
std::string op
Definition: Expression.hpp:265
gnsstk::Expression::setSvObsEpoch
bool setSvObsEpoch(const SvObsEpoch &soe)
Definition: Expression.cpp:613
gnsstk::Expression::Token::value
std::string value
Definition: Expression.hpp:323
gnsstk::Expression::Expression
Expression(void)
Definition: Expression.cpp:175
gnsstk::Expression::Token::setArgumentPattern
void setArgumentPattern(std::string value)
Definition: Expression.hpp:317
gnsstk::Expression::Token
Definition: Expression.hpp:293
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Expression::buildExpressionTree
void buildExpressionTree(void)
Definition: Expression.cpp:411
gnsstk::Expression::Token::setUsed
void setUsed(void)
Definition: Expression.hpp:304
gnsstk::Expression::tList
std::list< Token > tList
Definition: Expression.hpp:347
gnsstk::Expression::Token::used
bool used
Definition: Expression.hpp:329
gnsstk::Expression::FuncOpNode
Definition: Expression.hpp:272
gnsstk::Expression::ConstNode::print
std::ostream & print(std::ostream &ostr)
Definition: Expression.hpp:213
gnsstk::Expression::BinOpNode::right
ExpNode * right
Definition: Expression.hpp:267
gnsstk::NEW_EXCEPTION_CLASS
NEW_EXCEPTION_CLASS(FileSpecException, gnsstk::Exception)
gnsstk::Expression::Token::print
void print(std::ostream &ostr)
Definition: Expression.cpp:138
gnsstk::Expression::VarNode::getValue
double getValue()
Definition: Expression.cpp:122
gnsstk::Expression::argumentPatternMap
static std::map< std::string, std::string > argumentPatternMap
Definition: Expression.hpp:344
gnsstk::Expression::ExpNode
Definition: Expression.hpp:184
gnsstk::Expression::Token::setNode
void setNode(ExpNode *newNode)
Definition: Expression.hpp:308
gnsstk::Expression::ConstNode::getValue
double getValue()
Definition: Expression.hpp:210
gnsstk::Expression::BinOpNode::BinOpNode
BinOpNode(const std::string &theOp, ExpNode *theLeft, ExpNode *theRight)
Definition: Expression.hpp:255
gnsstk::Expression::defineOperators
void defineOperators(void)
Definition: Expression.cpp:217
gnsstk::Expression::operatorMap
static std::map< std::string, int > operatorMap
Definition: Expression.hpp:343
gnsstk::Expression::Token::setOperator
void setOperator(bool value)
Definition: Expression.hpp:314
gnsstk::Expression::eList
std::list< ExpNode * > eList
Definition: Expression.hpp:348
gnsstk::Expression::VarNode::print
std::ostream & print(std::ostream &ostr)
Definition: Expression.hpp:234
gnsstk::Expression::Token::getArgumentPattern
std::string getArgumentPattern(void)
Definition: Expression.hpp:316
gnsstk::Expression::VarNode::setValue
void setValue(double newValue)
Definition: Expression.cpp:116
gnsstk::Expression::dumpLists
void dumpLists(void)
Definition: Expression.cpp:198
gnsstk::Expression::VarNode::name
std::string name
Definition: Expression.hpp:239
RinexObsData.hpp
gnsstk::Expression::canEvaluate
bool canEvaluate(void)
Definition: Expression.cpp:560
gnsstk::Expression::Token::isOperator
bool isOperator
Definition: Expression.hpp:324
gnsstk::Expression::Token::expNode
ExpNode * expNode
Definition: Expression.hpp:328
RinexObsHeader.hpp
gnsstk::Expression::operator=
Expression & operator=(const Expression &rhs)
Assignment operator.
Definition: Expression.cpp:190
gnsstk::RinexObsData::RinexObsTypeMap
std::map< RinexObsType, gnsstk::RinexDatum > RinexObsTypeMap
map from RinexObsType to RinexDatum.
Definition: RinexObsData.hpp:73
gnsstk::Expression::Token::setResolved
void setResolved(bool value)
Definition: Expression.hpp:310
gnsstk::Expression::BinOpNode::left
ExpNode * left
Definition: Expression.hpp:266
gnsstk::Expression::Token::getNode
ExpNode * getNode(void)
Definition: Expression.hpp:307
Exception.hpp
gnsstk::SvObsEpoch
All the observations collected from a single SV at a single epoch.
Definition: SvObsEpoch.hpp:55
gnsstk::Expression::ExpNode::getValue
virtual double getValue()=0
example5.soe
soe
Definition: example5.py:25
gnsstk::Expression::operatorsDefined
static bool operatorsDefined
Definition: Expression.hpp:345
gnsstk::Expression::ConstNode
Definition: Expression.hpp:202
gnsstk::Expression::set
bool set(const char *name, double value)
Definition: Expression.hpp:138
gnsstk::Expression::Token::getOperator
bool getOperator(void)
Definition: Expression.hpp:313
gnsstk::Expression::Token::priority
int priority
Definition: Expression.hpp:327
gnsstk::Expression::print
void print(std::ostream &ostr) const
Definition: Expression.hpp:180
gnsstk::Expression::VarNode::VarNode
VarNode(std::string theName)
Definition: Expression.hpp:226
gnsstk::Expression::BinOpNode::print
std::ostream & print(std::ostream &ostr)
Definition: Expression.cpp:106
gnsstk::Expression::setGPSConstants
bool setGPSConstants(void)
Definition: Expression.cpp:581
gnsstk::Expression::Token::resolved
bool resolved
Definition: Expression.hpp:325
gnsstk::Expression::FuncOpNode::print
std::ostream & print(std::ostream &ostr)
Definition: Expression.cpp:99
gnsstk::Expression
Definition: Expression.hpp:88


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39