.TH "InputByteStream" 3 "Mon Jan 12 2015" "Version dvi2bitmap1.0" "dvi2bitmap" \" -*- nroff -*- .ad l .nh .SH NAME InputByteStream \- .PP Abstracts a file as a stream of bytes\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .PP Inherited by \fBFileByteStream\fP, and \fBPipeStream\fP\&. .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBInputByteStream\fP (int fileno) throw (InputByteStreamError)" .br .RI "\fIPrepares to read a stream from the specified file descriptor, which must be open\&. \fP" .ti -1c .RI "\fBInputByteStream\fP (string srcspec) throw (InputByteStreamError)" .br .RI "\fIPrepares to read a stream from the specified source\&. \fP" .ti -1c .RI "\fB~InputByteStream\fP ()" .br .RI "\fICloses the file and reclaims any buffers\&. \fP" .ti -1c .RI "bool \fBeof\fP ()" .br .RI "\fIIndicates whether we are at the end of the file\&. \fP" .ti -1c .RI "virtual void \fBclose\fP ()" .br .RI "\fICloses the stream, releasing all resources\&. \fP" .ti -1c .RI "\fBByte\fP \fBgetByte\fP (void) throw (InputByteStreamError)" .br .RI "\fIReads a byte from the stream\&. \fP" .ti -1c .RI "const \fBByte\fP * \fBgetBlock\fP (unsigned int length) throw (InputByteStreamError)" .br .RI "\fIRetrieves a block from the current position in the stream\&. \fP" .ti -1c .RI "void \fBskip\fP (unsigned int) throw (InputByteStreamError)" .br .RI "\fISkips a given number of bytes forward in the stream\&. \fP" .ti -1c .RI "signed int \fBgetSIU\fP (int) throw (InputByteStreamError)" .br .RI "\fIObtains an n-byte unsigned integer from the stream, as a signed int\&. \fP" .ti -1c .RI "signed int \fBgetSIS\fP (int) throw (InputByteStreamError)" .br .RI "\fIObtains an n-byte signed integer from the stream, as a signed int\&. \fP" .ti -1c .RI "unsigned int \fBgetUIU\fP (int) throw (InputByteStreamError)" .br .RI "\fIObtains an n-byte unsigned integer from the stream, as an unsigned int\&. \fP" .in -1c .SS "Static Public Member Functions" .in +1c .ti -1c .RI "static unsigned int \fBgetUIU\fP (int, const \fBByte\fP *) throw (InputByteStreamError)" .br .RI "\fIObtains an n-byte unsigned integer from the beginning of a \fCByte\fP array, as an unsigned int\&. \fP" .ti -1c .RI "static void \fBsetDefaultBufferSize\fP (unsigned int length)" .br .RI "\fISets the default buffer size to be used for reading files\&. \fP" .ti -1c .RI "static void \fBverbosity\fP (const \fBverbosities\fP level)" .br .RI "\fISets the verbosity of this module\&. \fP" .ti -1c .RI "static \fBverbosities\fP \fBgetVerbosity\fP (void)" .br .RI "\fIReturns the verbosity setting of this class\&. \fP" .in -1c .SS "Protected Member Functions" .in +1c .ti -1c .RI "\fBInputByteStream\fP ()" .br .RI "\fINo-argument constructor creates a new \fBInputByteStream\fP object, but does not associate it with any source of bytes\&. \fP" .ti -1c .RI "bool \fBbindToFileDescriptor\fP (int fileno, string filename='', int bufsize=0, bool fillBufferAndClose=false, bool assertIsSeekable=false) throw (InputByteStreamError)" .br .RI "\fIBinds this stream to a given file descriptor\&. \fP" .ti -1c .RI "int \fBopenSourceSpec\fP (string srcspec) throw (InputByteStreamError)" .br .RI "\fIOpens a source\&. \fP" .ti -1c .RI "int \fBgetFD\fP (void) const " .br .RI "\fIReturns the file descriptor this stream is bound to\&. \fP" .ti -1c .RI "void \fBbufferSeek\fP (unsigned int pos) throw (InputByteStreamError)" .br .RI "\fISeeks to a specific point in the buffer\&. \fP" .ti -1c .RI "void \fBreloadBuffer\fP (void)" .br .RI "\fIReloads the buffer, presumably after the file descriptor has been adjusted by an extending class\&. \fP" .in -1c .SH "Detailed Description" .PP Abstracts a file as a stream of bytes\&. Functions are provided to read individual bytes from the file and blocks of contiguous bytes\&. .PP Since this class is intended to help reading TeX DVI and PK files, we also provide methods to read signed and unsigned integers from the stream, encoded as described in the DVI driver standard\&. .PP This class is designed to be extended (and is extended in fact in classes \fBFileByteStream\fP and \fBPipeStream\fP)\&. The subclassing interface consists of a no-argument constructor, a method to associate the class with a given file descriptor (\fBbindToFileDescriptor\fP), and a convenience method to help opening files, using the same specification syntax supported by this class (\fBopenSourceSpec\fP)\&. Since one of the main purposes of this subclassing is to support a class which handles a seekable input stream, we also have \fBgetFD\fP to get the file descriptor being handled, and \fBreloadBuffer\fP to indicate to the parent class that the underlying stream has been modified (typically by a \fCseek\fP operation) so that the input buffer should be invalidated\&. If \fCbindToFileDescriptor\fP was invoked with the \fCfillBufferAndClose\fP flag true, then the \fBbufferSeek\fP method allows rapid seeking by simply adjusting the buffer pointer; though this is useless unless the whole stream is in the buffer, the class makes no check on this, and it is the extending class's responsibility to make sure that this is not called inappropriately\&. .SH "Constructor & Destructor Documentation" .PP .SS "InputByteStream::InputByteStream (intfd)\fBInputByteStreamError\fP" .PP Prepares to read a stream from the specified file descriptor, which must be open\&. .PP \fBParameters:\fP .RS 4 \fIfd\fP an open file descriptor .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if there is a problem binding to the descriptor .RE .PP .SS "InputByteStream::InputByteStream (stringsrcspec)\fBInputByteStreamError\fP" .PP Prepares to read a stream from the specified source\&. The source may be .PD 0 .IP "\(bu" 2 a file name, which should be readable .IP "\(bu" 2 a specifier of the form \fCfilename\fP: the specified file is opened .IP "\(bu" 2 a specifier of the form \fCinteger\fP: the integer specifyies an (open) OS file descriptor; thus \fC0\fP opens the standard input .PP .PP \fBParameters:\fP .RS 4 \fIsrcspec\fP a source specification as described above .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if there is a problem opening or binding to the descriptor .RE .PP .SS "InputByteStream::~InputByteStream ()" .PP Closes the file and reclaims any buffers\&. .PP References close()\&. .SS "InputByteStream::InputByteStream ()\fC [protected]\fP" .PP No-argument constructor creates a new \fBInputByteStream\fP object, but does not associate it with any source of bytes\&. To associate it with a source, use \fBbindToFileDescriptor\fP or the convenience method \fBopenSourceSpec\fP\&. .SH "Member Function Documentation" .PP .SS "bool InputByteStream::bindToFileDescriptor (intfileno, stringfilename = \fC''\fP, intbufsize = \fC0\fP, boolfillBufferAndClose = \fCfalse\fP, boolassertIsSeekable = \fCfalse\fP)\fBInputByteStreamError\fP\fC [protected]\fP" .PP Binds this stream to a given file descriptor\&. If the parameter \fCfillBufferAndClose\fP is true, then this method will keep reading from the file descriptor until it reaches either the end of the newly-allocated buffer, or end-of-file, whichever comes first\&. It will then close the file descriptor\&. In this case (and in this case alone), the method \fBbufferSeek\fP becomes useful, and can be used by an extending class to implement an efficient \fCseek\fP operation on the file\&. .PP \fBParameters:\fP .RS 4 \fIfileno\fP the file descriptor to be handled by this object .br \fIfilename\fP the file name associated with this descriptor; this may be the empty string .br \fIbufsize\fP a size suggested for the input buffer, or zero to accept the default .br \fIfillBufferAndClose\fP if true, read the entire contents of the file into memory .br \fIassertIsSeekable\fP if true, the caller is asserting that the given file descriptor points to a seekable object (presumably because it will depend on it being so)\&. If this is not the case (the descriptor refers to a pipe or other non-seekable, and non-mappable, object), then throw an exception\&. If this is false, no assertion is being made; it is not being asserted that the object is non-seekable\&. .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if there is some other problem reading the file; or if a negative buffer size is given; or if the assertion described for parameter \fCassertIsSeekable\fP turns out to be false\&. .RE .PP \fBReturns:\fP .RS 4 true on success .RE .PP .PP References debug, normal, and Util::verbosity_\&. .SS "void InputByteStream::bufferSeek (unsigned intoffset)\fBInputByteStreamError\fP\fC [protected]\fP" .PP Seeks to a specific point in the buffer\&. This is only useful when the buffer holds the complete file, that is, when \fCbindToFileDescriptor\fP was called with parameter \fCfillBufferAndClose\fP true\&. .PP \fBParameters:\fP .RS 4 \fIoffset\fP the offset from the beginning of the buffer, where the current position is relocated to .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if the offset would take the pointer outside the buffer, or if the stream has been closed .RE .PP .PP References debug, and Util::verbosity_\&. .SS "void InputByteStream::close (void)\fC [virtual]\fP" .PP Closes the stream, releasing all resources\&. .PP Reimplemented in \fBPipeStream\fP\&. .PP References normal, and Util::verbosity_\&. .PP Referenced by PipeStream::close(), and ~InputByteStream()\&. .SS "bool InputByteStream::eof ()" .PP Indicates whether we are at the end of the file\&. This method does not return true until \fIafter\fP a failed attempt to read past the end of file; that is, it does not return true immediately after the last byte has been read from the file\&. .PP \fBReturns:\fP .RS 4 true if we are at the end of the file .RE .PP .PP Referenced by DviFile::eof(), and getByte()\&. .SS "const \fBByte\fP * InputByteStream::getBlock (unsigned intlength)\fBInputByteStreamError\fP" .PP Retrieves a block from the current position in the stream\&. Leaves the pointer pointing after the block returned\&. .PP \fBParameters:\fP .RS 4 \fIlength\fP the size of block desired .RE .PP \fBReturns:\fP .RS 4 a pointer to a block of bytes .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if the requested number of bytes cannot be read, which includes the case of this method being called when \fC\fBeof()\fP\fP is true .RE .PP .SS "\fBByte\fP InputByteStream::getByte (void)\fBInputByteStreamError\fP" .PP Reads a byte from the stream\&. Increments the reading pointer\&. This method does not signal an error at end-of-file; if \fBeof\fP is true or \fIbecomes\fP true as a result of this attempt to read past the end of the file, then we return zero\&. That is, \fC\fBeof()\fP\fP does not return true immediately the last byte in the file has been read\&. .PP \fBReturns:\fP .RS 4 the byte read, or zero if we are at the end of the file .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if there is some problem reading the stream .RE .PP .PP References eof()\&. .SS "int InputByteStream::getFD (void) const\fC [inline]\fP, \fC [protected]\fP" .PP Returns the file descriptor this stream is bound to\&. If there is no open descriptor (see the \fCfillBufferAndClose\fP parameter to \fBbindToFileDescriptor\fP), returns negative\&. .PP \fBReturns:\fP .RS 4 the file descriptor, or negative if the descriptor has been closed .RE .PP .SS "signed int InputByteStream::getSIS (intn)\fBInputByteStreamError\fP" .PP Obtains an n-byte signed integer from the stream, as a signed int\&. .PP \fBParameters:\fP .RS 4 \fIn\fP the number of bytes to read, in the range 1--4 inclusive .RE .PP \fBReturns:\fP .RS 4 the next integer from the input stream, as a signed int .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if parameter \fCn\fP was out of range .RE .PP .SS "signed int InputByteStream::getSIU (intn)\fBInputByteStreamError\fP" .PP Obtains an n-byte unsigned integer from the stream, as a signed int\&. .PP \fBParameters:\fP .RS 4 \fIn\fP the number of bytes to read, in the range 1--3 inclusive (there are no 4-byte unsigned quantities in DVI files) .RE .PP \fBReturns:\fP .RS 4 the next integer from the input stream, as a signed int .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if parameter \fCn\fP was out of range .RE .PP .SS "unsigned int InputByteStream::getUIU (intn)\fBInputByteStreamError\fP" .PP Obtains an n-byte unsigned integer from the stream, as an unsigned int\&. .PP \fBParameters:\fP .RS 4 \fIn\fP the number of bytes to read, in the range 1--4 inclusive .RE .PP \fBReturns:\fP .RS 4 the next integer from the input stream, as an unsigned int .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if parameter \fCn\fP was out of range .RE .PP .SS "unsigned int InputByteStream::getUIU (intn, const \fBByte\fP *p)\fBInputByteStreamError\fP\fC [static]\fP" .PP Obtains an n-byte unsigned integer from the beginning of a \fCByte\fP array, as an unsigned int\&. This has little specifically to do with Input streams, and is here as a convenience method\&. .PP \fBParameters:\fP .RS 4 \fIn\fP the number of bytes to read, in the range 1--4 inclusive .br \fIp\fP a pointer to an array of \fCByte\fP values .RE .PP \fBReturns:\fP .RS 4 the integer at the beginning of the given array, as an unsigned int .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if parameter \fCn\fP was out of range .RE .PP .SS "static \fBverbosities\fP InputByteStream::getVerbosity (void)\fC [inline]\fP, \fC [static]\fP" .PP Returns the verbosity setting of this class\&. .PP Referenced by PipeStreamSignalHandling::expectAnother(), and PipeStreamSignalHandling::got_status()\&. .SS "int InputByteStream::openSourceSpec (stringsrcspec)\fBInputByteStreamError\fP\fC [protected]\fP" .PP Opens a source\&. The source is specified as in \fBInputByteStream(string)\fP\&. Throws an exception on any problems, so that if it returns, it has successfully opened the file, or determined that the file descriptor is (syntactically) valid\&. .PP \fBParameters:\fP .RS 4 \fIsrcspec\fP a source specification .RE .PP \fBReturns:\fP .RS 4 an open file descriptor .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if there is any problem opening the file .RE .PP .PP References normal, and Util::verbosity_\&. .SS "void InputByteStream::reloadBuffer (void)\fC [protected]\fP" .PP Reloads the buffer, presumably after the file descriptor has been adjusted by an extending class\&. .PP References debug, and Util::verbosity_\&. .SS "void InputByteStream::setDefaultBufferSize (unsigned intlength)\fC [static]\fP" .PP Sets the default buffer size to be used for reading files\&. .PP \fBParameters:\fP .RS 4 \fIlength\fP the size, in bytes, of the input buffer .RE .PP .SS "void InputByteStream::skip (unsigned intincrement)\fBInputByteStreamError\fP" .PP Skips a given number of bytes forward in the stream\&. .PP \fBParameters:\fP .RS 4 \fIincrement\fP the number of bytes to move forward in the stream .RE .PP \fBExceptions:\fP .RS 4 \fI\fBInputByteStreamError\fP\fP if we skip past the end of file .RE .PP .SS "static void InputByteStream::verbosity (const \fBverbosities\fPlevel)\fC [inline]\fP, \fC [static]\fP" .PP Sets the verbosity of this module\&. .PP \fBParameters:\fP .RS 4 \fIlevel\fP the required verbosity .RE .PP .PP Referenced by main()\&. .SH "Author" .PP Generated automatically by Doxygen for dvi2bitmap from the source code\&.