|
typedef std::map< std::string,
std::shared_ptr< std::fstream > > | StreamMap |
|
typedef std::map< std::string,
int > | CountMap |
|
Definition at line 385 of file file.h.
badgerdb::BlobFile::BlobFile |
( |
const std::string & |
name, |
|
|
const bool |
create_new |
|
) |
| |
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.
344 :
File(name, create_new) {
File(const std::string &name, const bool create_new)
badgerdb::BlobFile::BlobFile |
( |
const BlobFile & |
other | ) |
|
Copy constructor.
- Parameters
-
other | File object to copy. |
- Returns
- A copy of the File object.
Definition at line 350 of file file.cpp.
351 :
File(other.filename_,
false )
File(const std::string &name, const bool create_new)
badgerdb::BlobFile::~BlobFile |
( |
| ) |
|
Destructor that automatically closes the underlying file if no other File objects are using it.
Definition at line 347 of file file.cpp.
Page badgerdb::BlobFile::allocatePage |
( |
PageId & |
new_page_number | ) |
|
|
virtual |
Allocates a new page in the file.
- Returns
- The new page.
Implements badgerdb::File.
Definition at line 364 of file file.cpp.
368 new_page_number = header.num_pages;
371 header.first_used_page = header.num_pages;
376 new_page.set_page_number(new_page_number);
void writePage(const PageId page_number, const Page &new_page)
void writeHeader(const FileHeader &header)
static const PageId INVALID_NUMBER
FileHeader readHeader() const
void badgerdb::File::close |
( |
| ) |
|
|
protectedinherited |
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.
static CountMap open_counts_
std::shared_ptr< std::fstream > stream_
static StreamMap open_streams_
BlobFile badgerdb::BlobFile::create |
( |
const std::string & |
filename | ) |
|
|
static |
Creates a new BlobFile.
- Parameters
-
filename | Name of the file. |
- Exceptions
-
Definition at line 335 of file file.cpp.
const std::string & filename() const
BlobFile(const std::string &name, const bool create_new)
void badgerdb::BlobFile::deletePage |
( |
const PageId |
page_number | ) |
|
|
virtual |
Deletes a page from the file.
- Parameters
-
page_number | Number of page to delete. |
Implements badgerdb::File.
Definition at line 397 of file file.cpp.
398 throw InvalidPageException(page_number,
filename_);
bool badgerdb::File::exists |
( |
const std::string & |
filename | ) |
|
|
staticinherited |
Returns true if the file exists and is open.
- Parameters
-
filename | Name of the file. |
Definition at line 46 of file file.cpp.
const std::string & filename() const
const std::string& badgerdb::File::filename |
( |
| ) |
const |
|
inlineinherited |
Returns the name of the file this object represents.
- Returns
- Name of file.
Definition at line 158 of file file.h.
PageId badgerdb::File::getFirstPageNo |
( |
| ) |
|
|
inherited |
Returns pageid of first page in the file.
- Returns
- Iterator at first page of file.
Definition at line 62 of file file.cpp.
64 return header.first_used_page;
FileHeader readHeader() const
bool badgerdb::File::isOpen |
( |
const std::string & |
filename | ) |
|
|
staticinherited |
Returns true if the file exists and is open.
- Parameters
-
filename | Name of the file. |
Definition at line 39 of file file.cpp.
static CountMap open_counts_
const std::string & filename() const
static bool exists(const std::string &filename)
BlobFile badgerdb::BlobFile::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 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.
const std::string & filename() const
BlobFile(const std::string &name, const bool create_new)
void badgerdb::File::openIfNeeded |
( |
const bool |
create_new | ) |
|
|
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.
- Parameters
-
create_new | Whether to create a new file. |
- Exceptions
-
Definition at line 78 of file file.cpp.
83 std::ios_base::openmode mode =
84 std::fstream::in | std::fstream::out | std::fstream::binary;
92 mode = mode | std::fstream::trunc;
95 if (!already_exists) {
static CountMap open_counts_
std::shared_ptr< std::fstream > stream_
static StreamMap open_streams_
static bool exists(const std::string &filename)
Assignment operator.
- Parameters
-
rhs | File object to assign. |
- Returns
- Newly assigned file object.
Definition at line 355 of file file.cpp.
void openIfNeeded(const bool create_new)
static std::streampos badgerdb::File::pagePosition |
( |
const PageId |
page_number | ) |
|
|
inlinestaticprotectedinherited |
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.
176 return sizeof(FileHeader) + ((page_number - 1) *
Page::SIZE);
static const std::size_t SIZE
Reads the header for this file from disk.
- Returns
- The file header.
Definition at line 118 of file file.cpp.
120 stream_->seekg(0 , std::ios::beg);
121 stream_->read(reinterpret_cast<char*>(&header),
sizeof(FileHeader));
std::shared_ptr< std::fstream > stream_
Page badgerdb::BlobFile::readPage |
( |
const PageId |
page_number | ) |
const |
|
virtual |
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 383 of file file.cpp.
static std::streampos pagePosition(const PageId page_number)
std::shared_ptr< std::fstream > stream_
static const std::size_t SIZE
void badgerdb::File::remove |
( |
const std::string & |
filename | ) |
|
|
staticinherited |
Deletes an existing file.
- Parameters
-
filename | Name of the file. |
- Exceptions
-
Definition at line 29 of file file.cpp.
31 throw FileNotFoundException(
filename);
static bool isOpen(const std::string &filename)
const std::string & filename() const
static bool exists(const std::string &filename)
void badgerdb::File::writeHeader |
( |
const FileHeader & |
header | ) |
|
|
protectedinherited |
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.
126 stream_->seekp(0 , std::ios::beg);
127 stream_->write(reinterpret_cast<const char*>(&header),
sizeof(FileHeader));
std::shared_ptr< std::fstream > stream_
void badgerdb::BlobFile::writePage |
( |
const PageId |
page_number, |
|
|
const Page & |
new_page |
|
) |
| |
|
virtual |
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 390 of file file.cpp.
static std::streampos pagePosition(const PageId page_number)
std::shared_ptr< std::fstream > stream_
static const std::size_t SIZE
std::string badgerdb::File::filename_ |
|
protectedinherited |
Name of the file this object represents.
Definition at line 229 of file file.h.
File::CountMap badgerdb::File::open_counts_ |
|
staticprotectedinherited |
Counts for opened files.
Definition at line 224 of file file.h.
File::StreamMap badgerdb::File::open_streams_ |
|
staticprotectedinherited |
Streams for opened files.
Definition at line 219 of file file.h.
std::shared_ptr<std::fstream> badgerdb::File::stream_ |
|
protectedinherited |
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/h/a/haiyun/private/cs564-spr17/projects/p3/Btree/src/file.h
- /afs/cs.wisc.edu/u/h/a/haiyun/private/cs564-spr17/projects/p3/Btree/src/file.cpp