casacore
Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::BucketFile Class Reference

More...

#include <BucketFile.h>

Public Member Functions

 BucketFile (const String &fileName, uInt bufSizeFile=0, Bool mappedFile=False, MultiFileBase *mfile=0)
 Create a BucketFile object for a new file. More...
 
 BucketFile (const String &fileName, Bool writable, uInt bufSizeFile=0, Bool mappedFile=False, MultiFileBase *mfile=0)
 Create a BucketFile object for an existing file. More...
 
virtual ~BucketFile ()
 The destructor closes the file (if open). More...
 
virtual CountedPtr< ByteIOmakeFilebufIO (uInt bufferSize)
 Make a (temporary) buffered IO object for this file. More...
 
MMapfdIOmappedFile ()
 Get the mapped file object. More...
 
FilebufIObufferedFile ()
 Get the buffered file object. More...
 
virtual void open ()
 Open the file if not open yet. More...
 
virtual void close ()
 Close the file (if open). More...
 
virtual void remove ()
 Remove the file (and close it if needed). More...
 
virtual void fsync ()
 Fsync the file (i.e. More...
 
virtual void setRW ()
 Set the file to read/write access. More...
 
virtual const Stringname () const
 Get the file name. More...
 
Bool isWritable () const
 Has the file logically been indicated as writable? More...
 
virtual uInt read (void *buffer, uInt length)
 Read bytes from the file. More...
 
virtual uInt write (const void *buffer, uInt length)
 Write bytes into the file. More...
 
virtual void seek (Int64 offset)
 Seek in the file. More...
 
void seek (Int offset)
 
virtual Int64 fileSize () const
 Get the (physical) size of the file. More...
 
Bool isCached () const
 Is the file cached, mapped, or buffered? More...
 
Bool isMapped () const
 
Bool isBuffered () const
 

Private Member Functions

 BucketFile (const BucketFile &)
 Forbid copy constructor. More...
 
BucketFileoperator= (const BucketFile &)
 Forbid assignment. More...
 
void createMapBuf ()
 Create the mapped or buffered file object. More...
 
void deleteMapBuf ()
 Delete the possible mapped or buffered file object. More...
 

Private Attributes

String name_p
 The file name. More...
 
Bool isWritable_p
 The (logical) writability of the file. More...
 
Bool isMapped_p
 
uInt bufSize_p
 
int fd_p
 
CountedPtr< ByteIOfile_p
 The unbuffered file. More...
 
MMapfdIOmappedFile_p
 The optional mapped file. More...
 
FilebufIObufferedFile_p
 The optional buffered file. More...
 
MultiFileBasemfile_p
 The possibly used MultiFileBase. More...
 

Detailed Description

File object for BucketCache.

Intended use:

Internal

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

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.

The file can be opened as an ordinary file (with a file descriptor) or as a file in a MultiFileBase object. An ordinary file can be accessed in 3 ways:

A MultiFileBase file can only be accessed in the unbuffered way.

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();
BucketFile(const String &fileName, uInt bufSizeFile=0, Bool mappedFile=False, MultiFileBase *mfile=0)
Create a BucketFile object for a new file.
unsigned int uInt
Definition: aipstype.h:51

To Do

Definition at line 107 of file BucketFile.h.

Constructor & Destructor Documentation

◆ BucketFile() [1/3]

casacore::BucketFile::BucketFile ( const String fileName,
uInt  bufSizeFile = 0,
Bool  mappedFile = False,
MultiFileBase mfile = 0 
)
explicit

Create a BucketFile object for a new file.

The file with the given name will be created as a normal file or as part of a MultiFileBase (if mfile != 0). It can be indicated if a MMapfdIO and/or FilebufIO object must be created for the file. If a MultiFileBase is used, memory-mapped IO cannot be used and mappedFile is ignored.

◆ BucketFile() [2/3]

casacore::BucketFile::BucketFile ( const String fileName,
Bool  writable,
uInt  bufSizeFile = 0,
Bool  mappedFile = False,
MultiFileBase mfile = 0 
)

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 FilebufIO object must be created for the file. If a MultiFileBase is used, memory-mapped IO cannot be used and mappedFile is ignored.

◆ ~BucketFile()

virtual casacore::BucketFile::~BucketFile ( )
virtual

The destructor closes the file (if open).

◆ BucketFile() [3/3]

casacore::BucketFile::BucketFile ( const BucketFile )
private

Forbid copy constructor.

Member Function Documentation

◆ bufferedFile()

FilebufIO* casacore::BucketFile::bufferedFile ( )
inline

Get the buffered file object.

Definition at line 142 of file BucketFile.h.

References bufferedFile_p.

◆ close()

virtual void casacore::BucketFile::close ( )
virtual

Close the file (if open).

◆ createMapBuf()

void casacore::BucketFile::createMapBuf ( )
private

Create the mapped or buffered file object.

◆ deleteMapBuf()

void casacore::BucketFile::deleteMapBuf ( )
private

Delete the possible mapped or buffered file object.

◆ fileSize()

virtual Int64 casacore::BucketFile::fileSize ( ) const
virtual

Get the (physical) size of the file.

This is doing a seek and sets the file pointer to end-of-file.

◆ fsync()

virtual void casacore::BucketFile::fsync ( )
virtual

Fsync the file (i.e.

force the data to be physically written).

◆ isBuffered()

Bool casacore::BucketFile::isBuffered ( ) const
inline

Definition at line 235 of file BucketFile.h.

References bufSize_p.

◆ isCached()

Bool casacore::BucketFile::isCached ( ) const
inline

Is the file cached, mapped, or buffered?

Definition at line 231 of file BucketFile.h.

References bufSize_p, and isMapped_p.

◆ isMapped()

Bool casacore::BucketFile::isMapped ( ) const
inline

Definition at line 233 of file BucketFile.h.

References isMapped_p.

◆ isWritable()

Bool casacore::BucketFile::isWritable ( ) const
inline

Has the file logically been indicated as writable?

Definition at line 225 of file BucketFile.h.

References isWritable_p.

◆ makeFilebufIO()

virtual CountedPtr<ByteIO> casacore::BucketFile::makeFilebufIO ( uInt  bufferSize)
virtual

Make a (temporary) buffered IO object for this file.

That object should not close the file.

◆ mappedFile()

MMapfdIO* casacore::BucketFile::mappedFile ( )
inline

Get the mapped file object.

Definition at line 138 of file BucketFile.h.

References mappedFile_p.

◆ name()

const String & casacore::BucketFile::name ( ) const
inlinevirtual

Get the file name.

Definition at line 222 of file BucketFile.h.

References name_p.

◆ open()

virtual void casacore::BucketFile::open ( )
virtual

Open the file if not open yet.

Referenced by casacore::TSMFile::open().

◆ operator=()

BucketFile& casacore::BucketFile::operator= ( const BucketFile )
private

Forbid assignment.

◆ read()

virtual uInt casacore::BucketFile::read ( void *  buffer,
uInt  length 
)
virtual

Read bytes from the file.

◆ remove()

virtual void casacore::BucketFile::remove ( )
virtual

Remove the file (and close it if needed).

◆ seek() [1/2]

void casacore::BucketFile::seek ( Int  offset)
inline

Definition at line 228 of file BucketFile.h.

References seek().

◆ seek() [2/2]

virtual void casacore::BucketFile::seek ( Int64  offset)
virtual

Seek in the file.

Referenced by seek().

◆ setRW()

virtual void casacore::BucketFile::setRW ( )
virtual

Set the file to read/write access.

It is reopened if not writable. It does nothing if the file is already writable.

◆ write()

virtual uInt casacore::BucketFile::write ( const void *  buffer,
uInt  length 
)
virtual

Write bytes into the file.

Member Data Documentation

◆ bufferedFile_p

FilebufIO* casacore::BucketFile::bufferedFile_p
private

The optional buffered file.

Definition at line 203 of file BucketFile.h.

Referenced by bufferedFile().

◆ bufSize_p

uInt casacore::BucketFile::bufSize_p
private

Definition at line 196 of file BucketFile.h.

Referenced by isBuffered(), and isCached().

◆ fd_p

int casacore::BucketFile::fd_p
private

Definition at line 197 of file BucketFile.h.

◆ file_p

CountedPtr<ByteIO> casacore::BucketFile::file_p
private

The unbuffered file.

Definition at line 199 of file BucketFile.h.

◆ isMapped_p

Bool casacore::BucketFile::isMapped_p
private

Definition at line 195 of file BucketFile.h.

Referenced by isCached(), and isMapped().

◆ isWritable_p

Bool casacore::BucketFile::isWritable_p
private

The (logical) writability of the file.

Definition at line 194 of file BucketFile.h.

Referenced by isWritable().

◆ mappedFile_p

MMapfdIO* casacore::BucketFile::mappedFile_p
private

The optional mapped file.

Definition at line 201 of file BucketFile.h.

Referenced by mappedFile().

◆ mfile_p

MultiFileBase* casacore::BucketFile::mfile_p
private

The possibly used MultiFileBase.

Definition at line 205 of file BucketFile.h.

◆ name_p

String casacore::BucketFile::name_p
private

The file name.

Definition at line 192 of file BucketFile.h.

Referenced by name().


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