relPrintExpr.h

Go to the documentation of this file.
00001 /*
00002  * CrocoPat is a tool for relational programming.
00003  * This file is part of CrocoPat. 
00004  *
00005  * Copyright (C) 2002-2008  Dirk Beyer
00006  *
00007  * CrocoPat is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * CrocoPat is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with CrocoPat; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * Please find the GNU Lesser General Public License in file
00022  * License_LGPL.txt or at http://www.gnu.org/licenses/lgpl.txt
00023  *
00024  * Author:
00025  * Dirk Beyer (firstname.lastname@sfu.ca)
00026  * Simon Fraser University
00027  *
00028  * With contributions of: Andreas Noack, Michael Vogel
00029  */
00030 
00031 #include "relExpression.h"
00032 
00034 class relPrintExpr : public relObject
00035 {
00036 public:
00037   virtual void
00038   interpret(bddSymTab* pSymTab, ostream* pOut) = 0;
00039 };
00040 
00042 class relPrintExprSeq : public relPrintExpr
00043 {
00044 private:
00045   relPrintExpr* mPrintExpr1;
00046   relPrintExpr* mPrintExpr2;
00047 
00048 public:
00049   relPrintExprSeq(relPrintExpr* pPrintExpr1, relPrintExpr* pPrintExpr2)
00050     : mPrintExpr1(pPrintExpr1),
00051       mPrintExpr2(pPrintExpr2)
00052   {}
00053 
00054   ~relPrintExprSeq()
00055   {
00056     delete mPrintExpr1;
00057     delete mPrintExpr2;
00058   }
00059 
00060   virtual void
00061   interpret(bddSymTab* pSymTab, ostream* pOut)
00062   {
00063     mPrintExpr1->interpret(pSymTab, pOut);
00064     mPrintExpr2->interpret(pSymTab, pOut);
00065   }
00066 };
00067 
00069 class relPrintExprEndLine : public relPrintExpr
00070 {
00071 private:
00072 
00073 public:
00074   relPrintExprEndLine()
00075   {}
00076 
00077   ~relPrintExprEndLine()
00078   {}
00079 
00080   virtual void
00081   interpret(bddSymTab* pSymTab, ostream* pOut)
00082   {
00083     *pOut << endl;
00084   }
00085 };
00086 
00088 class relPrintExprString : public relPrintExpr
00089 {
00090 private:
00091   relStrExpr* mExpr;
00092 
00093 public:
00094   relPrintExprString(relStrExpr* pExpr)
00095         : mExpr(pExpr)
00096   {}
00097 
00098   ~relPrintExprString()
00099   {
00100     delete mExpr;
00101   }
00102 
00103   virtual void
00104   interpret(bddSymTab* pSymTab, ostream* pOut)
00105   {
00106     *pOut << mExpr->interpret(pSymTab).getValue();
00107     pSymTab->removeUserAttributes(gAttributePrefix);
00108   }
00109 };
00110 
00112 class relPrintExprInt : public relPrintExpr
00113 {
00114 private:
00115   relNumExpr* mExpr;
00116 
00117 public:
00118   relPrintExprInt(relNumExpr* pExpr)
00119         : mExpr(pExpr)
00120   {}
00121 
00122   ~relPrintExprInt()
00123   {
00124     delete mExpr;
00125   }
00126 
00127   virtual void
00128   interpret(bddSymTab* pSymTab, ostream* pOut)
00129   {
00130     *pOut << mExpr->interpret(pSymTab).getValue();
00131     pSymTab->removeUserAttributes(gAttributePrefix);
00132   }
00133 };
00134 
00136 class relPrintExprValues : public relPrintExpr
00137 {
00138 private:
00140   relStrExpr*     mPrefix;
00141   relExpression*  mExpr;
00142 
00143 public:
00144   relPrintExprValues(relStrExpr* pPrefix, 
00145                      relExpression* pExpr)
00146     : mPrefix(pPrefix),
00147       mExpr(pExpr)
00148   {}
00149 
00150   ~relPrintExprValues()
00151   {
00152     delete mPrefix;
00153     delete mExpr;
00154   }
00155 
00156   virtual void
00157   interpret(bddSymTab* pSymTab, ostream* pOut)
00158   {
00159     string lPrefix = mPrefix->interpret(pSymTab).getValue();
00160     if (lPrefix.length() != 0) {
00161       lPrefix += '\t';
00162     }
00163     const set<string> lFree = mExpr->collectFreeAttrs();
00164     bddRelation lRel = mExpr->interpret(pSymTab);
00165     map<unsigned,string> lVarOrd = pSymTab->computeVariableOrder(lFree);
00166     vector<string> lAttributeList;
00167     for(map<unsigned, string>::const_iterator lIt = lVarOrd.begin();
00168         lIt != lVarOrd.end();
00169         ++lIt)
00170     {
00171       lAttributeList.push_back(lIt->second);
00172     }
00173     lRel.printRelation(*pOut, lPrefix, lAttributeList );
00174     pSymTab->removeUserAttributes(gAttributePrefix);
00175   }
00176 };
00177 
00179 class relPrintExprRelInfo : public relPrintExpr
00180 {
00181 private:
00182   relExpression* mExpr;
00183 
00184 public:
00185   relPrintExprRelInfo(relExpression* pExpr)
00186     : mExpr(pExpr)
00187   {}
00188 
00189   ~relPrintExprRelInfo()
00190   {
00191     delete mExpr;
00192   }
00193 
00194   virtual void
00195   interpret(bddSymTab* pSymTab, ostream* pOut)
00196   {
00197     bddRelation lRel = mExpr->interpret(pSymTab);
00198 
00199     *pOut << "------------------------------------------------------" << endl;
00200         *pOut << "Information about the representing data structures." << endl;
00201         *pOut << endl;
00202 
00203     const set<string> lFree = mExpr->collectFreeAttrs();
00204     *pOut << "Number of tuples in the relation: " 
00205           << lRel.getTupleNr(lFree) 
00206           << endl;
00207 
00208     *pOut << "Number of values (universe): " 
00209           << pSymTab->getUniverseSize() << endl;
00210 
00211     // BDD info.
00212     lRel.printBddInfo(*pOut);
00213 
00214     *pOut << "Attribute order: ";
00215     const map<unsigned,string> lVarOrd = pSymTab->computeVariableOrder(lFree);
00216     for(map<unsigned, string>::const_iterator lIt = lVarOrd.begin();
00217         lIt != lVarOrd.end();
00218         ++lIt)
00219     {
00220       *pOut << lIt->second << " ";
00221     }
00222     *pOut << endl;
00223 
00224     *pOut << "------------------------------------------------------" << endl;
00225 
00226     pSymTab->removeUserAttributes(gAttributePrefix);
00227   }
00228 };
00229 
00231 class relPrintExprNodesPerVarId : public relPrintExpr
00232 {
00233 private:
00234   relExpression* mExpr;
00235 
00236 public:
00237   relPrintExprNodesPerVarId(relExpression* pExpr)
00238     : mExpr(pExpr)
00239   {}
00240 
00241   ~relPrintExprNodesPerVarId()
00242   {
00243     delete mExpr;
00244   }
00245 
00246   virtual void
00247   interpret(bddSymTab* pSymTab, ostream* pOut)
00248   {
00249     const bddRelation lRel = mExpr->interpret(pSymTab);
00250     const set<string> lFree = mExpr->collectFreeAttrs();
00251     lRel.printNodesPerVarId(*pOut, lFree);
00252     pSymTab->removeUserAttributes(gAttributePrefix);
00253   }
00254 };
00255 
00257 class relPrintExprGraph : public relPrintExpr
00258 {
00259 private:
00260   relExpression* mExpr;
00261 
00262 public:
00263   relPrintExprGraph(relExpression* pExpr)
00264     : mExpr(pExpr)
00265   {}
00266 
00267   ~relPrintExprGraph()
00268   {
00269     delete mExpr;
00270   }
00271 
00272   virtual void
00273   interpret(bddSymTab* pSymTab, ostream* pOut)
00274   {
00275     const bddRelation lRel = mExpr->interpret(pSymTab);
00276     const set<string> lFree = mExpr->collectFreeAttrs();
00277     lRel.printGraph(*pOut, lFree);
00278     pSymTab->removeUserAttributes(gAttributePrefix);
00279   }
00280 };
00281 
00283 class relPrintExprBDT : public relPrintExpr
00284 {
00285 private:
00286   relExpression* mExpr;
00287 
00288 public:
00289   relPrintExprBDT(relExpression* pExpr)
00290     : mExpr(pExpr)
00291   {}
00292 
00293   ~relPrintExprBDT()
00294   {
00295     delete mExpr;
00296   }
00297 
00298   virtual void
00299   interpret(bddSymTab* pSymTab, ostream* pOut)
00300   {
00301     const bddRelation lRel = mExpr->interpret(pSymTab);
00302     lRel.printBDT(*pOut);
00303     pSymTab->removeUserAttributes(gAttributePrefix);
00304   }
00305 };
00306 
00307 

Generated on Fri Jun 6 22:21:09 2008 for CrocoPat by  doxygen 1.5.1