Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

InputByteStream.h

Go to the documentation of this file.
00001 /* 00002 * This file is part of dvi2bitmap. 00003 * Copyright 1999--2002, Council for the Central Laboratory of the Research Councils 00004 * 00005 * This program is part of the Starlink Software Distribution: see 00006 * http://www.starlink.ac.uk 00007 * 00008 * dvi2bitmap is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * dvi2bitmap is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with dvi2bitmap; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * The General Public License is distributed along with this 00023 * program in the file LICENCE. 00024 * 00025 * Author: Norman Gray <norman@astro.gla.ac.uk> 00026 * $Id: InputByteStream.h,v 1.28 2004/11/04 20:32:28 nxg Exp $ 00027 */ 00028 00029 00030 #ifndef INPUT_BYTE_STREAM_HEADER_READ 00031 #define INPUT_BYTE_STREAM_HEADER_READ 1 00032 00033 #include <Byte.h> 00034 #include <DviError.h> 00035 #include <verbosity.h> 00036 00037 #include <string> 00038 00039 class InputByteStreamError : public DviError { 00040 public: 00041 InputByteStreamError(string s) : DviError(s) { } 00042 }; 00043 00074 class InputByteStream { 00075 00076 public: 00077 InputByteStream(int fileno) 00078 throw (InputByteStreamError); 00079 InputByteStream(string srcspec) 00080 throw (InputByteStreamError); 00081 ~InputByteStream(); 00082 00083 bool eof(); 00084 virtual void close(); 00085 Byte getByte(void) 00086 throw (InputByteStreamError); 00087 const Byte *getBlock(unsigned int length) 00088 throw (InputByteStreamError); 00089 void skip (unsigned int) 00090 throw (InputByteStreamError); 00091 00092 signed int getSIU(int) 00093 throw (InputByteStreamError); 00094 signed int getSIS(int) 00095 throw (InputByteStreamError); 00096 unsigned int getUIU(int) 00097 throw (InputByteStreamError); 00098 /* 00099 * static getUIU reads from an array, rather than the file (ie, 00100 * it's really nothing to do with InputByteStream, but it's here 00101 * for consistency. 00102 */ 00103 static unsigned int getUIU(int, const Byte *) 00104 throw (InputByteStreamError); 00105 static void setDefaultBufferSize(unsigned int length); 00110 static inline void verbosity (const verbosities level) { 00111 verbosity_ = level; 00112 } 00116 static verbosities getVerbosity(void) { return verbosity_; }; 00117 00118 protected: 00119 InputByteStream(); 00120 bool bindToFileDescriptor(int fileno, 00121 string filename="", 00122 int bufsize=0, 00123 bool fillBufferAndClose=false, 00124 bool assertIsSeekable=false) 00125 throw (InputByteStreamError); 00126 int openSourceSpec(string srcspec) 00127 throw (InputByteStreamError); 00136 int getFD(void) const { return fd_; } 00137 void bufferSeek(unsigned int pos) 00138 throw (InputByteStreamError); 00139 void reloadBuffer(void); 00140 00141 private: 00142 int fd_; /* file descriptor of handled file/pipe */ 00143 int mappedfd_; /* saved file descriptor of mapped file */ 00144 string fname_; /* name of file, or string rep'n of fd */ 00145 Byte *buf_; /* buffer */ 00146 size_t buflen_; /* size of buffer */ 00147 Byte *p_; /* current position in buffer */ 00148 Byte *eob_; /* end of buffer */ 00149 bool eof_; /* true on end of file (note this is from 00150 the client's point of view, not the class's: 00151 if we have `preloaded' a file, the 00152 underlying file will be closed, but there 00153 will still be more to read from the 00154 stream) */ 00155 void read_buf_(void) 00156 throw (InputByteStreamError); 00157 size_t certainly_read_(int fd, Byte *b, size_t len) 00158 throw (InputByteStreamError); 00159 00160 static verbosities verbosity_; 00161 static unsigned int default_buffer_length_; 00162 }; 00163 00164 #endif /* INPUT_BYTE_STREAM_HEADER_READ */

Generated on Sun Aug 21 18:21:02 2005 for dvi2bitmap by doxygen 1.3.8