casa
$Rev:20696$
|
Class for IO on a large file descriptor. More...
#include <LargeFiledesIO.h>
Public Member Functions | |
LargeFiledesIO () | |
Default constructor. | |
LargeFiledesIO (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. | |
~LargeFiledesIO () | |
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 String & | fileName () 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 | |
LargeFiledesIO (const LargeFiledesIO &that) | |
Copy constructor, should not be used. | |
LargeFiledesIO & | operator= (const LargeFiledesIO &that) |
Assignment, should not be used. | |
Private Attributes | |
Bool | itsSeekable |
Bool | itsReadable |
Bool | itsWritable |
int | itsFile |
String | itsFileName |
Class for IO on a large file descriptor.
Public interface
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.
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;
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 88 of file LargeFiledesIO.h.
Default constructor.
A stream can be attached using the attach function.
casa::LargeFiledesIO::LargeFiledesIO | ( | 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::LargeFiledesIO::LargeFiledesIO | ( | const LargeFiledesIO & | that | ) | [private] |
Copy constructor, should not be used.
void casa::LargeFiledesIO::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::LargeFiledesIO::close | ( | int | fd | ) | [static] |
static int casa::LargeFiledesIO::create | ( | const Char * | name, |
int | mode = 0644 |
||
) | [static] |
Some static convenience functions for file create/open/close.
void casa::LargeFiledesIO::detach | ( | ) | [protected] |
Detach from the file descriptor.
It is not closed.
virtual Int64 casa::LargeFiledesIO::doSeek | ( | Int64 | offset, |
ByteIO::SeekOption | |||
) | [protected, virtual] |
Reset the position pointer to the given value.
It returns the new position.
Implements casa::ByteIO.
Reimplemented in casa::MMapfdIO.
int casa::LargeFiledesIO::fd | ( | ) | const [inline, protected] |
const String& casa::LargeFiledesIO::fileName | ( | ) | const [inline] |
Get the file name of the file attached.
Definition at line 131 of file LargeFiledesIO.h.
References itsFileName.
void casa::LargeFiledesIO::fillRWFlags | ( | int | fd | ) | [protected] |
Determine if the file descriptor is readable and/or writable.
void casa::LargeFiledesIO::fillSeekable | ( | ) | [protected] |
Determine if the file is seekable.
virtual Bool casa::LargeFiledesIO::isReadable | ( | ) | const [virtual] |
Is the IO stream readable?
Implements casa::ByteIO.
virtual Bool casa::LargeFiledesIO::isSeekable | ( | ) | const [virtual] |
Is the IO stream seekable?
Implements casa::ByteIO.
virtual Bool casa::LargeFiledesIO::isWritable | ( | ) | const [virtual] |
Is the IO stream writable?
Implements casa::ByteIO.
virtual Int64 casa::LargeFiledesIO::length | ( | ) | [virtual] |
Get the length of the byte stream.
Implements casa::ByteIO.
static int casa::LargeFiledesIO::open | ( | const Char * | name, |
Bool | writable = False , |
||
Bool | throwExcp = True |
||
) | [static] |
LargeFiledesIO& casa::LargeFiledesIO::operator= | ( | const LargeFiledesIO & | that | ) | [private] |
Assignment, should not be used.
virtual Int casa::LargeFiledesIO::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.
Reimplemented in casa::MMapfdIO.
virtual void casa::LargeFiledesIO::write | ( | uInt | size, |
const void * | buf | ||
) | [virtual] |
int casa::LargeFiledesIO::itsFile [private] |
Definition at line 165 of file LargeFiledesIO.h.
Referenced by fd().
String casa::LargeFiledesIO::itsFileName [private] |
Definition at line 166 of file LargeFiledesIO.h.
Referenced by fileName().
Bool casa::LargeFiledesIO::itsReadable [private] |
Definition at line 163 of file LargeFiledesIO.h.
Bool casa::LargeFiledesIO::itsSeekable [private] |
Definition at line 162 of file LargeFiledesIO.h.
Bool casa::LargeFiledesIO::itsWritable [private] |
Definition at line 164 of file LargeFiledesIO.h.