BucketFile.h
Classes
- BucketFile -- File object for the bucket cache. (full description)
Interface
- Public Members
- explicit BucketFile (const String& fileName)
- BucketFile (const String& fileName, Bool writable)
- ~BucketFile()
- void open()
- void close()
- void remove()
- void fsync()
- void setRW()
- const String& name() const
- Bool isWritable() const
- uInt read (void* buffer, uInt length) const
- uInt write (const void* buffer, uInt length)
- void seek (Int64 offset) const
- void seek (Int offset) const
- Int64 fileSize() const
- int fd()
- Private Members
- BucketFile (const BucketFile&)
- BucketFile& operator= (const BucketFile&)
Etymology
BucketFile represents a data file for the BucketCache class.
Synopsis
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.
Motivation
Encapsulate the file creation and access into a single class
to hide the file IO details.
Example
// 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();
To Do
- Use the ByteIO classes when they are ready.
Member Description
explicit BucketFile (const String& fileName)
Create a BucketFile object for a new file.
The file with the given name will be created.
BucketFile (const String& fileName, Bool writable)
Create a BucketFile object for an existing file.
The file should be opened by the open.
Tell if the file must later be opened writable.
The destructor closes the file (if open).
Open the file if not open yet.
Close the file (if open).
Remove the file (and close it if needed).
Fsync the file (i.e. force the data to be physically written).
Set the file to read/write access.
It does nothing if the file is already writable.
Get the file name.
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
void seek (Int offset) const
Seek in the file.
Get the (physical) size of the file.
This is doing a seek and sets the file pointer to end-of-file.
int fd()
Get the file descriptor of the internal file.
Forbid copy constructor.
BucketFile& operator= (const BucketFile&)
Forbid assignment.