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 13:25:19 PST 1997 by heydon 00020 // Last modified on Wed Aug 4 17:43:19 EDT 2004 by ken@xorian.net 00021 // modified on Mon Nov 10 12:41:28 PST 1997 by heydon 00022 00023 /* This interface defines the classes "Derived::Index" (a ShortId), 00024 "Derived::Indices", and "Derived::IndicesApp". 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 _DERIVED_H 00034 #define _DERIVED_H 00035 00036 #include <Basics.H> 00037 #include <FS.H> 00038 #include <SRPC.H> 00039 #include <VestaLog.H> 00040 #include <Recovery.H> 00041 #include <SourceOrDerived.H> 00042 00043 namespace Derived 00044 { 00045 // Derived index type 00046 typedef ShortId Index; 00047 00048 // A list of derived indices 00049 class Indices { 00050 public: 00051 // data fields 00052 Index *index; // array of indices 00053 Basics::int32 len; // size of "index" array 00054 00055 // constructors/destructor 00056 Indices() throw () 00057 : len(0), index(NULL) { /*SKIP*/ } 00058 Indices(RecoveryReader &rd) throw (VestaLog::Error, VestaLog::Eof) 00059 { Recover(rd); } 00060 Indices(std::istream &ifs) throw (FS::EndOfFile, FS::Failure) 00061 { Read(ifs); } 00062 Indices(SRPC &srpc) throw (SRPC::failure) 00063 { Recv(srpc); } 00064 00065 // size 00066 int Size() const throw () 00067 { return sizeof(this->len) + (this->len * sizeof(*(this->index))); } 00068 00069 // logging/recovery 00070 void Log(VestaLog &log) const throw (VestaLog::Error); 00071 void Recover(RecoveryReader &rd) 00072 throw (VestaLog::Error, VestaLog::Eof); 00073 00074 // write/read 00075 void Write(std::ostream &ofs) const throw (FS::Failure); 00076 void Read(std::istream &ifs) throw (FS::EndOfFile, FS::Failure); 00077 00078 // skip 00079 static int Skip(std::istream &ifs) throw (FS::EndOfFile, FS::Failure); 00080 /* Advance "ifs" past the "Derived::Indices" stored at its current 00081 position, and return the total number of bytes by which "ifs" was 00082 advanced. */ 00083 00084 // send/receive 00085 void Send(SRPC &srpc) const throw (SRPC::failure); 00086 void Recv(SRPC &srpc) throw (SRPC::failure); 00087 00088 // print 00089 void Print(std::ostream &os, int indent) const throw (); 00090 00091 private: 00092 // hide the copy constructor from clients 00093 Indices(const Indices&); 00094 }; 00095 00096 // an appendable list of derived indices 00097 class IndicesApp: public Indices { 00098 public: 00099 IndicesApp() throw () 00100 : Indices(), maxLen(0) { /* SKIP */ } 00101 00102 void Append(Index di) throw (); 00103 /* Append the index "di" to this list. */ 00104 private: 00105 int maxLen; 00106 00107 // hide the copy constructor from clients 00108 IndicesApp(const IndicesApp&); 00109 }; 00110 } 00111 00112 std::ostream& operator << (std::ostream &os, const Derived::Indices &dis) throw (); 00113 00114 #endif // _DERIVED_H