wisc_db
Public Member Functions | Static Public Member Functions | Friends | List of all members
wiscdb::File Class Reference

Represents a file in the filesystem containing pages. More...

#include <file.h>

Public Member Functions

 File (const File &other)
 
Fileoperator= (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
 

Detailed Description

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.

Warning
This class is not threadsafe.

Definition at line 71 of file file.h.

Constructor & Destructor Documentation

wiscdb::File::File ( const File other)

Copy constructor.

Parameters
otherFile object to copy.
Returns
A copy of the File object.
wiscdb::File::~File ( )

Destructor; automatically closes the underlying file if no other File objects are using it.

Member Function Documentation

Page wiscdb::File::allocatePage ( )

Allocates a new page in the file.

Returns
The new page.
FileIterator wiscdb::File::begin ( )

Returns an iterator at the first page in the file.

Returns
Iterator at first page of 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.

Parameters
filenameName of the file.
Exceptions
FileExistsExceptionIf the requested file already exists.
void wiscdb::File::deletePage ( const PageId  page_number)

Deletes a page from the file.

Parameters
page_numberNumber of page to delete.
FileIterator wiscdb::File::end ( )

Returns an iterator representing the page after the last page in the file. This iterator should not be dereferenced.

Returns
Iterator representing page after the last page in the file.
static bool wiscdb::File::exists ( const std::string &  filename)
static

Returns true if the file exists.

Parameters
filenameName of the file.
const std::string& wiscdb::File::filename ( ) const
inline

Returns the name of the file this object represents.

Returns
Name of file.

Definition at line 180 of file file.h.

180 { return filename_; }
static bool wiscdb::File::isOpen ( const std::string &  filename)
static

Returns true if the file exists and is open.

Parameters
filenameName 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.

Parameters
filenameName of the file.
Exceptions
FileNotFoundExceptionIf the requested file doesn't exist.
File& wiscdb::File::operator= ( const File rhs)

Assignment operator.

Parameters
rhsFile object to assign.
Returns
Newly assigned file object.
Page wiscdb::File::readPage ( const PageId  page_number) const

Reads an existing page from the file.

Parameters
page_numberNumber of page to read.
Returns
The page.
Exceptions
InvalidPageExceptionIf 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.

Parameters
filenameName of the file.
Exceptions
FileNotFoundExceptionIf the file doesn't exist.
FileOpenExceptionIf 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().

See also
allocatePage()
Parameters
new_pagePage to write.

The documentation for this class was generated from the following file: