BadgerDB
Main Page
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Friends
Pages
afs
cs.wisc.edu
u
h
a
haiyun
private
cs564-spr17
projects
p2
BufMgr
src
file.h
1
8
#pragma once
9
10
#include <fstream>
11
#include <string>
12
#include <map>
13
#include <memory>
14
15
#include "page.h"
16
17
namespace
badgerdb {
18
19
class
FileIterator;
20
24
struct
FileHeader
{
28
PageId
num_pages
;
29
33
PageId
first_used_page
;
34
38
PageId
num_free_pages
;
39
43
PageId
first_free_page
;
44
51
bool
operator==
(
const
FileHeader
& rhs)
const
{
52
return
num_pages
== rhs.
num_pages
&&
53
num_free_pages
== rhs.
num_free_pages
&&
54
first_used_page
== rhs.
first_used_page
&&
55
first_free_page
== rhs.
first_free_page
;
56
}
57
};
58
73
class
File
{
74
public
:
81
static
File
create
(
const
std::string&
filename
);
82
93
static
File
open
(
const
std::string& filename);
94
102
static
void
remove
(
const
std::string&
filename
);
103
109
static
bool
isOpen
(
const
std::string& filename);
110
111
117
static
bool
exists
(
const
std::string& filename);
118
125
File
(
const
File
& other);
126
133
File
&
operator=
(
const
File
& rhs);
134
139
~File
();
140
146
Page
allocatePage
();
147
156
Page
readPage
(
const
PageId
page_number)
const
;
157
165
void
writePage
(
const
Page
& new_page);
166
172
void
deletePage
(
const
PageId
page_number);
173
179
const
std::string&
filename
()
const
{
return
filename_; }
180
186
FileIterator
begin
();
187
194
FileIterator
end
();
195
196
private
:
204
static
std::streampos pagePosition(
const
PageId
page_number) {
205
return
sizeof
(
FileHeader
) + ((page_number - 1) *
Page::SIZE
);
206
}
207
222
File
(
const
std::string& name,
const
bool
create_new);
223
235
void
openIfNeeded(
const
bool
create_new);
236
242
void
close();
243
257
Page
readPage
(
const
PageId
page_number,
const
bool
allow_free)
const
;
258
267
void
writePage
(
const
PageId
page_number,
const
Page& new_page);
268
278
void
writePage
(
const
PageId
page_number,
const
PageHeader& header,
279
const
Page& new_page);
280
286
FileHeader readHeader()
const
;
287
293
void
writeHeader(
const
FileHeader& header);
294
302
PageHeader readPageHeader(
const
PageId
page_number)
const
;
303
304
typedef
std::map<std::string,
305
std::shared_ptr<std::fstream> > StreamMap;
306
typedef
std::map<std::string, int> CountMap;
307
311
static
StreamMap open_streams_;
312
316
static
CountMap open_counts_;
317
321
std::string filename_;
322
326
std::shared_ptr<std::fstream> stream_;
327
328
friend
class
FileIterator;
329
friend
class
FileTest;
330
};
331
332
}
badgerdb::File::isOpen
static bool isOpen(const std::string &filename)
Definition:
file.cpp:47
badgerdb::FileHeader::first_free_page
PageId first_free_page
Definition:
file.h:43
badgerdb::File::begin
FileIterator begin()
Definition:
file.cpp:214
badgerdb::File::end
FileIterator end()
Definition:
file.cpp:219
badgerdb::File::filename
const std::string & filename() const
Definition:
file.h:179
badgerdb::FileHeader
Header metadata for files on disk which contain pages.
Definition:
file.h:24
badgerdb::File::open
static File open(const std::string &filename)
Definition:
file.cpp:33
badgerdb::File
Class which represents a file in the filesystem containing database pages.
Definition:
file.h:73
badgerdb::File::~File
~File()
Definition:
file.cpp:80
badgerdb::File::create
static File create(const std::string &filename)
Definition:
file.cpp:29
badgerdb::PageId
std::uint32_t PageId
Identifier for a page in a file.
Definition:
types.h:15
badgerdb::FileHeader::num_pages
PageId num_pages
Definition:
file.h:28
badgerdb::Page::SIZE
static const std::size_t SIZE
Definition:
page.h:113
badgerdb::Page
Class which represents a fixed-size database page containing records.
Definition:
page.h:107
badgerdb::FileHeader::operator==
bool operator==(const FileHeader &rhs) const
Definition:
file.h:51
badgerdb::File::writePage
void writePage(const Page &new_page)
Definition:
file.cpp:169
badgerdb::FileIterator
Iterator for iterating over the pages in a file.
Definition:
file_iterator.h:23
badgerdb::File::File
File(const File &other)
Definition:
file.cpp:65
badgerdb::File::readPage
Page readPage(const PageId page_number) const
Definition:
file.cpp:149
badgerdb::FileHeader::num_free_pages
PageId num_free_pages
Definition:
file.h:38
badgerdb::FileHeader::first_used_page
PageId first_used_page
Definition:
file.h:33
badgerdb::File::allocatePage
Page allocatePage()
Definition:
file.cpp:84
badgerdb::File::operator=
File & operator=(const File &rhs)
Definition:
file.cpp:71
badgerdb::File::exists
static bool exists(const std::string &filename)
Definition:
file.cpp:54
badgerdb::File::deletePage
void deletePage(const PageId page_number)
Definition:
file.cpp:184
Generated on Fri Feb 10 2017 12:39:55 for BadgerDB by
1.8.6