/* * Copyright 2012 Steven Gribble * * This file is part of the UW CSE 333 course project sequence * (333proj). * * 333proj is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 333proj is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 333proj. If not, see . */ #ifndef HW3_FILEINDEXREADER_H_ #define HW3_FILEINDEXREADER_H_ #include // for std::string #include // for (FILE*) #include "./DocTableReader.h" #include "./IndexTableReader.h" #include "./LayoutStructs.h" #include "./Utils.h" using std::string; namespace hw3 { // A FileIndexReader is used to access an index file, read the header // information out of it, and manufacture DocTableReader and // IndexTableReader hash table accessors. (To manufacture a // DocIDTableReader, you use a manufactured IndexTableReader.) class FileIndexReader { public: // Arguments: // - file_name: the index file to load. // - validate: whether to validate the checksums (default=true). explicit FileIndexReader(const string& file_name, bool validate = true); ~FileIndexReader(); // Manufactures and returns a DocTableReader for this index file. // A DocTableReader is a HashTableReader subclass that is // specialized to read the docid-->filename hashtable within this // index file. (See DocTableReader.h for details.) DocTableReader* NewDocTableReader() const; // Manufactures and returns an IndexTableReader for this index file. // An IndexTableReader is a HashTableReader subclass that is // specialized to read the word-->docidtable hashtable within this // index file. (See IndexTableReader.h for details.) IndexTableReader* NewIndexTableReader() const; // Returns a const reference to the file header information. const IndexFileHeader& getHeader() const { return header_; } protected: // The name of the index file we're reading. string file_name_; // The stdio.h (FILE*) for the file. FILE* file_; // A cached copy of file header. IndexFileHeader header_; private: // This friend declaration is here so that the Test_FileIndexReader // unit test fixture can access protected member variables of // FileIndexReader. friend class Test_FileIndexReader; DISALLOW_COPY_AND_ASSIGN(FileIndexReader); }; } // namespace hw3 #endif // HW3_FILEINDEXREADER_H_