Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Dep.H

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // File: Dep.H
00020 
00021 #ifndef Dep_H
00022 #define Dep_H
00023 
00024 #include "ValExpr.H"
00025 #include <FV2.H>
00026 #include <FP.H>
00027 #include <SharedTable.H>
00028 
00029 typedef FV2::T ArcSeq;
00030 
00031 // The kind of a DepPath.
00032 enum PathKind {
00033   NormPK = 'N', BangPK = '!', TypePK = 'T', LLenPK = 'L', BLenPK = 'B',
00034   ExprPK = 'E', DummyPK = 'D' };
00035 
00037 class DepPath {
00038   // The representation of a path:
00039 public:
00040   class DepPathC {
00041   public:
00042     DepPathC(int size)
00043       : pKind(NormPK), pathFP("", 0), dpathVersion(0)
00044         { path = NEW_CONSTR(ArcSeq, (size)); };
00045     DepPathC(const Text& id, PathKind pk);
00046     DepPathC(ArcSeq *tpath, PathKind pk);
00047     DepPathC(const ArcSeq& tpath, PathKind pk, const FP::Tag& fp,
00048              int version)
00049       : pKind(pk), pathFP(fp), dpathVersion(version)
00050         { path = NEW_CONSTR(ArcSeq, (tpath)); };
00051     DepPathC(ArcSeq *tpath, PathKind pk, const FP::Tag& fp)
00052       : path(tpath), pKind(pk), pathFP(fp), dpathVersion(0) { /*SKIP*/ };
00053     // Constructors.
00054 
00055     PathKind pKind;
00056     // The kind of a DepPath.
00057 
00058     int dpathVersion;
00059     // Used to avoid duplicate copy of this path.
00060 
00061     ArcSeq *path;
00062     // A path is a sequence of arcs (text).
00063     
00064     FP::Tag pathFP;
00065     // For efficient equality test only.
00066   };
00067       
00068   DepPathC *content;
00069   // The content of this DepPath.
00070 
00071   DepPath() { content = NULL; };
00072   // Default.  We do not allocate anything.
00073 
00074   DepPath(int size) { content = NEW_CONSTR(DepPathC, (size)); };
00075   // Construct an empty new DepPath.
00076 
00077   DepPath(ArcSeq *tpath, PathKind pk, const FP::Tag& fp)
00078     { content = NEW_CONSTR(DepPathC, (tpath, pk, fp)); };
00079   // Construct a new DepPath using a text sequence.
00080 
00081   DepPath(const Text& id, PathKind pk = NormPK)
00082     { content = NEW_CONSTR(DepPathC, (id, pk)); };
00083   // Construct a new DepPath with singleton id.
00084 
00085   DepPath(ArcSeq *path, PathKind pk)
00086     { content = NEW_CONSTR(DepPathC, (path, pk)); };
00087   // Construct a new DepPath using a copy of the text sequence path.
00088 
00089   DepPath(DepPathC *tcontent, int version = 0)
00090     { content = NEW_CONSTR(DepPathC, 
00091                            (*tcontent->path,
00092                              tcontent->pKind,
00093                              tcontent->pathFP,
00094                              version)); };
00095   // Construct a new DepPath by deep copying.
00096 
00097   void DeepCopy(const DepPath& dp, int version = 0)
00098     { content = NEW_CONSTR(DepPathC, 
00099                            (*dp.content->path,
00100                              dp.content->pKind,
00101                              dp.content->pathFP,
00102                              version)); };
00103   // Make this to be a deep copy of dp.
00104 
00105   DepPath* DeepCopy(int version = 0)
00106     { return NEW_CONSTR(DepPath, (this->content, version)); };
00107   // Make a deep copy of this.
00108 
00109   void Print(std::ostream *os);
00110   // Print this dependency path.
00111 
00112   int Size() { return content->path->size(); };
00113   // The length of this dependency path.
00114 
00115   int Version() { return content->dpathVersion; };
00116   // The version of this path.
00117 
00118   void Extend(const Text& id, PathKind pk = NormPK);
00119   // Extend (destructively) this path by id.
00120 
00121   void Extend(const ArcSeq& p, PathKind pk = NormPK);
00122   // Extend (destructively) this path by p from the end.
00123 
00124   void ExtendLow(const DepPath *dp);
00125   // Extend (destructively) this path by p from the front.
00126 
00127   Word Hash() const throw () { return content->pathFP.Hash(); };
00128   // Return a hash value for this.
00129 
00130   friend bool operator== (const DepPath& p1, const DepPath& p2)
00131     throw () {
00132       return ((p1.content->pathFP == p2.content->pathFP) && 
00133               (p1.content->pKind == p2.content->pKind)); };
00134   // Compare equality of two DepPaths.
00135 };
00136 
00138 class DepPathTbl {
00139 public:
00140   typedef SharedTable<DepPath, Val>::T T;
00141   typedef SharedTable<DepPath, Val>::Iterator TIter;
00142   typedef SharedTable<DepPath, Val>::KVPair KVPair;
00143   typedef KVPair *KVPairPtr;
00144 
00145   class DPS: public T {
00146   public:
00147     DPS(int sizeHint = 0) throw (): T(sizeHint) { /*SKIP*/ };
00148     bool Member(const DepPath& p) { KVPairPtr dummyKV; return Get(p, dummyKV); };
00149     DPS* Add(DepPath *dp, Val v, PathKind pk = DummyPK);
00150     DPS* AddExtend(DepPath *dp, Val v, PathKind pk, const Text& id);
00151     DPS* Merge(DPS *pds) { if (pds != NULL) this->Copy(pds); return this; };
00152     void Print(std::ostream *os);
00153   };
00154 };
00155 
00156 typedef DepPathTbl::DPS DPaths;
00157 
00158 #endif // Dep_H

Generated on Mon May 8 00:48:37 2006 for Vesta by  doxygen 1.4.2