casacore
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::FiledesIO Class Reference

More...

#include <FiledesIO.h>

Public Member Functions

 FiledesIO ()
 Default constructor. More...
 
 FiledesIO (int fd, const String &fileName=String())
 Construct from the given file descriptor. More...
 
void attach (int fd, const String &fileName)
 Attach to the given file descriptor. More...
 
void detach ()
 Detach from the file descriptor. More...
 
virtual ~FiledesIO ()
 The destructor detaches, but does not close the file. More...
 
virtual void write (Int64 size, const void *buf)
 Write the number of bytes. More...
 
virtual void pwrite (Int64 size, Int64 offset, const void *buf)
 Write the number of bytes at offset from start of the file. More...
 
virtual Int64 read (Int64 size, void *buf, Bool throwException=True)
 Read size bytes from the descriptor. More...
 
virtual Int64 pread (Int64 size, Int64 offset, void *buf, Bool throwException=True)
 Like read except reads from offset of the start of the file. More...
 
virtual Int64 length ()
 Get the length of the byte stream. More...
 
virtual Bool isReadable () const
 Is the IO stream readable? More...
 
virtual Bool isWritable () const
 Is the IO stream writable? More...
 
virtual Bool isSeekable () const
 Is the IO stream seekable? More...
 
void setWritable ()
 Set that the IO stream is writable. More...
 
virtual String fileName () const
 Get the file name of the file attached. More...
 
virtual void fsync ()
 Fsync the file (i.e. More...
 
- Public Member Functions inherited from casacore::ByteIO
 ByteIO ()
 The constructor does nothing. More...
 
virtual ~ByteIO ()
 
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 resync ()
 Resync the file (i.e. More...
 

Static Public Member Functions

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

Protected Member Functions

int fd () const
 Get the file descriptor. More...
 
void fillRWFlags (int fd)
 Determine if the file descriptor is readable and/or writable. More...
 
void fillSeekable ()
 Determine if the file is seekable. More...
 
virtual Int64 doSeek (Int64 offset, ByteIO::SeekOption)
 Reset the position pointer to the given value. 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). More...
 
ByteIOoperator= (const ByteIO &byteIO)
 

Private Member Functions

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

Private Attributes

Bool itsSeekable
 
Bool itsReadable
 
Bool itsWritable
 
int itsFile
 
String itsFileName
 

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

Detailed Description

Class for unbuffered IO on a file.

Intended use:

Public interface

Review Status

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

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;
int fd() const
Get the file descriptor.
Definition: FiledesIO.h:163
FiledesIO()
Default constructor.
static int open(const Char *name, Bool writable=False, Bool throwExcp=True)
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42

Motivation

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

Definition at line 88 of file FiledesIO.h.

Constructor & Destructor Documentation

◆ FiledesIO() [1/3]

casacore::FiledesIO::FiledesIO ( )

Default constructor.

A stream can be attached using the attach function.

◆ FiledesIO() [2/3]

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

◆ ~FiledesIO()

virtual casacore::FiledesIO::~FiledesIO ( )
virtual

The destructor detaches, but does not close the file.

◆ FiledesIO() [3/3]

casacore::FiledesIO::FiledesIO ( const FiledesIO that)
private

Copy constructor, should not be used.

Member Function Documentation

◆ attach()

void casacore::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.

◆ close()

static void casacore::FiledesIO::close ( int  fd)
static

◆ create()

static int casacore::FiledesIO::create ( const Char name,
int  mode = 0666 
)
static

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

Close is only done if the fd is non-negative.

◆ detach()

void casacore::FiledesIO::detach ( )

Detach from the file descriptor.

The file is not closed.

◆ doSeek()

virtual Int64 casacore::FiledesIO::doSeek ( Int64  offset,
ByteIO::SeekOption   
)
protectedvirtual

Reset the position pointer to the given value.

It returns the new position.

Implements casacore::ByteIO.

Reimplemented in casacore::MMapfdIO.

◆ fd()

int casacore::FiledesIO::fd ( ) const
inlineprotected

Get the file descriptor.

Definition at line 163 of file FiledesIO.h.

References itsFile.

◆ fileName()

virtual String casacore::FiledesIO::fileName ( ) const
virtual

Get the file name of the file attached.

Reimplemented from casacore::ByteIO.

◆ fillRWFlags()

void casacore::FiledesIO::fillRWFlags ( int  fd)
protected

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

◆ fillSeekable()

void casacore::FiledesIO::fillSeekable ( )
protected

Determine if the file is seekable.

◆ fsync()

virtual void casacore::FiledesIO::fsync ( )
virtual

Fsync the file (i.e.

force the data to be physically written).

Reimplemented from casacore::ByteIO.

◆ isReadable()

virtual Bool casacore::FiledesIO::isReadable ( ) const
virtual

Is the IO stream readable?

Implements casacore::ByteIO.

◆ isSeekable()

virtual Bool casacore::FiledesIO::isSeekable ( ) const
virtual

Is the IO stream seekable?

Implements casacore::ByteIO.

◆ isWritable()

virtual Bool casacore::FiledesIO::isWritable ( ) const
virtual

Is the IO stream writable?

Implements casacore::ByteIO.

◆ length()

virtual Int64 casacore::FiledesIO::length ( )
virtual

Get the length of the byte stream.

Implements casacore::ByteIO.

◆ open()

static int casacore::FiledesIO::open ( const Char name,
Bool  writable = False,
Bool  throwExcp = True 
)
static

◆ operator=()

FiledesIO& casacore::FiledesIO::operator= ( const FiledesIO that)
private

Assignment, should not be used.

◆ pread()

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

Like read except reads from offset of the start of the file.

The file offset is not changed

Reimplemented from casacore::ByteIO.

◆ pwrite()

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

Write the number of bytes at offset from start of the file.

The file offset is not changed

Reimplemented from casacore::ByteIO.

◆ read()

virtual Int64 casacore::FiledesIO::read ( Int64  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 occurred. 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 casacore::ByteIO.

Reimplemented in casacore::MMapfdIO.

◆ setWritable()

void casacore::FiledesIO::setWritable ( )
inline

Set that the IO stream is writable.

Definition at line 142 of file FiledesIO.h.

References itsWritable, and casacore::True.

◆ write()

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

Write the number of bytes.

Implements casacore::ByteIO.

Reimplemented in casacore::MMapfdIO.

Member Data Documentation

◆ itsFile

int casacore::FiledesIO::itsFile
private

Definition at line 180 of file FiledesIO.h.

Referenced by fd().

◆ itsFileName

String casacore::FiledesIO::itsFileName
private

Definition at line 181 of file FiledesIO.h.

◆ itsReadable

Bool casacore::FiledesIO::itsReadable
private

Definition at line 178 of file FiledesIO.h.

◆ itsSeekable

Bool casacore::FiledesIO::itsSeekable
private

Definition at line 177 of file FiledesIO.h.

◆ itsWritable

Bool casacore::FiledesIO::itsWritable
private

Definition at line 179 of file FiledesIO.h.

Referenced by setWritable().


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