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

GraphLog.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 // Last modified on Tue Aug  3 16:28:52 EDT 2004 by ken@xorian.net
00020 //      modified on Mon Nov 10 12:14:07 PST 1997 by heydon
00021 
00022 #ifndef _GRAPH_LOG_H
00023 #define _GRAPH_LOG_H
00024 
00025 #include <time.h>         // for time_t in GraphLog::Root
00026 #include <Basics.H>
00027 #include <FS.H>
00028 #include <VestaLog.H>
00029 #include <Recovery.H>
00030 #include <FP.H>
00031 
00032 #include "Model.H"
00033 #include "CacheIndex.H"
00034 #include "Derived.H"
00035 
00036 /* The "graphLog" is a linked list of "GraphLog::Node" structures. There are
00037    two kinds of entries: "Root" and "Node". Each type is a subtype of
00038    the base class "GraphLog::Entry". 
00039 
00040    The base class, "GraphLog::Entry", is not meant to be instantiated.
00041    Instead, clients should invoke the constructors of the derived "Root" and
00042    "Node" classes.
00043 
00044    Each class has a "Log" method for pickling an instance of the class to a
00045    "VestaLog". However, only the "Log" methods of the derived "Root" and
00046    "Node" classes should be used by clients.*/
00047 
00048 class GraphLog {
00049   public:
00050 
00051     // There are two kinds of graphLog entries
00052     enum Kind { RootKind, NodeKind };
00053 
00054     // Entry base class; do not instantiate directly!
00055     class Entry {
00056       public:
00057         // The kind of entry
00058         Kind kind;
00059         Entry(Kind kind) throw () : kind(kind) { /*SKIP*/ }
00060 
00061         // log/recover
00062         virtual void Log(VestaLog &log) const throw (VestaLog::Error)
00063            { log.write((char *)(&(this->kind)), sizeof(this->kind)); }
00064         static Entry *Recover(RecoveryReader &rd)
00065           throw (VestaLog::Error, VestaLog::Eof);
00066 
00067         // read/write
00068         virtual void Write(std::ostream &ofs) const throw (FS::Failure)
00069            { FS::Write(ofs, (char *)(&(this->kind)), sizeof(this->kind)); }
00070         static Entry *Read(std::istream &ifs) throw (FS::Failure, FS::EndOfFile);
00071 
00072         virtual void Debug(std::ostream &s) const throw ();
00073         /* Write a one-line representation of this entry to "s". The output is
00074            indented and ends with a newline. */
00075 
00076         virtual void DebugFull(std::ostream &s) const throw ();
00077         /* Write a complete, multi-line, representation of this entry
00078            to "s". */
00079 
00080       private:
00081         // hide copy constructor from clients
00082         Entry(const Entry &);
00083     };
00084 
00085     // Node derived class
00086     class Node: public Entry {
00087       public:
00088         Node *next;
00089         CacheEntry::Index ci;     // cache server index for this entry
00090         FP::Tag *loc;             // PK for this cache entry
00091         Model::T model;           // model in which entry's function is defined
00092         CacheEntry::Indices *kids;// child entries
00093         Derived::Indices *refs;   // deriveds reachable from this entry
00094 
00095         // Constructors
00096         Node(CacheEntry::Index ci, FP::Tag *loc, Model::T model,
00097           CacheEntry::Indices *kids, Derived::Indices *refs) throw ()
00098           : Entry(NodeKind) { Init(ci, loc, model, kids, refs); }
00099         Node(RecoveryReader &rd) throw (VestaLog::Error, VestaLog::Eof)
00100           : Entry(NodeKind) { Recover(rd); }
00101         Node(std::istream &ifs) throw (FS::Failure, FS::EndOfFile)
00102           : Entry(NodeKind) { Read(ifs); }
00103 
00104         void Init(CacheEntry::Index ci, FP::Tag *loc, Model::T model,
00105           CacheEntry::Indices *kids, Derived::Indices *refs) throw ();
00106         /* Initialize the graph log entry to the vector of its arguments. The
00107            responsibility for freeing the storage for "loc", "kids", and
00108            "refs" remains with the caller. */
00109 
00110         ~Node() throw () { this->Reset(); }
00111         void Reset() throw ()
00112            { this->loc = NULL; this->kids = NULL; this->refs = NULL; }
00113         /* Drop memory reachable from this "Node". */
00114 
00115         // log/recover
00116         void Log(VestaLog &log) const throw (VestaLog::Error);
00117         void Recover(RecoveryReader &rd)
00118           throw (VestaLog::Error, VestaLog::Eof);
00119         /* NB: The "Recover" constructor assumes the "kind" of node has
00120            already been read from the log, and is known to be "NodeKind". */
00121 
00122         // write/read
00123         void Write(std::ostream &ofs) const throw (FS::Failure);
00124         void Read(std::istream &ifs) throw (FS::Failure, FS::EndOfFile);
00125         /* NB: The "Read" constructor assumes the "kind" of node has already
00126            been read from the log, and is known to be "NodeKind". */
00127 
00128         // Overridden "Debug" and "DebugFull" methods
00129         void Debug(std::ostream &os) const throw ();
00130         void DebugFull(std::ostream &os) const throw ();
00131       private:
00132         // hide copy constructor from clients
00133         Node(const Node &);
00134     };
00135 
00136     // Root derived class
00137     class Root: public Entry {
00138       public:
00139         FP::Tag pkgVersion;
00140         Model::T model;
00141         time_t ts; // timestamp of when this node was created
00142         CacheEntry::Indices *cis;
00143         bool done;
00144 
00145         // Constructors
00146         Root(const FP::Tag &pkgVersion, Model::T model,
00147           CacheEntry::Indices *cis, bool done) throw ()
00148           : Entry(RootKind) { Init(pkgVersion, model, cis, done); }
00149         Root(RecoveryReader &rd) throw (VestaLog::Error, VestaLog::Eof)
00150           : Entry(RootKind) { Recover(rd); }
00151         Root(std::istream &ifs) throw (FS::Failure, FS::EndOfFile)
00152           : Entry(RootKind) { Read(ifs); }
00153 
00154         void Init(const FP::Tag &pkgVersion, Model::T model,
00155           CacheEntry::Indices *cis, bool done) throw ();
00156         /* Initialize the graph log entry to the vector of its arguments. The
00157            responsibility for freeing the storage for "cis" is transferred
00158            from caller to callee. */
00159 
00160         void DeleteContents() throw () { cis = NULL; }
00161         /* Drop memory reachable from this "Root". */
00162 
00163         // log/recover
00164         void Log(VestaLog &log) const throw (VestaLog::Error);
00165         void Recover(RecoveryReader &rd)
00166           throw (VestaLog::Error, VestaLog::Eof);
00167         /* NB: This constructor assumes the "kind" of node has already been
00168            read from the log, and is known to be "RootKind". */
00169 
00170         // write/read
00171         void Write(std::ostream &ofs) const throw (FS::Failure);
00172         void Read(std::istream &ifs) throw (FS::Failure, FS::EndOfFile);
00173         /* NB: The "Read" constructor assumes the "kind" of node has already
00174            been read from the log, and is known to be "NodeKind". */
00175 
00176         // Overridden "Debug" and "DebugFull" methods
00177         void Debug(std::ostream &os) const throw ();
00178         void DebugFull(std::ostream &os) const throw ();
00179 
00180       private:
00181         // hide copy constructor from clients
00182         Root(const Root &);
00183     };
00184 };
00185 
00186 #endif // _GRAPH_LOG_H

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