dvi2bitmap dvi2bitmap1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

InputByteStream.h
Go to the documentation of this file.
1 /* This file is part of dvi2bitmap; see README for copyrights and licence */
2
3 #ifndef INPUT_BYTE_STREAM_HEADER_READ
4 #define INPUT_BYTE_STREAM_HEADER_READ 1
5
6 #include <Byte.h>
7 #include <DviError.h>
8 #include <verbosity.h>
9
10 #include <string>
11
12 class InputByteStreamError : public DviError {
13 public:
14 InputByteStreamError(string s) : DviError(s) { }
15 };
16
47 class InputByteStream {
48
49 public:
50 InputByteStream(int fileno)
51 throw (InputByteStreamError);
52 InputByteStream(string srcspec)
53 throw (InputByteStreamError);
54 ~InputByteStream();
55
56 bool eof();
57 virtual void close();
58 Byte getByte(void)
59 throw (InputByteStreamError);
60 const Byte *getBlock(unsigned int length)
61 throw (InputByteStreamError);
62 void skip (unsigned int)
63 throw (InputByteStreamError);
64
65 signed int getSIU(int)
66 throw (InputByteStreamError);
67 signed int getSIS(int)
68 throw (InputByteStreamError);
69 unsigned int getUIU(int)
70 throw (InputByteStreamError);
71 /*
72 * static getUIU reads from an array, rather than the file (ie,
73 * it's really nothing to do with InputByteStream, but it's here
74 * for consistency.
75 */
76 static unsigned int getUIU(int, const Byte *)
77 throw (InputByteStreamError);
78 static void setDefaultBufferSize(unsigned int length);
83 static inline void verbosity (const verbosities level) {
84 verbosity_ = level;
85 }
89 static verbosities getVerbosity(void) { return verbosity_; };
90
91 protected:
92 InputByteStream();
93 bool bindToFileDescriptor(int fileno,
94 string filename="",
95 int bufsize=0,
96 bool fillBufferAndClose=false,
97 bool assertIsSeekable=false)
98 throw (InputByteStreamError);
99 int openSourceSpec(string srcspec)
100 throw (InputByteStreamError);
109 int getFD(void) const { return fd_; }
110 void bufferSeek(unsigned int pos)
111 throw (InputByteStreamError);
112 void reloadBuffer(void);
113
114 private:
115 int fd_; /* file descriptor of handled file/pipe */
116 int mappedfd_; /* saved file descriptor of mapped file */
117 string fname_; /* name of file, or string rep'n of fd */
118 Byte *buf_; /* buffer */
119 size_t buflen_; /* size of buffer */
120 Byte *p_; /* current position in buffer */
121 Byte *eob_; /* end of buffer */
122 bool eof_; /* true on end of file (note this is from
123 the client's point of view, not the class's:
124 if we have `preloaded' a file, the
125 underlying file will be closed, but there
126 will still be more to read from the
127 stream) */
128 void read_buf_(void)
129 throw (InputByteStreamError);
130 size_t certainly_read_(int fd, Byte *b, size_t len)
131 throw (InputByteStreamError);
132
133 static verbosities verbosity_;
134 static unsigned int default_buffer_length_;
135 };
136
137 #endif /* INPUT_BYTE_STREAM_HEADER_READ */