#include <DBFile.h>
This abstraction allows the user to treat a database as a collection of pages.
Public Member Functions | |
| DBFile (string name, int numPages) | |
| Creates a database with the specified number of pages. | |
| DBFile (string name) | |
| Opens the database with the given name. | |
| int | allocatePages (int runSize) |
| Allocates a set of pages. | |
| void | deallocatePages (int startPageNum, int runSize) |
| Deallocates a set of pages. | |
| void | readPage (int pageNum, Page *page) |
| Reads the contents of the specified page from disk into the page object provided. | |
| void | writePage (int pageNum, const Page *page) |
| Writes the contents of the specified page to disk. | |
Static Public Member Functions | |
| static bool | erase (string name) |
| Erases the database entirely from the filesystem. | |
| DBFile::DBFile | ( | string | name, | |
| int | numPages | |||
| ) |
Creates a database with the specified number of pages.
The number of pages in the database can never be increased.
| name | name to be given to database. | |
| numPages | maximum number of pages in database. |
| IOException | if problem with file system. |
| DBFile::DBFile | ( | string | name | ) |
Opens the database with the given name.
| name | name of the database. |
| IOException | if problem with file system. |
| int DBFile::allocatePages | ( | int | runSize | ) |
Allocates a set of pages.
| runSize | number of pages to be allocated in the run. |
| NonPositiveRunSizeException | if the run size is less than or equal to zero. | |
| FileFullException | if there are not enough free pages. |
| void DBFile::deallocatePages | ( | int | startPageNum, | |
| int | runSize | |||
| ) |
Deallocates a set of pages.
Does not ensure that the pages being deallocated are in fact allocated to begin with. If the pages were already deallocated, they remain so.
| startPageNum | page number at the beginning of the run to be deallocated. | |
| runSize | number of pages to deallocate. |
| NonPositiveRunSizeException | if the run size is less than or equal to zero. | |
| BadPageNumberException | if startPageNum is illegal. |
| static bool DBFile::erase | ( | string | name | ) | [static] |
Erases the database entirely from the filesystem.
Dangerous to do if still have a DBFile object that refers to this file.
| name | name of the database. |
| void DBFile::readPage | ( | int | pageNum, | |
| Page * | page | |||
| ) |
Reads the contents of the specified page from disk into the page object provided.
| pageNum | the page number to be read. | |
| page | a pointer to an already allocated Page object. |
| BadPageNumberException | if pageNum is not in the file. |
| void DBFile::writePage | ( | int | pageNum, | |
| const Page * | page | |||
| ) |
Writes the contents of the specified page to disk.
| pageNum | the page number to be written. | |
| page | a pointer to a Page object with data to be written. |
| EmptyFileException() | if the file has no pages within it. | |
| BadPageNumberException | if pageNum is not in the file. |
1.4.7