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

CompactFV.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 Mon Mar 30 11:38:16 PST 1998 by heydon
00020 // Last modified on Fri Apr 22 17:20:01 EDT 2005 by ken@xorian.net        
00021 //      modified on Sun Jul 28 12:12:48 EDT 2002 by lken@remote.xorian.net
00022 //      modified on Fri May  8 16:06:36 PDT 1998 by heydon
00023 
00024 #include <Basics.H>
00025 #include <SRPC.H>
00026 #include "FV.H"
00027 #include "PrefixTbl.H"
00028 #include "BitVector.H"
00029 #include "PrefixTbl.H"
00030 #include "CompactFV.H"
00031 
00032 using std::ostream;
00033 using std::istream;
00034 using std::endl;
00035 
00036 CompactFV::List::List(const FV::List &names) throw (PrefixTbl::Overflow)
00037 : num((short) names.len), tbl(names.len + 5)
00038 {
00039     if (names.len > 0) {
00040         this->idx = NEW_PTRFREE_ARRAY(short, names.len);
00041         this->types = NEW_PTRFREE_ARRAY(char, names.len);
00042         TextIntTbl putTbl(/*sizeHint=*/ names.len << 1, /*useGC=*/ true);
00043         for (int i = 0; i < names.len; i++) {
00044             const char *str = names.name[i].cchars();
00045 
00046             // strip off name type code (a single character)
00047             assert(str[0] != '\0' && str[1] == '/');
00048             this->types[i] = str[0];
00049 
00050             // add rest of path to table
00051             this->idx[i] = this->tbl.Put(str+2, /*INOUT*/ putTbl);
00052         }
00053     } else {
00054         this->idx = (short *)NULL;
00055         this->types = (char *)NULL;
00056     }
00057 }
00058 
00059 void CompactFV::List::ToFVList(/*INOUT*/ FV::ListApp &fvl) const throw ()
00060 {
00061     const int BuffLen = 100;
00062     char buff[BuffLen + 2];
00063 
00064     char *str = buff;
00065     int strLen = BuffLen;
00066     str[1] = '/';
00067     for (int i = 0; i < this->num; i++) {
00068         while (! this->tbl.GetString(this->idx[i], str+2, strLen)) {
00069             // allocate a new, larger buffer and try again
00070             strLen <<= 1;
00071             str = NEW_PTRFREE_ARRAY(char, strLen + 2);
00072             str[1] = '/';
00073         }
00074         str[0] = this->types[i];
00075         int ix = fvl.Append(FV::T(str)); assert(ix == i);
00076     }
00077 }
00078 
00079 void CompactFV::List::Write(ostream &ofs) const throw (FS::Failure)
00080 {
00081     this->tbl.Write(ofs);
00082     FS::Write(ofs, (char *)(&(this->num)), sizeof(this->num));
00083     if (this->num > 0) {
00084         FS::Write(ofs, this->types, this->num * sizeof(this->types[0]));
00085         FS::Write(ofs, (char *)(this->idx), this->num * sizeof(this->idx[0]));
00086     }
00087 }
00088 
00089 void CompactFV::List::Read(istream &ifs) throw (FS::EndOfFile, FS::Failure)
00090 {
00091     this->tbl.Read(ifs);
00092     FS::Read(ifs, (char *)(&(this->num)), sizeof(this->num));
00093     if (this->num > 0) {
00094         this->types = NEW_PTRFREE_ARRAY(char, this->num);
00095         this->idx = NEW_PTRFREE_ARRAY(short, this->num);
00096         FS::Read(ifs, this->types, this->num * sizeof(this->types[0]));
00097         FS::Read(ifs, (char *)(this->idx), this->num * sizeof(this->idx[0]));
00098     } else {
00099         this->types = (char *) NULL;
00100         this->idx = (short *) NULL;
00101     }
00102 }
00103 
00104 void CompactFV::List::Send(SRPC &srpc) const throw (SRPC::failure)
00105 {
00106     this->tbl.Send(srpc);
00107     srpc.send_bytes((const char *)(this->types), this->num);
00108     srpc.send_short_array(this->idx, this->num);
00109 }
00110 
00111 void CompactFV::List::Recv(SRPC &srpc) throw (SRPC::failure)
00112 /* Note: The wire protocol of this method must agree with that of
00113    "FV::List::Send" in "FV.C". */
00114 {
00115     this->tbl.Recv(srpc);
00116     int len;
00117     this->types = srpc.recv_bytes(/*OUT*/ len);
00118     this->idx = srpc.recv_short_array(/*OUT*/ len);
00119     this->num = (short) len;
00120 }
00121 
00122 inline void Indent(ostream &os, int indent) throw ()
00123 {
00124     for (int i = 0; i < indent; i++) os << " ";
00125 }
00126 
00127 void CompactFV::List::Print(ostream &os, int indent) const throw ()
00128 {
00129     for (int i = 0; i < this->num; i++) {
00130         Indent(os, indent);
00131         FV2::T *nm = this->tbl.Get(this->idx[i]);
00132         os << this->types[i] << '/' << *nm << endl;
00133     }
00134 }

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