00001 /*************************************************************************** 00002 iodevice.h - Definition of IODevice class. 00003 ------------------- 00004 begin : June 21 2002 00005 copyright : (C) 2003 by Vojtìch Toman 00006 email : vtoman@lit.cz 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00026 #ifndef IODEVICE_H 00027 #define IODEVICE_H 00028 00029 00030 00031 #include <cstdlib> 00032 #include "defs.h" 00033 #include "exceptions.h" 00034 00035 00037 typedef size_t IOSize; 00038 00039 00040 00046 enum IOState 00047 { 00049 ReadOk, 00050 00052 ReadError, 00053 00055 WriteOk, 00056 00058 WriteError, 00059 00061 EndOfFile, 00062 00064 DeviceNotPrepared 00065 00066 }; //IOState 00067 00068 00069 00103 class IODevice 00104 { 00105 public: 00111 IODevice() { prepared = false;} 00112 00118 virtual void prepare(void) throw (ExaltIOException) = 0; 00119 00125 virtual void flush(void) throw (ExaltIOException) = 0; 00126 00132 virtual void finish(void) throw (ExaltIOException) = 0; 00133 00144 virtual IOState readData(char *buf, IOSize length) throw (ExaltIOException) = 0; 00145 00155 virtual IOState getChar(int *c) throw (ExaltIOException) = 0; 00156 00167 virtual IOState writeData(const char *buf, IOSize length) throw (ExaltIOException) = 0; 00168 00178 virtual IOState putChar(int c) throw (ExaltIOException) = 0; 00179 00187 virtual IOSize bytesReadTotal(void) = 0; 00188 00196 virtual IOSize bytesRead(void) = 0; 00197 00198 00206 virtual IOSize bytesWritten(void) = 0; 00207 00216 virtual bool errorOccurred(void) = 0; 00217 00226 virtual bool eof(void) = 0; 00227 00236 virtual bool isPrepared(void) { return prepared; } 00237 00238 protected: 00240 bool prepared; 00241 00242 }; //IODevice 00243 00244 00245 00246 #endif //IODEVICE_H