casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
casacore::ByteIO Class Referenceabstract

Abstract base class for IO on a byte stream. More...

#include <ByteIO.h>

Inheritance diagram for casacore::ByteIO:
casacore::FilebufIO casacore::FiledesIO casacore::MemoryIO casacore::MFFileIO casacore::StreamIO casacore::TapeIO casacore::RegularFileIO casacore::MMapfdIO casacore::MMapIO

Public Types

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...
 

Public Member Functions

 ByteIO ()
 The constructor does nothing. More...
 
virtual ~ByteIO ()
 
virtual void write (Int64 size, const void *buf)=0
 Write size bytes to the byte stream. More...
 
virtual void pwrite (Int64 size, Int64 offset, const void *buf)
 Write size bytes to the byte stream at offset. More...
 
virtual Int64 read (Int64 size, void *buf, Bool throwException=True)=0
 Read size bytes from the byte stream. More...
 
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. More...
 
virtual void reopenRW ()
 Reopen the underlying IO stream for read/write access. More...
 
Int64 seek (Int offset, ByteIO::SeekOption=ByteIO::Begin)
 This function sets the position on the given offset. More...
 
Int64 seek (Int64 offset, ByteIO::SeekOption=ByteIO::Begin)
 
virtual void flush ()
 Flush the data to the file. More...
 
virtual void fsync ()
 Fsync the file (i.e. More...
 
virtual void resync ()
 Resync the file (i.e. More...
 
virtual String fileName () const
 Get the file name of the file attached. More...
 
virtual Int64 length ()=0
 Get the length of the byte stream. More...
 
virtual Bool isReadable () const =0
 Is the byte stream readable? More...
 
virtual Bool isWritable () const =0
 Is the byte stream writable? More...
 
virtual Bool isSeekable () const =0
 Is the byte stream seekable? More...
 

Protected Member Functions

 ByteIO (const ByteIO &byteIO)
 Make copy constructor and assignment protected, so a user cannot use them (but a derived class can). More...
 
ByteIOoperator= (const ByteIO &byteIO)
 
virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption)=0
 

Detailed Description

Abstract base class for IO on a byte stream.

Intended use:

Public interface

Review Status

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

Synopsis

ByteIO is the abstract base class for all classes doing IO on byte streams. Examples of derived classes are RegularFileIO and MemoryIO.

ByteIO contains two enumerations, which define the possible open and seek options on byte streams. These enumerations are used throughout the IO framework.

Motivation

Make polymorphic operations on byte streams possible.

Definition at line 61 of file ByteIO.h.

Member Enumeration Documentation

Define the possible ByteIO open options.

Enumerator
Old 
Update 

read/write; file must exist.

Append 

read/write; create file if not exist.

New 

read/write; create file if not exist.

NewNoReplace 

read/write; file may not exist yet.

Scratch 

read/write; delete file at close.

Delete 

read/write; file must exist; delete at close.

Definition at line 65 of file ByteIO.h.

Define the possible seek options.

Enumerator
Begin 

Seek from beginning of file.

Current 

Seek from current position.

End 

Seek from the end of the file.

Definition at line 82 of file ByteIO.h.

Constructor & Destructor Documentation

casacore::ByteIO::ByteIO ( )
inline

The constructor does nothing.

Definition at line 172 of file ByteIO.h.

virtual casacore::ByteIO::~ByteIO ( )
virtual
casacore::ByteIO::ByteIO ( const ByteIO byteIO)
inlineprotected

Make copy constructor and assignment protected, so a user cannot use them (but a derived class can).

Definition at line 175 of file ByteIO.h.

Member Function Documentation

virtual Int64 casacore::ByteIO::doSeek ( Int64  offset,
ByteIO::SeekOption   
)
protectedpure virtual
virtual String casacore::ByteIO::fileName ( ) const
virtual

Get the file name of the file attached.

The default implementation returns an empty string.

Reimplemented in casacore::TapeIO, casacore::FiledesIO, casacore::FilebufIO, casacore::MFFileIO, and casacore::RegularFileIO.

virtual void casacore::ByteIO::flush ( )
virtual

Flush the data to the file.

The default implementation does nothing.

Reimplemented in casacore::FilebufIO, casacore::MFFileIO, and casacore::MMapfdIO.

virtual void casacore::ByteIO::fsync ( )
virtual

Fsync the file (i.e.

force the data to be physically written). The default implementation does nothing.

Reimplemented in casacore::FiledesIO, and casacore::MFFileIO.

virtual Bool casacore::ByteIO::isReadable ( ) const
pure virtual
virtual Bool casacore::ByteIO::isSeekable ( ) const
pure virtual
virtual Bool casacore::ByteIO::isWritable ( ) const
pure virtual
virtual Int64 casacore::ByteIO::length ( )
pure virtual
ByteIO & casacore::ByteIO::operator= ( const ByteIO byteIO)
inlineprotected

Definition at line 178 of file ByteIO.h.

virtual Int64 casacore::ByteIO::pread ( Int64  size,
Int64  offset,
void *  buf,
Bool  throwException = True 
)
virtual

Like read but reads from offset of start of the file The file offset is not changed.

Reimplemented in casacore::FiledesIO.

virtual void casacore::ByteIO::pwrite ( Int64  size,
Int64  offset,
const void *  buf 
)
virtual

Write size bytes to the byte stream at offset.

The file offset is not changed

Reimplemented in casacore::FiledesIO.

virtual Int64 casacore::ByteIO::read ( Int64  size,
void *  buf,
Bool  throwException = True 
)
pure 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.

Implemented in casacore::MemoryIO, casacore::TapeIO, casacore::FilebufIO, casacore::FiledesIO, casacore::MMapfdIO, casacore::MFFileIO, and casacore::StreamIO.

virtual void casacore::ByteIO::reopenRW ( )
virtual

Reopen the underlying IO stream for read/write access.

Nothing will be done if the stream is writable already. Otherwise it will be reopened and an exception will be thrown if it is not possible to reopen it for read/write access. The default implementation in this base class throws a "not possible" exception if a reopen has to be done.

Reimplemented in casacore::MFFileIO, and casacore::RegularFileIO.

Referenced by casacore::StManArrayFile::reopenRW().

virtual void casacore::ByteIO::resync ( )
virtual

Resync the file (i.e.

empty the current buffer). The default implementation does nothing.

Reimplemented in casacore::FilebufIO.

Int64 casacore::ByteIO::seek ( Int  offset,
ByteIO::SeekOption  option = ByteIO::Begin 
)
inline

This function sets the position on the given offset.

The seek option defines from which file position the seek is done. -1 is returned if not seekable.

Definition at line 187 of file ByteIO.h.

References doSeek().

Int64 casacore::ByteIO::seek ( Int64  offset,
ByteIO::SeekOption  option = ByteIO::Begin 
)
inline

Definition at line 183 of file ByteIO.h.

References doSeek().

virtual void casacore::ByteIO::write ( Int64  size,
const void *  buf 
)
pure virtual

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