Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

PredicateTree.h

00001                               /* PredicateTree.h */
00002 
00003 #ifndef  PREDICATE_TREE_HH  
00004 #define  PREDICATE_TREE_HH  
00005 
00006 #include <string>
00007 #include <vector>
00008 #include <set>
00009 #include <iostream>
00010 #include "QueryTranslationException.h"
00011 #include "TableRowTranslator.h"
00012 
00013 
00014 namespace LcgInfo{
00015 /************************************  CLASS PredicateTree  ***********************************/
00016 
00051 class PredicateTree{
00052 
00053    //No copy constructor
00054    PredicateTree(PredicateTree & other);
00055 
00056 public:
00062    enum NodeType{
00063       BOOLEAN,
00064       COMPARISON,
00065       LEAF
00066    };
00067 
00072    PredicateTree();   
00073 
00077    virtual ~PredicateTree();
00078 
00089    virtual PredicateTree* create()=0;
00090 
00100    virtual PredicateTree * clone()=0;
00101 
00109    bool const PredicateTree::operator==(PredicateTree const & other);
00110 
00116    void clear();
00117 
00124    bool empty();
00125 
00131    NodeType type() const {return mType;}
00137    std::string value() const {return mValue;}
00138 
00155    void translate(TableRowTranslator * pTRowT, std::vector<std::string> * pOrgTables,
00156                   std::set<std::string> * pNewTables);
00157 
00163    void print();
00164 
00175    virtual void insertPredicate(std::string const & pPred)=0;
00176 
00188     virtual std::string evaluate(std::vector<std::string> & pQueries)=0;
00189 
00195    int depth() const {return mDepth;}
00202    PredicateTree* left() const {return mLeft;}
00208    PredicateTree* right() const {return mRight;}
00214    void setType(NodeType const & pType) {mType=pType;}
00220    void setValue(std::string const & pValue) {mValue=pValue;}
00226    void setDepth(int pDepth) {mDepth=pDepth;}
00233    void setLeft(PredicateTree* pLeft=NULL);
00240    void setRight(PredicateTree* pRight=NULL);
00241 
00249    void incrementDepth(int pAmount);
00250 
00259    bool relatesTables();
00264    bool isIdentity() const;   
00265    
00279    bool isRedundant(PredicateTree const & pPred);
00280 
00293    void addAndPredicate(std::string const& pPred, std::set<std::string> & pNewTables);
00294 
00298    bool isBooleanOp(std::string pStr);
00299    
00300 protected:
00309    virtual std::string getCHARS_TO_TOKENIZE_PREDICATES();
00310 
00311 
00312 private:
00316    NodeType mType;
00323    std::string mValue;
00328    int mDepth;
00333    PredicateTree* mLeft;
00337    PredicateTree* mRight;
00338 
00339 /*
00340  * The chars that have to be escaped in the literals, so that they are not
00341  * interpreted as special characters (comparison operators...).  
00342  */
00343 static std::string const CHARS_TO_ESCAPE_IN_LITERALS;
00344 
00345 };
00346 
00347 }
00348 #endif

Generated on Tue Oct 5 14:42:45 2004 for LCG Information System Interface by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002