00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00063
00064
00065 {
00066 CompactFV::List names(*this);
00067 names.Send(srpc);
00068 }
00069
00070 void FV::List::Recv(SRPC &srpc) throw (SRPC::failure)
00071
00072
00073 {
00074
00075
00076 srpc.recv_seq_start( &(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, 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, this->name[i]);
00153 }
00154 } else {
00155 this->name = (FV::T *)NULL;
00156 }
00157 }
00158
00159
00160
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( 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 (; i < oldLen; i++) {
00207 this->name[i] = empty;
00208 }
00209 }