Represents a file in the filesystem containing pages. More...
#include <file.h>
Public Member Functions | |
File (const File &other) | |
File & | operator= (const File &rhs) |
~File () | |
Page | allocatePage () |
Page | readPage (const PageId page_number) const |
void | writePage (const Page &new_page) |
void | deletePage (const PageId page_number) |
const std::string & | filename () const |
FileIterator | begin () |
FileIterator | end () |
void | close () |
Static Public Member Functions | |
static File | create (const std::string &filename) |
static File | 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) |
Friends | |
class | FileIterator |
class | FileTest |
Represents a file in the filesystem containing pages.
The File class wraps a stream to an underlying file on disk. Files contain fixed-sized pages, and they never deallocate space (though they do reuse deleted pages if possible). If multiple File objects refer to the same underlying file, they will share the stream in memory. If a file has already been opened (possibly by another query), then the File class detects this (by looking in the open_streams_ map) and returns a File object with the already created stream for the file without actually opening the UNIX file again.
wiscdb::File::File | ( | const File & | other | ) |
Destructor; automatically closes the underlying file if no other File objects are using it.
Allocates a new page in the file.
Returns an iterator at the first page in the file.
void wiscdb::File::close | ( | ) |
Closes the underlying file stream in <stream_>. This method only closes the file if no other File objects exist that access the same file.
static File wiscdb::File::create | ( | const std::string & | filename | ) | [static] |
Creates a new file.
filename | Name of the file. |
FileExistsException | If the requested file already exists. |
void wiscdb::File::deletePage | ( | const PageId | page_number | ) |
Deletes a page from the file.
page_number | Number of page to delete. |
Returns an iterator representing the page after the last page in the file. This iterator should not be dereferenced.
static bool wiscdb::File::exists | ( | const std::string & | filename | ) | [static] |
Returns true if the file exists.
filename | Name of the file. |
const std::string& wiscdb::File::filename | ( | ) | const [inline] |
static bool wiscdb::File::isOpen | ( | const std::string & | filename | ) | [static] |
Returns true if the file exists and is open.
filename | Name of the file. |
static File wiscdb::File::open | ( | const std::string & | filename | ) | [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 from the 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. |
Page wiscdb::File::readPage | ( | const PageId | page_number | ) | const |
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. |
static void wiscdb::File::remove | ( | const std::string & | filename | ) | [static] |
Deletes an existing file.
filename | Name of the file. |
FileNotFoundException | If the file doesn't exist. |
FileOpenException | If the file is currently open. |
void wiscdb::File::writePage | ( | const Page & | new_page | ) |
Writes a page into the file, replacing any existing contents. The page must have been already allocated in this file by a call to allocatePage().
new_page | Page to write. |