wisc_db
Main Page
Namespaces
Classes
Files
File List
home
newhall
public
cs44
wiscdb
src
file_iterator.h
1
8
#pragma once
9
10
#include <cassert>
11
#include "file.h"
12
#include "page.h"
13
#include "types.h"
14
15
namespace
wiscdb
{
16
23
class
FileIterator
{
24
public
:
28
FileIterator
()
29
: file_(NULL),
30
current_page_number_(
Page
::INVALID_NUMBER) {
31
}
32
39
FileIterator
(
File
* file)
40
: file_(file) {
41
assert(file_ != NULL);
42
const
FileHeader
& header = file_->readHeader();
43
current_page_number_ = header.
first_used_page
;
44
}
45
53
FileIterator
(
File
* file,
PageId
page_number)
54
: file_(file),
55
current_page_number_(page_number) {
56
}
57
61
inline
FileIterator
&
operator++
() {
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
}
68
69
//postfix
70
inline
FileIterator
operator++
(
int
)
71
{
72
FileIterator
tmp = *
this
;
// copy ourselves
73
74
assert(file_ != NULL);
75
const
PageHeader
& header = file_->readPageHeader(current_page_number_);
76
current_page_number_ = header.
next_page_number
;
77
78
return
tmp;
79
}
80
87
inline
bool
operator==
(
const
FileIterator
& rhs)
const
{
88
return
file_->
filename
() == rhs.file_->
filename
() &&
89
current_page_number_ == rhs.current_page_number_;
90
}
91
92
inline
bool
operator!=(
const
FileIterator
& rhs)
const
{
93
return
(file_->
filename
() != rhs.file_->
filename
()) ||
94
(current_page_number_ != rhs.current_page_number_);
95
}
96
103
inline
Page
operator*
()
const
104
{
return
file_->
readPage
(current_page_number_); }
105
106
private
:
110
File
* file_;
111
115
PageId
current_page_number_;
116
};
117
118
}
wiscdb::Page
Class which represents a fixed-size database page containing records.
Definition:
page.h:110
wiscdb
Definition:
buffer.h:14
wiscdb::FileIterator::FileIterator
FileIterator(File *file, PageId page_number)
Definition:
file_iterator.h:53
wiscdb::File::readPage
Page readPage(const PageId page_number) const
wiscdb::FileIterator::operator++
FileIterator & operator++()
Definition:
file_iterator.h:61
wiscdb::FileHeader::first_used_page
PageId first_used_page
Definition:
file.h:31
wiscdb::FileIterator::FileIterator
FileIterator()
Definition:
file_iterator.h:28
wiscdb::FileIterator::operator==
bool operator==(const FileIterator &rhs) const
Definition:
file_iterator.h:87
wiscdb::PageId
std::uint32_t PageId
Identifier for a page in a file.
Definition:
types.h:15
wiscdb::PageHeader::next_page_number
PageId next_page_number
Definition:
page.h:59
wiscdb::FileHeader
Header metadata for files on disk which contain pages.
Definition:
file.h:22
wiscdb::FileIterator
Iterator for iterating over the pages in a file.
Definition:
file_iterator.h:23
wiscdb::FileIterator::FileIterator
FileIterator(File *file)
Definition:
file_iterator.h:39
wiscdb::File
Represents a file in the filesystem containing pages.
Definition:
file.h:71
wiscdb::FileIterator::operator*
Page operator*() const
Definition:
file_iterator.h:103
wiscdb::File::filename
const std::string & filename() const
Definition:
file.h:180
wiscdb::PageHeader
Header metadata in a page.
Definition:
page.h:26
Generated by
1.8.11