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

PKPrefix.H

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 // Last modified on Tue Aug  3 16:56:58 EDT 2004 by ken@xorian.net  
00020 //      modified on Sat Feb 12 12:02:13 PST 2000 by mann  
00021 //      modified on Mon Nov 10 12:41:26 PST 1997 by heydon
00022 
00023 // PKPrefix -- A fingerprint prefix for indexing a table of MultiPKFiles.
00024 
00025 #ifndef _PK_PREFIX_H
00026 #define _PK_PREFIX_H
00027 
00028 #include <Basics.H>
00029 #include <SRPC.H>
00030 #include <FP.H>
00031 
00032 class PKPrefix {
00033   public:
00034     static int Granularity() throw ();
00035     /* Return the current granularity. */
00036 
00037     class T {
00038       public:
00039         T() throw () { /*SKIP*/ }
00040         /* Default constructor; leaves prefix uninitialized. */
00041 
00042         T(const FP::Tag& fp) throw ()
00043             { this->w = fp.Word0(); Init(Granularity()); }
00044         /* Initialize the prefix from the fingerprint "fp". */
00045 
00046         T(const FP::Tag& fp, int gran) throw ()
00047             { this->w = fp.Word0(); Init(gran); }
00048         /* Initialize the prefix from the fingerprint "fp" with
00049            granularity "gran". This method should only be used
00050            by test programs. */
00051 
00052         Text Pathname(int sigBits, int arcBits) const throw ();
00053         /* Return a (relative) pathname for the significant "sigBits" of this
00054            PKPrefix. Each arc name is formed from "arcBits" bits. */
00055 
00056         /*** Write/Read ***/
00057 
00058         /* Write/read this prefix to/from the given stream. */
00059         void Write(std::ostream &ofs) const throw (FS::Failure)
00060             { FS::Write(ofs, (char *)(&(this->w)), sizeof(this->w)); }
00061         void Read(std::istream &ifs) throw (FS::EndOfFile, FS::Failure)
00062             { FS::Read(ifs, (char *)(&(this->w)), sizeof(this->w)); }
00063 
00064         /*** Send/Receive ***/
00065 
00066         /* Send/receive the prefix to/from "srpc". */
00067         void Send(SRPC &srpc) const throw (SRPC::failure)
00068             { srpc.send_int64(this->w); }
00069         void Recv(SRPC &srpc) throw (SRPC::failure)
00070             { this->w = srpc.recv_int64(); }
00071 
00072         // operators
00073         friend std::ostream& operator << (std::ostream &os, const T &pfx) throw ();
00074         friend bool operator == (const T &pfx1, const T &pfx2) throw ()
00075             { return pfx1.w == pfx2.w; }
00076         friend bool operator != (const T &pfx1, const T &pfx2) throw ()
00077             { return pfx1.w != pfx2.w; }
00078 
00079         // hash
00080         Word Hash() const throw () { return this->w; };
00081         /* Return a hash value for this fingerprint. */
00082 
00083       private:
00084         Word w;
00085 
00086         void Init(int gran) throw();
00087         /* Initialize this prefix for granularity "gran". */
00088     };
00089 
00090     class List {
00091       public:
00092         PKPrefix::T *pfx;  // array of prefixes
00093         int len;           // size of "pfx" array
00094 
00095         List() throw () : len(0), pfx(NULL) { /*SKIP*/ }
00096         List(SRPC &srpc) throw (SRPC::failure) { Recv(srpc); }
00097 
00098         // write/read
00099         void Write(std::ostream &ofs) const throw (FS::Failure);
00100         void Read(std::istream &ifs) throw (FS::EndOfFile, FS::Failure);
00101 
00102         // send/receive
00103         void Send(SRPC &srpc) const throw (SRPC::failure);
00104         void Recv(SRPC &srpc) throw (SRPC::failure);
00105 
00106         // print
00107         void Print(std::ostream &os, int indent) const throw ();
00108       private:
00109         // hide copy constructor
00110         List(const List&);
00111     };
00112 };
00113 
00114 #endif // _PK_PREFIX_H

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