Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QIODeviceAdaptor.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------*
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2003  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the license. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 #ifndef __QIODEVICEADAPTOR_H_INCLUDED__
00029 #define __QIODEVICEADAPTOR_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file     QIODeviceAdaptor.H
00034  * @brief    Header file of class qgxml::QIODeviceAdaptor
00035  *
00036  * @author   <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a>
00037  * @date     March 14, 2003  15:27
00038  * @since    Qgar 2.1.1
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: QIODeviceAdaptor.H,v 1.3 2004/06/24 15:07:27 rendek Exp $ */
00044 
00045 
00046 #include <qxml.h>
00047 
00048 #include <istream>
00049 
00050 namespace qgxml {
00051 
00052 
00053 /**
00054  * @class QIODeviceAdaptor QIODeviceAdaptor.H
00055  * @brief Adapts the interface of Qt QIODevice to std::istream.
00056  *
00057  * 
00058  * <p>
00059  * This class adapts a standard input stream (std::istream) into a valid Qt
00060  * QIODevice. All function calls performed on an instance of this class are
00061  * transformed into calls to the istream data member. Although this
00062  * class extends QIODevice, it implements only a <strong>sequential
00063  * input stream</strong>
00064  * </p>
00065  * <p>
00066  * For compatibility reasons with the parent class QIODevice, this
00067  * class implements some inherited function members that are not
00068  * relevant for  a sequential output stream. These members are:
00069  * - size()
00070  * - writeBlock()
00071  * - putch()
00072  *
00073  * Any attempt to use these function members will raise a
00074  * std::runtime_error exception.
00075  * </p>
00076  *
00077  * @author <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a> 
00078  * @date   March 14, 2003  15:27
00079  * @since  Qgar 2.1.1
00080  */
00081 class QIODeviceAdaptor : public QIODevice {
00082 
00083 // -------------------------------------------------------------------
00084 // P U B L I C    M E M B E R S
00085 // -------------------------------------------------------------------
00086 public:
00087 
00088 
00089 /** @name Constructors */
00090 //        ============
00091 //@{
00092 /**
00093  * @brief Default constructor
00094  *
00095  * <p>
00096  * Create an adaptor redirecting class to a QIODevice instance to a
00097  * istream instance. This QIODevice should be used only as a
00098  * sequential input device.
00099  * </p>
00100  * <p>
00101  * The QIODevice flags set at the creation are: 
00102  * - IO_ReadOnly 
00103  * - IO_Sequential 
00104  * - IO_Open;
00105  * </p>
00106  *
00107  * @param stream The stream to which all calls will be redirected to.
00108  */
00109   explicit QIODeviceAdaptor(std::istream * stream);
00110 //@}
00111 
00112 
00113 /** @name Destructors */
00114 //        ===========
00115 //@{
00116 /**
00117  * @brief Destructor
00118  */
00119   virtual ~QIODeviceAdaptor();
00120 //@}
00121 
00122 
00123 /**
00124  * @brief Open the I/O device using a specified mode.
00125  *
00126  * <p>
00127  * This function is provided for compatibility purpose only. The
00128  * stream is declared opened at creation time (see QIODeviceAdatptor)
00129  * and will remain this way until destroyed. Thus this function member
00130  * returns always true.
00131  * </p>
00132  *
00133  * @return always true
00134  */
00135   virtual bool open(int mode);
00136 
00137 
00138 /**
00139  * @brief Closes the device.
00140  */
00141   virtual void close();
00142 
00143 
00144 /**
00145  * @brief flushes an open iodevice
00146  *
00147  */
00148   virtual void flush();
00149 
00150 
00151 /**
00152  * @brief Returns the size of the IODevice.
00153  *
00154  * @return nothing since any call to this function member will raise an
00155  * exception.
00156  *
00157  * @warning Method redefined for compatibility purpose only. Calling
00158  * it will raise an error.
00159  *
00160  * @throw std::runtime_error whenever this function member is called.
00161  */
00162   virtual Offset size() const;
00163 
00164 
00165 /**
00166  * @brief Reads a block of data from the stream. 
00167  *
00168  * Reads at most maxlen bytes from the I/O device into data and
00169  * returns the number of bytes actually read.
00170  *
00171  * @param data a pointer on a free memory space where to store the
00172  * read data. This space must be big enough to hold up to maxlen
00173  * bytes.
00174  *
00175  * @param maxlen The maximum number of bytes to be read from the
00176  * device.
00177  * 
00178  * @return the number of bytes actually read.
00179  */
00180   virtual Q_LONG readBlock(char * data, Q_ULONG maxlen);
00181 
00182 
00183 /**
00184  * @brief Writes a block of data to the stream
00185  *
00186  * @return nothing since any call to this function member will raise an
00187  * exception.
00188  *
00189  * @warning Method redefined for compatibility purpose only. Calling
00190  * it will raise an error.
00191  *
00192  * @throw std::runtime_error whenever this function member is called.
00193  */
00194   virtual Q_LONG writeBlock(const char * data, Q_ULONG len);
00195 
00196 
00197 /**
00198  * @brief reads a single byte from the stream.
00199  *
00200  * @return the byte read cast into an int.
00201  */
00202   virtual int getch();
00203 
00204 
00205 /**
00206  * @brief Writes a single byte to the stream
00207  *
00208  * @return nothing since any call to this function member will raise an
00209  * exception.
00210  *
00211  * @warning Method redefined for compatibility purpose only. Calling
00212  * it will raise an error.
00213  *
00214  * @throw std::runtime_error whenever this function member is called.
00215  */
00216   virtual int putch (int ch);
00217 
00218   
00219 /**
00220  * @brief  Puts the character ch back into the I/O device and
00221  * decrements the index position if it is not zero. 
00222  *
00223  * @return nothing since any call to this function member will raise an
00224  * exception.
00225  *
00226  * @warning Method redefined for compatibility purpose only. Calling
00227  * it will raise an error.
00228  *
00229  * @throw std::runtime_error whenever this function member is called.
00230  */
00231   virtual int ungetch(int ch);
00232 
00233 
00234 
00235 // -------------------------------------------------------------------
00236 // P R O T E C T E D    M E M B E R S
00237 // -------------------------------------------------------------------
00238 protected:
00239 
00240 /**
00241  * @brief The input stream implementing this IODevice.
00242  *
00243  * This data member is the 'real' implementation of the
00244  * IODevice. Every calls to a function member of this class is
00245  * translated and redirected to it.
00246  */
00247   std::istream * _stream;
00248 
00249 
00250 // -------------------------------------------------------------------
00251 
00252 }; // class QIODeviceAdaptor
00253 
00254 } // namespace qgxml
00255 
00256 
00257 #endif /* __QIODEVICEADAPTOR_H_INCLUDED__ */