00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00047 typedef int Epoch;
00048
00049
00050 class T: public Text {
00051 public:
00052
00053 T() throw () : Text() { }
00054 T(const T& t) throw (): Text(t) { }
00055 T(const char c) throw (): Text(c) { }
00056 T(const char *str) throw (): Text(str) { }
00057 T(const char *bytes, int len) throw (): Text(bytes, len) { }
00058
00059
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
00067 class List {
00068 public:
00069 FV::T *name;
00070 Basics::int32 len;
00071
00072 List() throw () : len(0), name(NULL) { }
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
00081 void Copy(const List &l) throw ();
00082
00083
00084
00085 int CheapSize() const throw ()
00086
00087
00088 { return sizeof(this->len) + (this->len * sizeof(*(this->name))); }
00089 int Size() const throw ();
00090
00091
00092
00093
00094 void Send(SRPC &srpc) const throw (SRPC::failure, PrefixTbl::Overflow);
00095 void Recv(SRPC &srpc) throw (SRPC::failure);
00096
00097
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
00102
00103
00104
00105
00106
00107 void Log(VestaLog &log) const throw (VestaLog::Error);
00108 void Recover(RecoveryReader &rd)
00109 throw (VestaLog::Error, VestaLog::Eof);
00110
00111
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
00117 List(const List&);
00118 };
00119
00120
00121 class ListApp: public List {
00122 public:
00123
00124 ListApp() throw ()
00125 : List(), maxLen(0) { }
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
00137
00138
00139 void Grow(int sizeHint) throw ();
00140
00141
00142
00143 int Append(const FV::T& s) throw ();
00144
00145
00146
00147 void Pack(const BitVector &packMask) throw ();
00148
00149
00150
00151
00152 void Pack(const BitVector *packMask) throw ()
00153 { if (packMask != (BitVector *)NULL) Pack(*packMask); }
00154
00155
00156 void Recover(RecoveryReader &rd)
00157 throw (VestaLog::Error, VestaLog::Eof)
00158 {
00159 List::Recover(rd);
00160 this->maxLen = this->len;
00161 }
00162
00163
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;
00172
00173
00174 ListApp(const ListApp&);
00175 };
00176 }
00177
00178 #endif // _FV_H