casa
$Rev:20696$
|
File object for the bucket cache. More...
#include <BucketFile.h>
Public Member Functions | |
BucketFile (const String &fileName, uInt bufSizeFile=0, Bool mappedFile=False) | |
Create a BucketFile object for a new file. | |
BucketFile (const String &fileName, Bool writable, uInt bufSizeFile=0, Bool mappedFile=False) | |
Create a BucketFile object for an existing file. | |
~BucketFile () | |
The destructor closes the file (if open). | |
MMapfdIO * | mappedFile () |
Get the mapped file object. | |
LargeFilebufIO * | bufferedFile () |
Get the buffered file object. | |
void | open () |
Open the file if not open yet. | |
void | close () |
Close the file (if open). | |
void | remove () |
Remove the file (and close it if needed). | |
void | fsync () |
Fsync the file (i.e. | |
void | setRW () |
Set the file to read/write access. | |
const String & | name () const |
Get the file name. | |
Bool | isWritable () const |
Has the file logically been indicated as writable? | |
uInt | read (void *buffer, uInt length) const |
Read bytes from the file. | |
uInt | write (const void *buffer, uInt length) |
Write bytes into the file. | |
void | seek (Int64 offset) const |
Seek in the file. | |
void | seek (Int offset) const |
Int64 | fileSize () const |
Get the (physical) size of the file. | |
int | fd () |
Get the file descriptor of the internal file. | |
Bool | isCached () const |
Is the file cached, mapped, or buffered? | |
Bool | isMapped () const |
Bool | isBuffered () const |
Private Member Functions | |
BucketFile (const BucketFile &) | |
Forbid copy constructor. | |
BucketFile & | operator= (const BucketFile &) |
Forbid assignment. | |
void | createMapBuf () |
Create the mapped or buffered file object. | |
void | deleteMapBuf () |
Delete the possible mapped or buffered file object. | |
Private Attributes | |
String | name_p |
Bool | isWritable_p |
The (logical) writability of the file. | |
Bool | isMapped_p |
uInt | bufSize_p |
int | fd_p |
The file descriptor. | |
MMapfdIO * | mappedFile_p |
The optional mapped file. | |
LargeFilebufIO * | bufferedFile_p |
The optional buffered file. |
File object for the bucket cache.
Internal
BucketFile represents a data file for the BucketCache class.
A BucketFile object represents a data file. Currently it is used by the Table system, but it can easily be turned into a more general storage manager file class.
Creation of a BucketFile object does not open the file yet. An explicit open call has to be given before the file can be used.
Underneath it uses a file descriptor to access the file. It is straightforward to replace this by a mapped file or a filebuf.
Encapsulate the file creation and access into a single class to hide the file IO details.
// Create the file for the given storage manager. BucketFile file ("file.name"); // Open the file and write into it. file.open(); file.write (someBuffer, someLength); // Get the length of the file. uInt size = file.fileSize();
Definition at line 97 of file BucketFile.h.
casa::BucketFile::BucketFile | ( | const String & | fileName, |
uInt | bufSizeFile = 0 , |
||
Bool | mappedFile = False |
||
) | [explicit] |
Create a BucketFile object for a new file.
The file with the given name will be created. It can be indicated if a MMapfdIO and/or LargeFilebufIO object must be created for the file.
casa::BucketFile::BucketFile | ( | const String & | fileName, |
Bool | writable, | ||
uInt | bufSizeFile = 0 , |
||
Bool | mappedFile = False |
||
) |
Create a BucketFile object for an existing file.
The file should be opened by the open
. Tell if the file must be opened writable. It can be indicated if a MMapfdIO and/or LargeFilebufIO object must be created for the file.
The destructor closes the file (if open).
casa::BucketFile::BucketFile | ( | const BucketFile & | ) | [private] |
Forbid copy constructor.
LargeFilebufIO* casa::BucketFile::bufferedFile | ( | ) | [inline] |
Get the buffered file object.
Definition at line 123 of file BucketFile.h.
References bufferedFile_p.
void casa::BucketFile::close | ( | ) |
Close the file (if open).
void casa::BucketFile::createMapBuf | ( | ) | [private] |
Create the mapped or buffered file object.
void casa::BucketFile::deleteMapBuf | ( | ) | [private] |
Delete the possible mapped or buffered file object.
int casa::BucketFile::fd | ( | ) | [inline] |
Get the file descriptor of the internal file.
Definition at line 209 of file BucketFile.h.
References fd_p.
Int64 casa::BucketFile::fileSize | ( | ) | const |
Get the (physical) size of the file.
This is doing a seek and sets the file pointer to end-of-file.
void casa::BucketFile::fsync | ( | ) |
Fsync the file (i.e.
force the data to be physically written).
Bool casa::BucketFile::isBuffered | ( | ) | const [inline] |
Definition at line 219 of file BucketFile.h.
References bufSize_p.
Bool casa::BucketFile::isCached | ( | ) | const [inline] |
Is the file cached, mapped, or buffered?
Definition at line 215 of file BucketFile.h.
References bufSize_p, and isMapped_p.
Bool casa::BucketFile::isMapped | ( | ) | const [inline] |
Definition at line 217 of file BucketFile.h.
References isMapped_p.
Bool casa::BucketFile::isWritable | ( | ) | const [inline] |
Has the file logically been indicated as writable?
Definition at line 206 of file BucketFile.h.
References isWritable_p.
MMapfdIO* casa::BucketFile::mappedFile | ( | ) | [inline] |
const String & casa::BucketFile::name | ( | ) | const [inline] |
void casa::BucketFile::open | ( | ) |
Open the file if not open yet.
Referenced by casa::TSMFile::open().
BucketFile& casa::BucketFile::operator= | ( | const BucketFile & | ) | [private] |
Forbid assignment.
uInt casa::BucketFile::read | ( | void * | buffer, |
uInt | length | ||
) | const |
Read bytes from the file.
void casa::BucketFile::remove | ( | ) |
Remove the file (and close it if needed).
void casa::BucketFile::seek | ( | Int64 | offset | ) | const |
Seek in the file.
Referenced by seek().
void casa::BucketFile::seek | ( | Int | offset | ) | const [inline] |
Definition at line 212 of file BucketFile.h.
References seek().
void casa::BucketFile::setRW | ( | ) |
Set the file to read/write access.
It is reopened if not writable. It does nothing if the file is already writable.
uInt casa::BucketFile::write | ( | const void * | buffer, |
uInt | length | ||
) |
Write bytes into the file.
LargeFilebufIO* casa::BucketFile::bufferedFile_p [private] |
The optional buffered file.
Definition at line 186 of file BucketFile.h.
Referenced by bufferedFile().
uInt casa::BucketFile::bufSize_p [private] |
Definition at line 180 of file BucketFile.h.
Referenced by isBuffered(), and isCached().
int casa::BucketFile::fd_p [private] |
Bool casa::BucketFile::isMapped_p [private] |
Definition at line 179 of file BucketFile.h.
Referenced by isCached(), and isMapped().
Bool casa::BucketFile::isWritable_p [private] |
The (logical) writability of the file.
Definition at line 178 of file BucketFile.h.
Referenced by isWritable().
MMapfdIO* casa::BucketFile::mappedFile_p [private] |
String casa::BucketFile::name_p [private] |