/*
* 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_DOCTABLEREADER_H_
#define HW3_DOCTABLEREADER_H_
#include // for string
#include // for (FILE*)
#include "./HashTableReader.h"
using std::string;
namespace hw3 {
// A DocTableReader (a derived class of HashTableReader) is used to
// read the single doc_id --> doc_name "doctable" within the index file.
class DocTableReader : protected HashTableReader {
public:
// Construct a new DocTableReader at a specified offset within
// an index file. Arguments:
//
// - f: an open (FILE*) for the underlying index file. The
// constructed object takes ownership of the (FILE*) and will
// fclose() it on destruction.
//
// - offset: the "doctable"'s byte offset within the file.
DocTableReader(FILE* f, IndexFileOffset_t offset);
~DocTableReader() { }
// Lookup a docID and get back a string containing the filename
// associated with the docID, if it exists.
//
// Arguments:
// - docid: the docID to look for within the doctable.
// - ret_str: the string containing the filename (an output parameter).
// Nothing is returned through this if the docID is not found.
//
// Returns:
// - true if the docID is found, false otherwise.
bool LookupDocID(const DocID_t& doc_id, string* const ret_str) const;
private:
// This friend declaration is here so that the Test_DocTableReader
// unit test fixture can access protected member variables of
// DocTableReader. See test_doctablereader.h for details.
friend class Test_DocTableReader;
DISALLOW_COPY_AND_ASSIGN(DocTableReader);
};
} // namespace hw3
#endif // HW3_DOCTABLEREADER_H_