Loading...
Searching...
No Matches
casacore::FiledesIO Class Reference
casa package (libcasa_casa) » IO_module

More...

`#include <FiledesIO.h>`

## 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.
void | detach ()
| Detach from the file descriptor.
virtual | ~FiledesIO ()
| The destructor detaches, but does not close the file.
virtual void | write (Int64 size, const void *buf)
| Write the number of bytes.
virtual void | pwrite (Int64 size, Int64 offset, const void *buf)
| Write the number of bytes at offset from start of the file.
virtual Int64 | read (Int64 size, void *buf, Bool throwException=True)
| Read size bytes from the descriptor.
virtual Int64 | pread (Int64 size, Int64 offset, void *buf, Bool throwException=True)
| Like read except reads from offset of the start of the file.
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?
void | setWritable ()
| Set that the IO stream is writable.
virtual String | fileName () const
| Get the file name of the file attached.
virtual void | fsync ()
| Fsync the file (i.e.
virtual void | truncate (Int64 size)
| Truncate the file to the given size.
Public Member Functions inherited from casacore::ByteIO
| ByteIO ()
| The constructor does nothing.
virtual | ~ByteIO ()
virtual void | reopenRW ()
| Reopen the underlying IO stream for read/write access.
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 | flush ()
| Flush the data to the file.
virtual void | resync ()
| Resync the file (i.e.

## Static Public Member Functions

static int | create (const Char *name, int mode=0666)
| 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
| Get 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.
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).
ByteIO & | operator= (const ByteIO &byteIO)

## Private Member Functions

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

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

- ByteIO class
- file descriptors

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

### 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 86 of file FiledesIO.h.

## Constructor & Destructor Documentation

## FiledesIO() [1/3]

casacore::FiledesIO::FiledesIO | ( |  | ) |

Default constructor.

A stream can be attached using the attach function.

Referenced by FiledesIO(), and operator=().

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

References fd(), and fileName().

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

References FiledesIO().

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

References fd(), and fileName().

## close()

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

static

References fd().

## create()

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.

References casacore::name().

## 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 | )

protected virtual

Reset the position pointer to the given value.

It returns the new position.

Implements casacore::ByteIO.

Reimplemented in casacore::MMapfdIO.

References casacore::offset().

## fd()

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

inline protected

Get the file descriptor.

Definition at line 164 of file FiledesIO.h.

References itsFile.

Referenced by attach(), close(), FiledesIO(), fillRWFlags(), casacore::MMapfdIO::map(), and casacore::MMapfdIO::MMapfdIO().

## fileName()

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

virtual

Get the file name of the file attached.

Reimplemented from casacore::ByteIO.

Referenced by attach(), FiledesIO(), casacore::FileUnbufferedIO::FileUnbufferedIO(), casacore::MMapfdIO::map(), and casacore::MMapfdIO::MMapfdIO().

## fillRWFlags()

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

protected

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

References fd().

## 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()

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

static

References casacore::False, casacore::name(), and casacore::True.

## operator=()

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

private

Assignment, should not be used.

References FiledesIO().

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

References casacore::offset(), casacore::size(), and casacore::True.

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

References casacore::offset(), and casacore::size().

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

References casacore::size(), and casacore::True.

## setWritable()

void casacore::FiledesIO::setWritable | ( |  | ) |

inline

Set that the IO stream is writable.

Definition at line 140 of file FiledesIO.h.

References itsWritable, and casacore::True.

## truncate()

virtual void casacore::FiledesIO::truncate | ( | Int64 | size | ) |

virtual

Truncate the file to the given size.

Reimplemented from casacore::ByteIO.

References casacore::size().

## write()

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

virtual

Write the number of bytes.

Implements casacore::ByteIO.

Reimplemented in casacore::MMapfdIO.

References casacore::size().

## Member Data Documentation

## itsFile

int casacore::FiledesIO::itsFile

private

Definition at line 181 of file FiledesIO.h.

Referenced by fd().

## itsFileName

String casacore::FiledesIO::itsFileName

private

Definition at line 182 of file FiledesIO.h.

## itsReadable

Bool casacore::FiledesIO::itsReadable

private

Definition at line 179 of file FiledesIO.h.

## itsSeekable

Bool casacore::FiledesIO::itsSeekable

private

Definition at line 178 of file FiledesIO.h.

## itsWritable

Bool casacore::FiledesIO::itsWritable

private

Definition at line 180 of file FiledesIO.h.

Referenced by setWritable().

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

- casa/IO/FiledesIO.h