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

StatMPKFile.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 // Last modified on Fri Apr 29 00:27:48 EDT 2005 by ken@xorian.net         
00020 //      modified on Mon Jul 15 17:14:55 EDT 2002 by kcschalk@shr.intel.com 
00021 //      modified on Sat Feb 12 13:10:04 PST 2000 by mann  
00022 //      modified on Wed Oct 21 20:24:26 PDT 1998 by heydon
00023 
00024 #include <Basics.H>
00025 #include <FS.H>
00026 #include "SMultiPKFileRep.H"
00027 #include "StatError.H"
00028 #include "StatNames.H"
00029 #include "StatDirEntry.H"
00030 #include "StatPKFile.H"
00031 #include "StatMPKFile.H"
00032 
00033 using std::ifstream;
00034 using std::cout;
00035 using std::endl;
00036 
00037 int MPKFileObj::Search(int verbose, /*INOUT*/ Stat::Collection &stats)
00038   throw (StatError::BadMPKFile,
00039          StatError::EndOfFile, FS::Failure, FS::DoesNotExist)
00040 {
00041     if (verbose >= 2) {
00042         cout << "  " << this->fname << endl;
00043     }
00044 
00045     // read the MPKFile
00046     ifstream ifs;
00047     FS::OpenReadOnly(this->fname, /*OUT*/ ifs);
00048     try {
00049         try {
00050           this->hdr = NEW_CONSTR(SMultiPKFileRep::Header, (ifs));
00051           this->hdr->ReadEntries(ifs);
00052           this->hdr->ReadPKFiles(ifs);
00053         }
00054         catch (SMultiPKFileRep::BadMPKFile) {
00055             throw (StatError::BadMPKFile(this->fname));
00056         }
00057         catch (FS::EndOfFile) {
00058             throw (StatError::EndOfFile(this->fname));
00059         }
00060     }
00061     catch (...) {
00062         FS::Close(ifs);
00063         throw;
00064     }
00065     FS::Close(ifs);
00066 
00067     // iterate over children
00068     int cnt;
00069     {
00070       PKFileObj *pkf = (PKFileObj *) 0;
00071       MPKFileIter it(this);
00072       for (cnt = 0; it.Next(/*OUT*/ pkf); cnt++) {
00073         (void) pkf->Search(verbose, /*INOUT*/ stats);
00074       }
00075       pkf = (PKFileObj *) 0; // drop on floor for GC
00076     }
00077 
00078     // update "stats.entryStats" field for this MultiPKFile
00079     stats.entryStats[Stat::MPKFileSize].AddVal(this->hdr->totalLen, this->loc);
00080 
00081     // update fan-out for this level
00082     int thisLevel = 3;
00083     StatCount *sc;
00084     if (stats.fanout.size() <= thisLevel) {
00085         assert(stats.fanout.size() == thisLevel);
00086         sc = NEW(StatCount);
00087         stats.fanout.addhi(sc);
00088     } else {
00089         sc = stats.fanout.get(thisLevel);
00090     }
00091     sc->AddVal(cnt, this->loc);
00092     return thisLevel;
00093 }
00094 
00095 bool MPKFileIter::Next(/*OUT*/ PKFileObj* &pkf) throw ()
00096 {
00097     const SMultiPKFileRep::Header *hdr = this->mpkf->hdr;
00098     bool res = (this->pkIndex < hdr->num);
00099     if (res) {
00100         SMultiPKFileRep::HeaderEntry *he;
00101         FP::Tag *fpPtr = hdr->pkSeq[this->pkIndex++];
00102         bool inTbl = hdr->pkTbl.Get(*fpPtr, /*OUT*/ he);
00103         assert(inTbl);
00104         pkf = NEW_CONSTR(PKFileObj, (*(mpkf->loc), he));
00105     }
00106     return res;
00107 }

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