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 /** 00029 * @file QIODeviceAdaptor.C 00030 * @brief Implementation of class qgxml::QIODeviceAdaptor 00031 * 00032 * See file QIODeviceAdaptor.H for the interface. 00033 * 00034 * @author <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a> 00035 * @date March 14, 2003 15:27 00036 * @since Qgar 2.1.1 00037 */ 00038 00039 00040 // For RCS/CVS use: Do not delete 00041 /* $Id: QIODeviceAdaptor.C,v 1.3 2004/06/21 16:03:37 rendek Exp $ */ 00042 00043 00044 #include <qgarlib/qtimpl/QIODeviceAdaptor.H> 00045 00046 #include <stdexcept> 00047 00048 using namespace std; 00049 00050 namespace qgxml { 00051 00052 00053 // --------------------------------------------------------------------- 00054 // C O N S T R U C T O R S 00055 // --------------------------------------------------------------------- 00056 00057 // Default constructor 00058 QIODeviceAdaptor::QIODeviceAdaptor(istream * stream) 00059 { 00060 _stream = stream; 00061 00062 00063 //-- Initialize device with proper flag. 00064 00065 setFlags( IO_ReadOnly | IO_Sequential | IO_Open ); 00066 } 00067 00068 // --------------------------------------------------------------------- 00069 // D E S T R U C T O R 00070 // --------------------------------------------------------------------- 00071 00072 QIODeviceAdaptor::~QIODeviceAdaptor() 00073 { 00074 close(); 00075 } 00076 00077 00078 // --------------------------------------------------------------------- 00079 // O T H E R 00080 // --------------------------------------------------------------------- 00081 bool 00082 QIODeviceAdaptor::open(int mode) 00083 { 00084 return true; 00085 } 00086 00087 // ---------------------------------------------------------------------- 00088 00089 void 00090 QIODeviceAdaptor::close() 00091 { 00092 flush(); 00093 } 00094 00095 // ---------------------------------------------------------------------- 00096 00097 void 00098 QIODeviceAdaptor::flush() 00099 { 00100 _stream->sync(); 00101 } 00102 00103 // ---------------------------------------------------------------------- 00104 00105 Q_ULONG 00106 QIODeviceAdaptor::size() const 00107 { 00108 // Since a accessing a stream is sequential, the size cannot be 00109 // known. This method should never be called. 00110 throw runtime_error("Unimplemented method"); 00111 return 0; 00112 } 00113 00114 // ---------------------------------------------------------------------- 00115 00116 Q_LONG 00117 QIODeviceAdaptor::readBlock(char * data, Q_ULONG maxlen) 00118 { 00119 return (Q_LONG)(_stream->readsome(data, maxlen)); 00120 } 00121 00122 // ---------------------------------------------------------------------- 00123 00124 Q_LONG 00125 QIODeviceAdaptor::writeBlock(const char * data, Q_ULONG len) 00126 { 00127 // This class only provides the features to read from a stream. 00128 throw runtime_error("Unimplemented method"); 00129 return 0; 00130 } 00131 00132 // ---------------------------------------------------------------------- 00133 00134 int 00135 QIODeviceAdaptor::getch() 00136 { 00137 return _stream->get(); 00138 } 00139 00140 // ---------------------------------------------------------------------- 00141 00142 int 00143 QIODeviceAdaptor::putch(int ch) 00144 { 00145 // This class only provides the features to read from a stream. 00146 throw runtime_error("Unimplemented method"); 00147 return 0; 00148 } 00149 00150 // ---------------------------------------------------------------------- 00151 00152 int 00153 QIODeviceAdaptor::ungetch(int ch) 00154 { 00155 // To be checked 00156 _stream->unget(); 00157 return 0; 00158 } 00159 00160 00161 // ---------------------------------------------------------------------- 00162 00163 } // namespace qgxml