Public Member Functions | |
PageFile (const std::string &name, const bool create_new) | |
PageFile (const PageFile &other) | |
PageFile & | operator= (const PageFile &rhs) |
~PageFile () | |
Page | allocatePage (PageId &new_page_number) |
Page | readPage (const PageId page_number) const |
void | writePage (const PageId page_number, const Page &new_page) |
void | deletePage (const PageId page_number) |
FileIterator | begin () |
FileIterator | end () |
const std::string & | filename () const |
PageId | getFirstPageNo () |
Static Public Member Functions | |
static PageFile | create (const std::string &filename) |
static PageFile | open (const std::string &filename) |
static void | remove (const std::string &filename) |
static bool | isOpen (const std::string &filename) |
static bool | exists (const std::string &filename) |
Protected Types | |
typedef std::map< std::string, std::shared_ptr< std::fstream > > | StreamMap |
typedef std::map< std::string, int > | CountMap |
Protected Member Functions | |
void | openIfNeeded (const bool create_new) |
void | close () |
FileHeader | readHeader () const |
void | writeHeader (const FileHeader &header) |
Static Protected Member Functions | |
static std::streampos | pagePosition (const PageId page_number) |
Protected Attributes | |
std::string | filename_ |
std::shared_ptr< std::fstream > | stream_ |
Static Protected Attributes | |
static StreamMap | open_streams_ |
static CountMap | open_counts_ |
Friends | |
class | FileIterator |
badgerdb::PageFile::PageFile | ( | const std::string & | name, |
const bool | create_new | ||
) |
Constructs a file object representing a file on the filesystem.
name | Name of file. |
create_new | Whether to create a new file. |
FileExistsException | If the underlying file exists and create_new is true. |
FileNotFoundException | If the underlying file doesn't exist and create_new is false. |
Definition at line 143 of file file.cpp.
badgerdb::PageFile::PageFile | ( | const PageFile & | other | ) |
badgerdb::PageFile::~PageFile | ( | ) |
Allocates a new page in the file.
Implements badgerdb::File.
Definition at line 165 of file file.cpp.
FileIterator badgerdb::PageFile::begin | ( | ) |
|
protectedinherited |
|
static |
Creates a new file.
filename | Name of the file. |
FileExistsException | If the requested file already exists. |
Definition at line 135 of file file.cpp.
|
virtual |
Deletes a page from the file.
page_number | Number of page to delete. |
Implements badgerdb::File.
Definition at line 276 of file file.cpp.
FileIterator badgerdb::PageFile::end | ( | ) |
|
staticinherited |
|
inlineinherited |
|
inherited |
|
staticinherited |
|
static |
Opens the file named fileName and returns the corresponding File object. It first checks if the file is already open. If so, then the new File object created uses the same input-output stream to read to or write fom that already open file. Reference count (open_counts_ static variable inside the File object) is incremented whenever an already open file is opened again. Otherwise the UNIX file is actually opened. The fileName and the stream associated with this File object are inserted into the open_streams_ map.
filename | Name of the file. |
FileNotFoundException | If the requested file doesn't exist. |
Definition at line 139 of file file.cpp.
|
protectedinherited |
Opens the underlying file named in filename_. This method only opens the file if no other File objects exist that access the same filesystem file; otherwise, it reuses the existing stream.
create_new | Whether to create a new file. |
FileExistsException | If the underlying file exists and create_new is true. |
FileNotFoundException | If the underlying file doesn't exist and create_new is false. |
Definition at line 78 of file file.cpp.
|
inlinestaticprotectedinherited |
|
protectedinherited |
Reads an existing page from the file.
page_number | Number of page to read. |
InvalidPageException | If the page doesn't exist in the file or is not currently used. |
Implements badgerdb::File.
Definition at line 238 of file file.cpp.
|
staticinherited |
Deletes an existing file.
filename | Name of the file. |
FileNotFoundException | If the file doesn't exist. |
FileOpenException | If the file is currently open. |
Definition at line 29 of file file.cpp.
|
protectedinherited |
Writes a page into the file at the given page number. No bounds checking is performed.
page_number | Number of page whose contents to replace. |
new_page | Page to write. |
Implements badgerdb::File.
Definition at line 260 of file file.cpp.
|
protectedinherited |
|
staticprotectedinherited |
|
staticprotectedinherited |
|
protectedinherited |