List of all members.
Detailed Description
Definition at line 385 of file file.h.
Constructor & Destructor Documentation
Constructs a file object representing a file on the filesystem.
- See also:
- File::create()
-
File::open()
- Parameters:
-
name | Name of file. |
create_new | Whether to create a new file. |
- Exceptions:
-
Definition at line 343 of file file.cpp.
: File(name, create_new) {
}
Copy constructor.
- Parameters:
-
other | File object to copy. |
- Returns:
- A copy of the File object.
Definition at line 350 of file file.cpp.
: File(other.filename_, false )
{
}
Destructor that automatically closes the underlying file if no other File objects are using it.
Definition at line 347 of file file.cpp.
Member Function Documentation
Allocates a new page in the file.
- Returns:
- The new page.
Implements badgerdb::File.
Definition at line 364 of file file.cpp.
{
FileHeader header = readHeader();
Page new_page;
new_page_number = header.num_pages;
if (header.first_used_page == Page::INVALID_NUMBER) {
header.first_used_page = header.num_pages;
}
++header.num_pages;
writePage(new_page_number, new_page);
writeHeader(header);
return new_page;
}
Closes the underlying file stream in <stream_>. This method only closes the file if no other File objects exist that access the same file.
Definition at line 105 of file file.cpp.
Creates a new BlobFile.
- Parameters:
-
filename | Name of the file. |
- Exceptions:
-
Definition at line 335 of file file.cpp.
Deletes a page from the file.
- Parameters:
-
page_number | Number of page to delete. |
Implements badgerdb::File.
Definition at line 396 of file file.cpp.
{
throw InvalidPageException(page_number, filename_);
}
Returns true if the file exists and is open.
- Parameters:
-
filename | Name of the file. |
Definition at line 46 of file file.cpp.
{
std::fstream file(filename);
if(file)
{
file.close();
return true;
}
return false;
}
Returns the name of the file this object represents.
- Returns:
- Name of file.
Definition at line 158 of file file.h.
Returns pageid of first page in the file.
- Returns:
- Iterator at first page of file.
Definition at line 62 of file file.cpp.
{
const FileHeader& header = readHeader();
return header.first_used_page;
}
Returns true if the file exists and is open.
- Parameters:
-
filename | Name of the file. |
Definition at line 39 of file file.cpp.
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.
- Parameters:
-
filename | Name of the file. |
- Exceptions:
-
Definition at line 339 of file file.cpp.
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.
- Parameters:
-
create_new | Whether to create a new file. |
- Exceptions:
-
Definition at line 78 of file file.cpp.
Assignment operator.
- Parameters:
-
rhs | File object to assign. |
- Returns:
- Newly assigned file object.
Definition at line 355 of file file.cpp.
Returns the position of the page with the given number in the file (as an offset from the beginning of the file).
- Parameters:
-
page_number | Number of page. |
- Returns:
- Position of page in file.
Definition at line 175 of file file.h.
{
return sizeof(FileHeader) + ((page_number - 1) * Page::SIZE);
}
Reads the header for this file from disk.
- Returns:
- The file header.
Definition at line 118 of file file.cpp.
{
FileHeader header;
stream_->seekg(0 , std::ios::beg);
stream_->read(reinterpret_cast<char*>(&header), sizeof(FileHeader));
return header;
}
Reads an existing page from the file.
- Parameters:
-
page_number | Number of page to read. |
- Returns:
- The page.
- Exceptions:
-
Implements badgerdb::File.
Definition at line 382 of file file.cpp.
Deletes an existing file.
- Parameters:
-
filename | Name of the file. |
- Exceptions:
-
Definition at line 29 of file file.cpp.
Writes the given header to the disk as the header for this file.
- Parameters:
-
header | File header to write. |
Definition at line 125 of file file.cpp.
{
stream_->seekp(0 , std::ios::beg);
stream_->write(reinterpret_cast<const char*>(&header), sizeof(FileHeader));
stream_->flush();
}
Writes a page into the file at the given page number. No bounds checking is performed.
- Parameters:
-
page_number | Number of page whose contents to replace. |
new_page | Page to write. |
Implements badgerdb::File.
Definition at line 389 of file file.cpp.
Member Data Documentation
Name of the file this object represents.
Definition at line 229 of file file.h.
Counts for opened files.
Definition at line 224 of file file.h.
Streams for opened files.
Definition at line 219 of file file.h.
Stream for underlying filesystem object.
Definition at line 234 of file file.h.
The documentation for this class was generated from the following files:
- /afs/cs.wisc.edu/u/m/o/mohan/private/cs564/btree/btree/src/file.h
- /afs/cs.wisc.edu/u/m/o/mohan/private/cs564/btree/btree/src/file.cpp