wisc_db
Public Member Functions | List of all members
wiscdb::FileIterator Class Reference

Iterator for iterating over the pages in a file. More...

#include <file_iterator.h>

Public Member Functions

 FileIterator ()
 
 FileIterator (File *file)
 
 FileIterator (File *file, PageId page_number)
 
FileIteratoroperator++ ()
 
FileIterator operator++ (int)
 
bool operator== (const FileIterator &rhs) const
 
bool operator!= (const FileIterator &rhs) const
 
Page operator* () const
 

Detailed Description

Iterator for iterating over the pages in a file.

This class provides a forward-only iterator for iterating over all of the pages in a file.

Definition at line 23 of file file_iterator.h.

Constructor & Destructor Documentation

wiscdb::FileIterator::FileIterator ( )
inline

Constructs an empty iterator.

Definition at line 28 of file file_iterator.h.

29  : file_(NULL),
30  current_page_number_(Page::INVALID_NUMBER) {
31  }
static const PageId INVALID_NUMBER
Definition: page.h:132
wiscdb::FileIterator::FileIterator ( File file)
inline

Constructors an iterator over the pages in a file, starting at the first page.

Parameters
fileFile to iterate over.

Definition at line 39 of file file_iterator.h.

40  : file_(file) {
41  assert(file_ != NULL);
42  const FileHeader& header = file_->readHeader();
43  current_page_number_ = header.first_used_page;
44  }
wiscdb::FileIterator::FileIterator ( File file,
PageId  page_number 
)
inline

Constructs an iterator over the pages in a file, starting at the given page number.

Parameters
fileFile to iterate over.
page_numberNumber of page to start iterator at.

Definition at line 53 of file file_iterator.h.

54  : file_(file),
55  current_page_number_(page_number) {
56  }

Member Function Documentation

Page wiscdb::FileIterator::operator* ( ) const
inline

Dereferences the iterator, returning a copy of the current page in the file.

Returns
Page in file.

Definition at line 103 of file file_iterator.h.

104  { return file_->readPage(current_page_number_); }
Page readPage(const PageId page_number) const
FileIterator& wiscdb::FileIterator::operator++ ( )
inline

Advances the iterator to the next page in the file.

Definition at line 61 of file file_iterator.h.

61  {
62  assert(file_ != NULL);
63  const PageHeader& header = file_->readPageHeader(current_page_number_);
64  current_page_number_ = header.next_page_number;
65 
66  return *this;
67  }
bool wiscdb::FileIterator::operator== ( const FileIterator rhs) const
inline

Returns true if this iterator is equal to the given iterator.

Parameters
rhsIterator to compare against.
Returns
True if other iterator is equal to this one.

Definition at line 87 of file file_iterator.h.

87  {
88  return file_->filename() == rhs.file_->filename() &&
89  current_page_number_ == rhs.current_page_number_;
90  }
const std::string & filename() const
Definition: file.h:180

The documentation for this class was generated from the following file: