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

SQLtoSQLPredicateTree.cpp

00001                               /* SQLtoSQLPredicateTree.cpp */
00002 
00003 /*
00004  *  Implementation of SQLtoSQLPredicateTree.h
00005  */
00006 #include "SQLtoSQLPredicateTree.h"
00007 
00008 using namespace LcgInfo;
00009 using namespace std;
00010    
00011 
00012 /**************************  METHODS FOR CLASS SQLtoSQLPredicateTree ***************************/
00013 
00014 /***** Public functions *****/
00015 
00016 SQLtoSQLPredicateTree::SQLtoSQLPredicateTree()
00017 :SQLPredicateTree(){
00018 }
00019 
00020 SQLtoSQLPredicateTree::~SQLtoSQLPredicateTree(){
00021 }
00022 
00023 
00024 SQLtoSQLPredicateTree* SQLtoSQLPredicateTree::create(){
00025    return new SQLtoSQLPredicateTree();
00026 }
00027 
00028 SQLtoSQLPredicateTree * SQLtoSQLPredicateTree::clone(){
00029    SQLtoSQLPredicateTree * aux=create();
00030 
00031    //copy this node values
00032    aux->setValue(value());
00033    aux->setType(type());
00034    aux->setDepth(depth());
00035 
00036   //clone children
00037   if(left()!=NULL)
00038       aux->setLeft(left()->clone());
00039    else
00040       aux->setLeft(NULL);
00041    if(right()!=NULL)
00042       aux->setRight(right()->clone());
00043    else
00044       aux->setRight(NULL);    
00045 
00046    return aux;
00047 }
00048 
00049 string SQLtoSQLPredicateTree::evaluate(vector<string> & pQueries){
00050    vector<string> result;
00051    string aux;   
00052    switch (this->type()){
00053       case COMPARISON:
00054          aux=left()->evaluate(pQueries) + ' ' + this->value() + ' ' + right()->evaluate(pQueries);
00055          break;
00056 
00057       case BOOLEAN: 
00058          if (nocaseCompare(this->value(),"NOT"))
00059             aux="NOT " + right()->evaluate(pQueries);
00060          else{
00061            //first check for NULL children (usually coming from identities)
00062            if((right()==0)&&(left()==0)) return "";
00063            if(right()==0) aux = left()->evaluate(pQueries);
00064            else if(left()==0) aux = right()->evaluate(pQueries);
00065            else{
00066               aux=left()->evaluate(pQueries) + ' ';
00067               aux += this->value() + ' ' + right()->evaluate(pQueries);
00068            }
00069          }
00070          break;
00071 
00072       case LEAF:
00073          return this->value();
00074    }
00075 
00076    if(aux.empty()){
00077       string msg="Parsing error. The node could not be evaluated.";
00078       msg += "\nThis node's value: " + value() + "\nThis node's depth: " + int2str(depth());
00079       throw QueryTranslationException(msg,__FILE__,__LINE__);
00080    }
00081 
00082    if(depth()>0) aux='('+aux+')';
00083    return aux;
00084 };// end of evaluate(pQueries)

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