Class for unbuffered IO on a file. 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. | |
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. | |
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 |
Class for unbuffered IO on a file.
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 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.
casacore::FiledesIO::FiledesIO | ( | ) |
Default constructor.
A stream can be attached using the attach function.
virtual casacore::FiledesIO::~FiledesIO | ( | ) | [virtual] |
The destructor detaches, but does not close the file.
casacore::FiledesIO::FiledesIO | ( | const FiledesIO & | that | ) | [private] |
Copy constructor, should not be used.
void casacore::FiledesIO::attach | ( | int | fd, | |
const String & | fileName | |||
) |
static void casacore::FiledesIO::close | ( | int | fd | ) | [static] |
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.
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.
int casacore::FiledesIO::fd | ( | ) | const [inline, protected] |
virtual String casacore::FiledesIO::fileName | ( | ) | const [virtual] |
Get the file name of the file attached.
Reimplemented from casacore::ByteIO.
void casacore::FiledesIO::fillRWFlags | ( | int | fd | ) | [protected] |
Determine if the file descriptor is readable and/or writable.
void casacore::FiledesIO::fillSeekable | ( | ) | [protected] |
Determine if the file is seekable.
virtual void casacore::FiledesIO::fsync | ( | ) | [virtual] |
virtual Bool casacore::FiledesIO::isReadable | ( | ) | const [virtual] |
Is the IO stream readable?
Implements casacore::ByteIO.
virtual Bool casacore::FiledesIO::isSeekable | ( | ) | const [virtual] |
Is the IO stream seekable?
Implements casacore::ByteIO.
virtual Bool casacore::FiledesIO::isWritable | ( | ) | const [virtual] |
Is the IO stream writable?
Implements casacore::ByteIO.
virtual Int64 casacore::FiledesIO::length | ( | ) | [virtual] |
Get the length of the byte stream.
Implements casacore::ByteIO.
static int casacore::FiledesIO::open | ( | const Char * | name, | |
Bool | writable = False , |
|||
Bool | throwExcp = True | |||
) | [static] |
Assignment, should not be used.
Reimplemented from casacore::ByteIO.
Reimplemented in casacore::MMapfdIO, and casacore::MMapIO.
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.
Write the number of bytes at offset from start of the file.
The file offset is not changed
Reimplemented from casacore::ByteIO.
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.
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.
virtual void casacore::FiledesIO::write | ( | Int64 | size, | |
const void * | buf | |||
) | [virtual] |
int casacore::FiledesIO::itsFile [private] |
Definition at line 180 of file FiledesIO.h.
Referenced by fd().
String casacore::FiledesIO::itsFileName [private] |
Definition at line 181 of file FiledesIO.h.
Bool casacore::FiledesIO::itsReadable [private] |
Definition at line 178 of file FiledesIO.h.
Bool casacore::FiledesIO::itsSeekable [private] |
Definition at line 177 of file FiledesIO.h.
Bool casacore::FiledesIO::itsWritable [private] |
Definition at line 179 of file FiledesIO.h.
Referenced by setWritable().