casacore
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
casacore::MFFileIO Class Reference

More...

#include <MFFileIO.h>

Public Member Functions

 MFFileIO (const std::shared_ptr< MultiFileBase > &, const String &name, ByteIO::OpenOption=ByteIO::Old)
 Open or create a virtual file with the given name.
 
 ~MFFileIO () override
 The destructor flushes and closes the file.
 
Int64 read (Int64 size, void *buf, Bool throwException=True) override
 Read size bytes from the byte stream.
 
void write (Int64 size, const void *buffer) override
 Write a block at the current offset.
 
void reopenRW () override
 Reopen the file (and possibly underlying MultiFileBase) for read/write access.
 
void remove ()
 Remove the file from the MultiFileBase object.
 
void flush () override
 Flush the file by writing all dirty data and all header info.
 
Int64 length () override
 Get the length of the file.
 
Bool isReadable () const override
 The file is always readable.
 
Bool isWritable () const override
 Is the file writable?
 
Bool isSeekable () const override
 The file is always seekable.
 
String fileName () const override
 Get the file name of the file attached.
 
void fsync () override
 Fsync the file (i.e.
 
void truncate (Int64 size) override
 Truncate the file to the given size.
 
Int64 doSeek (Int64 offset, ByteIO::SeekOption) override
 Reset the position pointer to the given value.
 
const MultiFileInfogetInfo () const
 Get the MultiFileInfo object for this file.
 
- Public Member Functions inherited from casacore::ByteIO
 ByteIO ()
 The constructor does nothing.
 
virtual ~ByteIO ()
 
virtual void pwrite (Int64 size, Int64 offset, const void *buf)
 Write size bytes to the byte stream at offset.
 
virtual Int64 pread (Int64 size, Int64 offset, void *buf, Bool throwException=True)
 Like read but reads from offset of start of the file The file offset is not changed.
 
Int64 seek (Int offset, ByteIO::SeekOption=ByteIO::Begin)
 This function sets the position on the given offset.
 
Int64 seek (Int64 offset, ByteIO::SeekOption=ByteIO::Begin)
 
virtual void resync ()
 Resync the file (i.e.
 

Private Attributes

std::shared_ptr< MultiFileBaseitsFile
 
Int64 itsPosition
 
String itsName
 
Int itsId
 
Bool itsIsWritable
 

Additional Inherited Members

- Public Types inherited from casacore::ByteIO
enum  OpenOption {
  Old ,
  Update ,
  Append ,
  New ,
  NewNoReplace ,
  Scratch ,
  Delete
}
 Define the possible ByteIO open options. More...
 
enum  SeekOption {
  Begin ,
  Current ,
  End
}
 Define the possible seek options. More...
 
- Protected Member Functions inherited from casacore::ByteIO
 ByteIO (const ByteIO &byteIO)
 Make copy constructor and assignment protected, so a user cannot use them (but a derived class can).
 
ByteIOoperator= (const ByteIO &byteIO)
 

Detailed Description


Class for IO on a virtual file in a MultiFileBase

Intended use:

Public interface

Review Status

Reviewed By:
Friso Olnon
Date Reviewed:
1996/11/06
Test programs:
tByteIO

Synopsis

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.

Example

// Create a new MultiFile using a block size of 1 MB.
shared_ptr<MultiFileBase> mfile
(new MultiFile("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 76 of file MFFileIO.h.

Constructor & Destructor Documentation

◆ MFFileIO()

casacore::MFFileIO::MFFileIO ( const std::shared_ptr< 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.

◆ ~MFFileIO()

casacore::MFFileIO::~MFFileIO ( )
override

The destructor flushes and closes the file.

Member Function Documentation

◆ doSeek()

Int64 casacore::MFFileIO::doSeek ( Int64  offset,
ByteIO::SeekOption   
)
overridevirtual

Reset the position pointer to the given value.

It returns the new position.

Implements casacore::ByteIO.

◆ fileName()

String casacore::MFFileIO::fileName ( ) const
overridevirtual

Get the file name of the file attached.

Reimplemented from casacore::ByteIO.

◆ flush()

void casacore::MFFileIO::flush ( )
overridevirtual

Flush the file by writing all dirty data and all header info.

Reimplemented from casacore::ByteIO.

◆ fsync()

void casacore::MFFileIO::fsync ( )
overridevirtual

Fsync the file (i.e.

force the data to be physically written).

Reimplemented from casacore::ByteIO.

◆ getInfo()

const MultiFileInfo & casacore::MFFileIO::getInfo ( ) const

Get the MultiFileInfo object for this file.

◆ isReadable()

Bool casacore::MFFileIO::isReadable ( ) const
overridevirtual

The file is always readable.

Implements casacore::ByteIO.

◆ isSeekable()

Bool casacore::MFFileIO::isSeekable ( ) const
overridevirtual

The file is always seekable.

Implements casacore::ByteIO.

◆ isWritable()

Bool casacore::MFFileIO::isWritable ( ) const
overridevirtual

Is the file writable?

Implements casacore::ByteIO.

◆ length()

Int64 casacore::MFFileIO::length ( )
overridevirtual

Get the length of the file.

Implements casacore::ByteIO.

◆ read()

Int64 casacore::MFFileIO::read ( Int64  size,
void *  buf,
Bool  throwException = True 
)
overridevirtual

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.

◆ remove()

void casacore::MFFileIO::remove ( )

Remove the file from the MultiFileBase object.

It makes the object invalid by setting the fileId to -1.

◆ reopenRW()

void casacore::MFFileIO::reopenRW ( )
overridevirtual

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.

◆ truncate()

void casacore::MFFileIO::truncate ( Int64  size)
overridevirtual

Truncate the file to the given size.

Reimplemented from casacore::ByteIO.

◆ write()

void casacore::MFFileIO::write ( Int64  size,
const void *  buffer 
)
overridevirtual

Write a block at the current offset.

Implements casacore::ByteIO.

Member Data Documentation

◆ itsFile

std::shared_ptr<MultiFileBase> casacore::MFFileIO::itsFile
private

Definition at line 140 of file MFFileIO.h.

◆ itsId

Int casacore::MFFileIO::itsId
private

Definition at line 143 of file MFFileIO.h.

◆ itsIsWritable

Bool casacore::MFFileIO::itsIsWritable
private

Definition at line 144 of file MFFileIO.h.

◆ itsName

String casacore::MFFileIO::itsName
private

Definition at line 142 of file MFFileIO.h.

◆ itsPosition

Int64 casacore::MFFileIO::itsPosition
private

Definition at line 141 of file MFFileIO.h.


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