Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

IODevice Class Reference

The abstract parent of all input/output devices. More...

#include <iodevice.h>

Inheritance diagram for IODevice:

FileDevice FunnelDevice List of all members.

Public Methods

 IODevice ()
 A constructor. More...

virtual void prepare (void)=0 throw (ExaltIOException)
 Prepare the device. More...

virtual void flush (void)=0 throw (ExaltIOException)
 Flush the device. More...

virtual void finish (void)=0 throw (ExaltIOException)
 Finish the work with the device. More...

virtual IOState readData (char *buf, IOSize length)=0 throw (ExaltIOException)
 Read up to the specified number of bytes into the buffer. More...

virtual IOState getChar (int *c)=0 throw (ExaltIOException)
 Read one char. More...

virtual IOState writeData (const char *buf, IOSize length)=0 throw (ExaltIOException)
 Write the specified number of bytes from the buffer. More...

virtual IOState putChar (int c)=0 throw (ExaltIOException)
 Write one char. More...

virtual IOSize bytesReadTotal (void)=0
 Return the number of bytes read so far. More...

virtual IOSize bytesRead (void)=0
 Return the number of bytes read by the last read operation. More...

virtual IOSize bytesWritten (void)=0
 Return the number of bytes written so far. More...

virtual bool errorOccurred (void)=0
 Informs whether an error occurred. More...

virtual bool eof (void)=0
 Informs whether the end of file occurred. More...

virtual bool isPrepared (void)
 Informs whether the device is prepared. More...


Protected Attributes

bool prepared
 Indication whether the device is prepared.


Detailed Description

The abstract parent of all input/output devices.

Libexalt is designed to support various kinds of inputs and outputs. In order to make this possible, it provides an abstraction of an input/output device. This generic device defines an interface that has to be implemented by all the devices used for the input/output.

The IODevice class defines also the style of the work with the devices. A typical example would look as follows (using FileDevice, which represents a file input/output):

  ...

  FileDevice file;
  char buffer[BUFFER_SIZE]

  file.prepare("filename.txt");
  while (file.readData(buffer, BUFFER_SIZE) == ReadOk)
    {
      //...do something with the buffer
    }

  if (file.errorOccurred())
    {
      //...an error occurred.
    }

  file.finish();

  ...

The device uses the C++ exceptions to report errors (see exceptions.h).

See also:
FileDevice, FunnelDevice.

Definition at line 103 of file iodevice.h.


Constructor & Destructor Documentation

IODevice::IODevice   [inline]
 

A constructor.

Initializes the device as unprepared.

Definition at line 111 of file iodevice.h.

References prepared.


Member Function Documentation

virtual IOSize IODevice::bytesRead void    [pure virtual]
 

Return the number of bytes read by the last read operation.

Returns the number of bytes read from the device by the last read operation.

Returns:
Number of bytes.

Implemented in FileDevice.

virtual IOSize IODevice::bytesReadTotal void    [pure virtual]
 

Return the number of bytes read so far.

Returns the total number of bytes read from the device.

Returns:
Number of bytes.

Implemented in FileDevice.

virtual IOSize IODevice::bytesWritten void    [pure virtual]
 

Return the number of bytes written so far.

Returns the total number of bytes written to the device.

Returns:
Number of bytes.

Implemented in FileDevice.

virtual bool IODevice::eof void    [pure virtual]
 

Informs whether the end of file occurred.

This method can be used for tests of the "end of file".

Return values:
TRUE  End of file occurred.
FALSE  End of file didn't occurred.

Implemented in FileDevice.

Referenced by XmlCodec::decode.

virtual bool IODevice::errorOccurred void    [pure virtual]
 

Informs whether an error occurred.

If any of the IO operations was unsuccessful, this method can be used to test it.

Return values:
TRUE  An error occurred.
FALSE  No error occurred.

Implemented in FileDevice.

Referenced by XmlCodec::decode.

virtual void IODevice::finish void    throw (ExaltIOException) [pure virtual]
 

Finish the work with the device.

This method ends the work with the device. In a case of a file device, for example, it may close a file. An attempt to work with finished device will cause an ExaltIOException to be raised.

Implemented in FileDevice.

virtual void IODevice::flush void    throw (ExaltIOException) [pure virtual]
 

Flush the device.

Ensures that all the data is written to the device.

Implemented in FileDevice.

virtual IOState IODevice::getChar int *    c throw (ExaltIOException) [pure virtual]
 

Read one char.

Reads one character from the device. If an error occurred, ExaltIOException is raised.

Parameters:
c  Pointer where the read character is stored.
Returns:
State of the device after the read operation.

Implemented in FileDevice.

Referenced by XmlCodec::decode.

virtual bool IODevice::isPrepared void    [inline, virtual]
 

Informs whether the device is prepared.

If the device is prepared, this method returns TRUE.

Return values:
TRUE  The device is prepared.
FALSE  The device is not prepared.

Definition at line 236 of file iodevice.h.

References prepared.

Referenced by FileDevice::~FileDevice.

virtual void IODevice::prepare void    throw (ExaltIOException) [pure virtual]
 

Prepare the device.

This method prepares the device for further work. In a case of a file device, for example, it can open a file. An attempt to work with unprepared device will cause an ExaltIOException to be raised.

Implemented in FileDevice.

virtual IOState IODevice::putChar int    c throw (ExaltIOException) [pure virtual]
 

Write one char.

Writes one character to the device. If an error occurred, ExaltIOException is raised.

Parameters:
c  The character.
Returns:
State of the device after the read operation.

Implemented in FileDevice.

Referenced by ArithCodec::doneOutputtingBits, XmlCodec::encode, and XmlCodec::initializePushCoder.

virtual IOState IODevice::readData char *    buf,
IOSize    length
throw (ExaltIOException) [pure virtual]
 

Read up to the specified number of bytes into the buffer.

Reads up to length bytes from the device and stores them in buffer. If an error occurred, ExaltIOException is raised.

Parameters:
buf  Pointer to the buffer.
length  Length of the buffer.
Returns:
State of the device after the read operation.

Implemented in FileDevice.

Referenced by XmlCodec::decode.

virtual IOState IODevice::writeData const char *    buf,
IOSize    length
throw (ExaltIOException) [pure virtual]
 

Write the specified number of bytes from the buffer.

Writes length bytes from the buffer buf to the device. If an error occurred, ExaltIOException is raised.

Parameters:
buf  Pointer to the buffer.
length  Length of the buffer.
Returns:
State of the device after the write operation.

Implemented in FileDevice.

Referenced by KYGrammar::appendToRootRule, XmlCodec::encode, XmlCodec::initializePushCoder, KYGrammar::reconstructRule, and KYGrammar::setAlphabetBaseSize.


The documentation for this class was generated from the following file:
Generated on Wed Feb 5 10:43:05 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002