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

FV.C

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:16:28 PST 1997 by heydon
00020 // Last modified on Fri Apr 22 17:49:59 EDT 2005 by ken@xorian.net
00021 //      modified on Fri May  8 12:05:29 PDT 1998 by heydon
00022 
00023 #include <Basics.H>
00024 #include <FS.H>
00025 #include <VestaLog.H>
00026 #include <Recovery.H>
00027 #include "TextIO.H"
00028 #include "BitVector.H"
00029 #include "FV.H"
00030 #include "CompactFV.H"
00031 
00032 using std::ostream;
00033 using std::istream;
00034 
00035 inline void Indent(ostream &os, int indent) throw ()
00036 {
00037     for (int i = 0; i < indent; i++) os << " ";
00038 }
00039 
00040 // FV::List -------------------------------------------------------------------
00041 
00042 void FV::List::Copy(const FV::List &l) throw ()
00043 {
00044     this->len = l.len;
00045     this->name = NEW_ARRAY(FV::T, l.len);
00046     for (int i = 0; i < l.len; i++) {
00047         this->name[i] = l.name[i];
00048     }
00049 }
00050 
00051 int FV::List::Size() const throw ()
00052 {
00053     register int res = this->CheapSize();
00054     for (int i = 0; i < this->len; i++) {
00055         res += name[i].Length() + 1;
00056     }
00057     return res;
00058 }
00059 
00060 void FV::List::Send(SRPC &srpc) const throw (SRPC::failure,
00061                                              PrefixTbl::Overflow)
00062 /* Note: The following must agree with "CompactFV::List::Recv"
00063    in "CompactFV.C". This method is only called to send back
00064    the PKFile's "allNames" for the "FreeVariables" method. */
00065 {
00066     CompactFV::List names(*this);
00067     names.Send(srpc);
00068 }
00069 
00070 void FV::List::Recv(SRPC &srpc) throw (SRPC::failure)
00071 /* Note: The following method must agree with "FV2::List::Send"
00072    in "FV2.C". */
00073 {
00074     // The following code unmarshalls a list of FV::T's as
00075     // a sequence of Texts
00076     srpc.recv_seq_start(/*OUT*/ &(this->len));
00077     this->name = NEW_ARRAY(FV::T, this->len);
00078     for (int i = 0; i < this->len; i++) {
00079         this->name[i].Recv(srpc);
00080     }
00081     srpc.recv_seq_end();
00082 }
00083 
00084 ostream& operator << (ostream &os, const FV::List &names) throw ()
00085 {
00086     os << "{ ";
00087     for (int i = 0; i < names.len; i++) {
00088         os << "\"" << names.name[i] << "\"";
00089         if (i < names.len - 1) os << ", ";
00090     }
00091     os << " }";
00092     return os;
00093 }
00094 
00095 void FV::List::Print(ostream &os, int indent, const BitVector *bv)
00096   const throw ()
00097 {
00098     if (this->len > 0) {
00099         indent--;
00100         for (int i = 0; i < this->len; i++) {
00101             if (indent >= 0) {
00102                 Indent(os, indent);
00103                 os << ((bv != NULL && bv->Read(i)) ? '*' : ' ');
00104             }
00105             os << "nm[" << i << "] = \"" << this->name[i] << "\"\n";
00106         }
00107     } else {
00108         Indent(os, indent);
00109         os << "<< no names >>\n";
00110     }
00111 }
00112 
00113 void FV::List::Log(VestaLog &log) const
00114   throw (VestaLog::Error)
00115 {
00116     log.write((char *)(&(this->len)), sizeof(this->len));
00117     for (int i = 0; i < this->len; i++) {
00118         TextIO::Log(log, this->name[i]);
00119     }
00120 }
00121 
00122 void FV::List::Recover(RecoveryReader &rd)
00123   throw (VestaLog::Error, VestaLog::Eof)
00124 {
00125     rd.readAll((char *)(&(this->len)), sizeof(this->len));
00126     if (this->len > 0) {
00127         this->name = NEW_ARRAY(FV::T, this->len);
00128         for (int i = 0; i < this->len; i++) {
00129             TextIO::Recover(rd, /*OUT*/ this->name[i]);
00130         }
00131     } else {
00132         this->name = (FV::T *)NULL;
00133     }
00134 }
00135 
00136 void FV::List::Write(ostream &ofs) const
00137   throw (FS::Failure)
00138 {
00139     FS::Write(ofs, (char *)(&(this->len)), sizeof(this->len));
00140     for (int i = 0; i < this->len; i++) {
00141         TextIO::Write(ofs, this->name[i]);
00142     }
00143 }
00144 
00145 void FV::List::Read(istream &ifs)
00146   throw (FS::EndOfFile, FS::Failure)
00147 {
00148     FS::Read(ifs, (char *)(&(this->len)), sizeof(this->len));
00149     if (this->len > 0) {
00150         this->name = NEW_ARRAY(FV::T, this->len);
00151         for (int i = 0; i < this->len; i++) {
00152             TextIO::Read(ifs, /*OUT*/ this->name[i]);
00153         }
00154     } else {
00155         this->name = (FV::T *)NULL;
00156     }
00157 }
00158 
00159 
00160 // FV::ListApp ----------------------------------------------------------------
00161 
00162 void FV::ListApp::Grow(int sizeHint) throw ()
00163 {
00164     if (this->maxLen < sizeHint) {
00165         FV::T *new_names = NEW_ARRAY(FV::T, sizeHint);
00166         if (this->name != (FV::T *)NULL) {
00167             for (int i = 0; i < this->len; i++) {
00168                 new_names[i] = this->name[i];
00169             }
00170         }
00171         this->name = new_names;
00172         this->maxLen = sizeHint;
00173     }
00174 }
00175 
00176 int FV::ListApp::Append(const FV::T& s) throw ()
00177 {
00178     int res;
00179     if (this->len == this->maxLen) {
00180         this->maxLen = max(2, 2 * this->maxLen);
00181         assert(this->maxLen > this->len);
00182         FV::T *newNames = NEW_ARRAY(FV::T, this->maxLen);
00183         if (this->name != (FV::T *)NULL) {
00184             for (int i = 0; i < this->len; i++) {
00185                 newNames[i] = this->name[i];
00186             }
00187         }
00188         this->name = newNames;
00189     }
00190     res = this->len;
00191     this->name[this->len++] = s;
00192     return res;
00193 }
00194 
00195 void FV::ListApp::Pack(const BitVector &packMask) throw ()
00196 {
00197     BVIter it(&packMask);
00198     int i, ix;
00199     for (i = 0; it.Next(/*OUT*/ ix); i++) {
00200         assert(i <= ix);
00201         if (i < ix) this->name[i] = this->name[ix];
00202     }
00203     int oldLen = this->len;
00204     this->len = i;
00205     FV::T empty;
00206     for (/*SKIP*/; i < oldLen; i++) {
00207         this->name[i] = empty;
00208     }
00209 }

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