Class for IO on a virtual file in a MultiFileBase. More...
#include <MFFileIO.h>
Public Member Functions | |
MFFileIO (MultiFileBase &, const String &name, ByteIO::OpenOption=ByteIO::Old) | |
Open or create a virtual file with the given name. | |
virtual | ~MFFileIO () |
The destructor flushes and closes the file. | |
virtual Int64 | read (Int64 size, void *buf, Bool throwException=True) |
Read size bytes from the byte stream. | |
virtual void | write (Int64 size, const void *buffer) |
Write a block at the given offset. | |
virtual void | reopenRW () |
Reopen the file (and possibly underlying MultiFileBase) for read/write access. | |
void | remove () |
Remove the file from the MultiFileBase object. | |
virtual void | flush () |
Flush the file by writing all dirty data and all header info. | |
virtual Int64 | length () |
Get the length of the file. | |
virtual Bool | isReadable () const |
The file is always readable. | |
virtual Bool | isWritable () const |
Is the file writable? | |
virtual Bool | isSeekable () const |
The file is always seekable. | |
virtual String | fileName () const |
Get the file name of the file attached. | |
virtual void | fsync () |
Fsync the file (i.e. | |
virtual Int64 | doSeek (Int64 offset, ByteIO::SeekOption) |
Reset the position pointer to the given value. | |
Private Attributes | |
MultiFileBase & | itsFile |
Int64 | itsPosition |
String | itsName |
Int | itsId |
Class for IO on a virtual file in a MultiFileBase.
Public interface
This class is a specialization of class ByteIO . It uses a MultiFileBase as the data store.
Similar to a regular file it is possible to read and write data and to seek in the file. The object keeps track of the current file offset.
// Create a new MultiFile using a block size of 1 MB. MultiFile mfile("file.mf', ByteIO::New, 1048576); // Create a virtual file in it. MFFileIO mf1(mfile, "mf1", ByteIO::New); // Use it (for example) as the sink of AipsIO. AipsIO stream (&mf1); // Write values. stream << (Int)10; stream << True; // Seek to beginning of file and read data in. stream.setpos (0); Int vali; Bool valb; stream >> vali >> valb;
Definition at line 77 of file MFFileIO.h.
casacore::MFFileIO::MFFileIO | ( | MultiFileBase & | , | |
const String & | name, | |||
ByteIO::OpenOption | = ByteIO::Old | |||
) |
Open or create a virtual file with the given name.
Note that only the basename of the file name is actually used. It is created in the given MultiFileBase.
virtual casacore::MFFileIO::~MFFileIO | ( | ) | [virtual] |
The destructor flushes and closes the file.
virtual Int64 casacore::MFFileIO::doSeek | ( | Int64 | offset, | |
ByteIO::SeekOption | ||||
) | [virtual] |
Reset the position pointer to the given value.
It returns the new position.
Implements casacore::ByteIO.
virtual String casacore::MFFileIO::fileName | ( | ) | const [virtual] |
Get the file name of the file attached.
Reimplemented from casacore::ByteIO.
virtual void casacore::MFFileIO::flush | ( | ) | [virtual] |
Flush the file by writing all dirty data and all header info.
Reimplemented from casacore::ByteIO.
virtual void casacore::MFFileIO::fsync | ( | ) | [virtual] |
virtual Bool casacore::MFFileIO::isReadable | ( | ) | const [virtual] |
The file is always readable.
Implements casacore::ByteIO.
virtual Bool casacore::MFFileIO::isSeekable | ( | ) | const [virtual] |
The file is always seekable.
Implements casacore::ByteIO.
virtual Bool casacore::MFFileIO::isWritable | ( | ) | const [virtual] |
Is the file writable?
Implements casacore::ByteIO.
virtual Int64 casacore::MFFileIO::length | ( | ) | [virtual] |
Get the length of the file.
Implements casacore::ByteIO.
virtual Int64 casacore::MFFileIO::read | ( | Int64 | size, | |
void * | buf, | |||
Bool | throwException = True | |||
) | [virtual] |
Read size
bytes from the byte stream.
Returns the number of bytes actually read, or a negative number if an error occurred. Will also throw an Exception (AipsError) if the requested number of bytes could not be read unless throwException is set to False.
Implements casacore::ByteIO.
void casacore::MFFileIO::remove | ( | ) |
Remove the file from the MultiFileBase object.
It makes the object invalid by setting the fileId to -1.
virtual void casacore::MFFileIO::reopenRW | ( | ) | [virtual] |
Reopen the file (and possibly underlying MultiFileBase) for read/write access.
Nothing will be done if the stream is writable already. An exception will be thrown if it is not possible to reopen it for read/write access.
Reimplemented from casacore::ByteIO.
virtual void casacore::MFFileIO::write | ( | Int64 | size, | |
const void * | buffer | |||
) | [virtual] |
Write a block at the given offset.
Implements casacore::ByteIO.
MultiFileBase& casacore::MFFileIO::itsFile [private] |
Definition at line 135 of file MFFileIO.h.
Int casacore::MFFileIO::itsId [private] |
Definition at line 138 of file MFFileIO.h.
String casacore::MFFileIO::itsName [private] |
Definition at line 137 of file MFFileIO.h.
Int64 casacore::MFFileIO::itsPosition [private] |
Definition at line 136 of file MFFileIO.h.