casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
casa::FiledesIO Class Reference

Class for IO on a file descriptor. More...

#include <FiledesIO.h>

Inheritance diagram for casa::FiledesIO:
casa::ByteIO

List of all members.

Public Member Functions

 FiledesIO ()
 Default constructor.
 FiledesIO (int fd, const String &fileName=String())
 Construct from the given file descriptor.
void attach (int fd, const String &fileName)
 Attach to the given file descriptor.
 ~FiledesIO ()
 The destructor does not close the file.
virtual void write (uInt size, const void *buf)
 Write the number of bytes.
virtual Int read (uInt size, void *buf, Bool throwException=True)
 Read size bytes from the descriptor.
virtual Int64 length ()
 Get the length of the byte stream.
virtual Bool isReadable () const
 Is the IO stream readable?
virtual Bool isWritable () const
 Is the IO stream writable?
virtual Bool isSeekable () const
 Is the IO stream seekable?
const StringfileName () const
 Get the file name of the file attached.

Static Public Member Functions

static int create (const Char *name, int mode=0644)
 Some static convenience functions for file create/open/close.
static int open (const Char *name, Bool writable=False, Bool throwExcp=True)
static void close (int fd)

Protected Member Functions

int fd () const
 
      

void detach ()
 Detach from the file descriptor.
void fillRWFlags (int fd)
 Determine if the file descriptor is readable and/or writable.
void fillSeekable ()
 Determine if the file is seekable.
virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption)
 Reset the position pointer to the given value.

Private Member Functions

 FiledesIO (const FiledesIO &that)
 Copy constructor, should not be used.
FiledesIOoperator= (const FiledesIO &that)
 Assignment, should not be used.

Private Attributes

Bool itsSeekable
Bool itsReadable
Bool itsWritable
int itsFile
String itsFileName

Detailed Description

Class for IO on a file descriptor.

Intended use:

Public interface

 <h3>Review Status</h3><dl><dt>Reviewed By:<dd>Friso Olnon<dt>Date Reviewed:<dd>1996/11/06<dt>Test programs:<dd>tByteIO</dl> 

Prerequisite

Synopsis

This class is a specialization of class ByteIO . It uses a file descriptor to read/write data.

The file associated with the file descriptor has to be opened before hand. The constructor will determine automatically if the file is readable, writable and seekable. Note that on destruction the file descriptor is NOT closed.

Example

This example shows how FiledesIO can be used with an fd. It uses the fd for a regular file, which could be done in an easier way using class RegularFileIO . However, when using pipes or sockets, this would be the only way.

       // Get a file descriptor for the file.
       int fd = open ("file.name");
       // Use that as the source of AipsIO (which will also use CanonicalIO).
       FiledesIO fio (fd);
       AipsIO stream (&fio);
       // Read the data.
       Int vali;
       Bool valb;
       stream >> vali >> valb;

Motivation

Make it possible to use the AIPS++ IO functionality on any file. In this way any device can be hooked to the IO framework.

Definition at line 86 of file FiledesIO.h.


Constructor & Destructor Documentation

Default constructor.

A stream can be attached using the attach function.

casa::FiledesIO::FiledesIO ( int  fd,
const String fileName = String() 
) [explicit]

Construct from the given file descriptor.

The file name is only used in possible error messages.

The destructor does not close the file.

casa::FiledesIO::FiledesIO ( const FiledesIO that) [private]

Copy constructor, should not be used.


Member Function Documentation

void casa::FiledesIO::attach ( int  fd,
const String fileName 
)

Attach to the given file descriptor.

An exception is thrown if it is not in a detached state. The file name is only used in error messages.

static void casa::FiledesIO::close ( int  fd) [static]
static int casa::FiledesIO::create ( const Char name,
int  mode = 0644 
) [static]

Some static convenience functions for file create/open/close.

void casa::FiledesIO::detach ( ) [protected]

Detach from the file descriptor.

It is not closed.

virtual Int64 casa::FiledesIO::doSeek ( Int64  offset,
ByteIO::SeekOption   
) [protected, virtual]

Reset the position pointer to the given value.

It returns the new position.

Implements casa::ByteIO.

int casa::FiledesIO::fd ( ) const [inline, protected]

      

Get the file descriptor.

Definition at line 143 of file FiledesIO.h.

References itsFile.

const String& casa::FiledesIO::fileName ( ) const [inline]

Get the file name of the file attached.

Definition at line 129 of file FiledesIO.h.

References itsFileName.

void casa::FiledesIO::fillRWFlags ( int  fd) [protected]

Determine if the file descriptor is readable and/or writable.

void casa::FiledesIO::fillSeekable ( ) [protected]

Determine if the file is seekable.

virtual Bool casa::FiledesIO::isReadable ( ) const [virtual]

Is the IO stream readable?

Implements casa::ByteIO.

virtual Bool casa::FiledesIO::isSeekable ( ) const [virtual]

Is the IO stream seekable?

Implements casa::ByteIO.

virtual Bool casa::FiledesIO::isWritable ( ) const [virtual]

Is the IO stream writable?

Implements casa::ByteIO.

virtual Int64 casa::FiledesIO::length ( ) [virtual]

Get the length of the byte stream.

Implements casa::ByteIO.

static int casa::FiledesIO::open ( const Char name,
Bool  writable = False,
Bool  throwExcp = True 
) [static]
FiledesIO& casa::FiledesIO::operator= ( const FiledesIO that) [private]

Assignment, should not be used.

virtual Int casa::FiledesIO::read ( uInt  size,
void *  buf,
Bool  throwException = True 
) [virtual]

Read size bytes from the descriptor.

Returns the number of bytes actually read or a negative number if an error occured. Will throw an Exception (AipsError) if the requested number of bytes could not be read, or an error occured, unless throwException is set to False. Will always throw an exception if the descriptor is not readable or the system call returned an undocumented value.

Implements casa::ByteIO.

virtual void casa::FiledesIO::write ( uInt  size,
const void *  buf 
) [virtual]

Write the number of bytes.

Implements casa::ByteIO.


Member Data Documentation

int casa::FiledesIO::itsFile [private]

Definition at line 163 of file FiledesIO.h.

Referenced by fd().

Definition at line 164 of file FiledesIO.h.

Referenced by fileName().

Definition at line 161 of file FiledesIO.h.

Definition at line 160 of file FiledesIO.h.

Definition at line 162 of file FiledesIO.h.


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