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

FV.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 // Created on Fri Nov  7 10:11:38 PST 1997 by heydon
00020 // Last modified on Fri Apr 22 18:36:17 EDT 2005 by ken@xorian.net
00021 //      modified on Thu May  7 12:44:30 PDT 1998 by heydon
00022 
00023 /* Defines the types "FV::Epoch", "FV::T", "FV::List", and "FV::ListApp".
00024    A "FV::T" is a free variable, a subtype of "Text".
00025 
00026    IMPORTANT: Use of this interface assumes you are linking your
00027    application program with a garbage collector! Also, none of these
00028    classes defines an assignment operator, so objects are copied
00029    field-wise by default. This means that use of the assignment
00030    operator will produce aliases for those fields that are pointer
00031    types. */
00032 
00033 #ifndef _FV_H
00034 #define _FV_H
00035 
00036 #include <Basics.H>
00037 #include <FS.H>
00038 #include <SRPC.H>
00039 #include <VestaLog.H>
00040 #include <Recovery.H>
00041 #include "BitVector.H"
00042 #include "PrefixTbl.H"
00043 
00044 namespace FV
00045 {
00046   // epoch of free variables set
00047   typedef int Epoch;
00048 
00049   // free variable
00050   class T: public Text {
00051   public:
00052     // inherit all constructors from "Text"
00053     T() throw () : Text() { /*SKIP*/ }
00054     T(const T& t) throw (): Text(t) { /*SKIP*/ }
00055     T(const char c) throw (): Text(c) { /*SKIP*/ }
00056     T(const char *str) throw (): Text(str) { /*SKIP*/ }
00057     T(const char *bytes, int len) throw (): Text(bytes, len) { /*SKIP*/ }
00058 
00059     // send/receive
00060     void Send(SRPC &srpc) const throw (SRPC::failure)
00061     { srpc.send_chars(this->s); }
00062     void Recv(SRPC &srpc) throw (SRPC::failure)
00063     { this->s = srpc.recv_chars(); }
00064   };
00065     
00066   // list of free variables
00067   class List {
00068   public:
00069     FV::T *name;                // array of names
00070     Basics::int32 len;      // size of "name" array
00071 
00072     List() throw () : len(0), name(NULL) { /*SKIP*/ }
00073     List(int size) throw () : len(size), name(NEW_ARRAY(FV::T, size)) { }
00074     List(SRPC &srpc) throw (SRPC::failure) { Recv(srpc); }
00075     List(RecoveryReader &rd) throw (VestaLog::Error, VestaLog::Eof)
00076     { Recover(rd); }
00077     List(std::istream &ifs) throw (FS::EndOfFile, FS::Failure)
00078     { Read(ifs); }
00079 
00080     // copy
00081     void Copy(const List &l) throw ();
00082     /* Set this list to a copy of the names in "l". */
00083 
00084     // size
00085     int CheapSize() const throw ()
00086     /* This is an underestimate of the actual storage size of a List,
00087        but it statically computable. */
00088     { return sizeof(this->len) + (this->len * sizeof(*(this->name))); }
00089     int Size() const throw ();
00090     /* This is the true size of a List, but it takes time linear
00091        in the sum of the sizes of the List names to compute. */
00092 
00093     // send/receive
00094     void Send(SRPC &srpc) const throw (SRPC::failure, PrefixTbl::Overflow);
00095     void Recv(SRPC &srpc) throw (SRPC::failure);
00096 
00097     // print
00098     friend std::ostream& operator << (std::ostream &os, const List &names) throw ();
00099     void Print(std::ostream &os, int indent,
00100                const BitVector *bv = (BitVector *)NULL) const throw ();
00101     /* Print a list of names, each on its own line and indented by
00102        "indent" spaces. If "bv" is non-NULL and "indent > 1", then each
00103        name in the list whose index corresponds to a set bit in "bv" is
00104        preceeded by a "*". */
00105 
00106     // logging/recovery
00107     void Log(VestaLog &log) const throw (VestaLog::Error);
00108     void Recover(RecoveryReader &rd)
00109       throw (VestaLog::Error, VestaLog::Eof);
00110 
00111     // write/read
00112     void Write(std::ostream &ofs) const throw (FS::Failure);
00113     void Read(std::istream &ifs) throw (FS::EndOfFile, FS::Failure);
00114 
00115   private:
00116     // hide the copy constructor from clients
00117     List(const List&);
00118   };
00119 
00120   // list with append operation
00121   class ListApp: public List {
00122   public:
00123     // constructors
00124     ListApp() throw ()
00125       : List(), maxLen(0) { /*SKIP*/ }
00126     ListApp(int sizeHint) throw ()
00127       : List(), maxLen(sizeHint) {
00128       this->name = NEW_ARRAY(FV::T, sizeHint);
00129     }
00130     ListApp(RecoveryReader &rd) throw (VestaLog::Error, VestaLog::Eof)
00131     { Recover(rd); }
00132     ListApp(std::istream &ifs) throw (FS::EndOfFile, FS::Failure)
00133     { Read(ifs); }
00134 
00135     void Reset() throw () { len = 0; }
00136     /* Reset this list so as not to contain any names; this does not free
00137        the list's underlying storage. */
00138 
00139     void Grow(int sizeHint) throw ();
00140     /* Allocate enough storage so this list can hold up to "sizeHint"
00141        names without requiring any new allocation. */
00142 
00143     int Append(const FV::T& s) throw ();
00144     /* Append the text "s" to the list, and return the index of "s" in
00145        the (zero-based) "name" array. */
00146 
00147     void Pack(const BitVector &packMask) throw ();
00148     /* "Pack" the names in this list so as to include only those names
00149        whose indices correspond to set bits in "packMask". The order of
00150        those preserved names is unchanged, but the names are packed toward
00151        the start of the array so there are no holes in the list. */
00152     void Pack(const BitVector *packMask) throw ()
00153     { if (packMask != (BitVector *)NULL) Pack(*packMask); }
00154 
00155     // logging/recovery
00156     void Recover(RecoveryReader &rd)
00157       throw (VestaLog::Error, VestaLog::Eof)
00158     {
00159       List::Recover(rd);
00160       this->maxLen = this->len;
00161     }
00162 
00163     // write/read
00164     void Read(std::istream &ifs) throw (FS::EndOfFile, FS::Failure)
00165     {
00166       List::Read(ifs);
00167       this->maxLen = this->len;
00168     }
00169 
00170   private:
00171     int maxLen;           // size of "name"
00172 
00173     // hide the copy constructor from clients
00174     ListApp(const ListApp&);
00175   };
00176 }
00177 
00178 #endif // _FV_H

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