ByteIO.h

Classes

ByteIO -- Abstract base class for IO on a byte stream. (full description)

class ByteIO

Types

enum OpenOption

Old = 1
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.

enum SeekOption

Begin = 1
Seek from beginning of file.
Current
Seek from current position.
End
Seek from the end of the file.

Interface

Public Members
ByteIO()
virtual ~ByteIO()
virtual void write (uInt size, const void* buf) = 0
virtual Int read (uInt size, void* buf, Bool throwException=True) = 0
virtual void reopenRW()
Int64 seek (Int offset, ByteIO::SeekOption = ByteIO::Begin)
Int64 seek (Int64 offset, ByteIO::SeekOption = ByteIO::Begin)
virtual Int64 length() = 0
virtual Bool isReadable() const = 0
virtual Bool isWritable() const = 0
virtual Bool isSeekable() const = 0
Protected Members
ByteIO (const ByteIO& byteIO)
ByteIO& operator= (const ByteIO& byteIO)
virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption) = 0

Description

Review Status

Reviewed By:
Friso Olnon
Date Reviewed:
1996/11/06
Programs:
Tests:

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.

Member Description

enum OpenOption

Define the possible ByteIO open options.

enum SeekOption

Define the possible seek options.

ByteIO()

The constructor does nothing.

virtual ~ByteIO()

virtual void write (uInt size, const void* buf) = 0

Write size bytes to the byte stream.

virtual Int read (uInt size, void* buf, Bool throwException=True) = 0

Read size bytes from the byte stream. Returns the number of bytes actually read, or a negative number if an error occured. Will also throw an Exception (AipsError) if the requested number of bytes could not be read unless throwException is set to False.

virtual void reopenRW()

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.

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

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.

virtual Int64 length() = 0

Get the length of the byte stream.

virtual Bool isReadable() const = 0

Is the byte stream readable?

virtual Bool isWritable() const = 0

Is the byte stream writable?

virtual Bool isSeekable() const = 0

Is the byte stream seekable?

ByteIO (const ByteIO& byteIO)
ByteIO& operator= (const ByteIO& byteIO)

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

virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption) = 0