1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * FileBuf.h -- File buffer
|
---|
4 | * Copyright (C) 1999 Rodger McNab
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | **************************************************************************/
|
---|
21 |
|
---|
22 | #ifndef FILEBUF_H
|
---|
23 | #define FILEBUF_H
|
---|
24 |
|
---|
25 | #define FILEBUFSIZE 65536
|
---|
26 |
|
---|
27 |
|
---|
28 | class FileBuf {
|
---|
29 | protected:
|
---|
30 | unsigned char buf[FILEBUFSIZE];
|
---|
31 | unsigned char *here;
|
---|
32 | unsigned char *end;
|
---|
33 |
|
---|
34 | int fd;
|
---|
35 |
|
---|
36 | // gets a new buffer if need be, returns true if
|
---|
37 | // more could be got. if true is returned the caller
|
---|
38 | // can assume that here != end
|
---|
39 | bool NextBuf ();
|
---|
40 |
|
---|
41 | public:
|
---|
42 | FileBuf ();
|
---|
43 |
|
---|
44 | void SetFD (int _fd);
|
---|
45 |
|
---|
46 | inline bool Get (unsigned char &c) {
|
---|
47 | if (here != end || NextBuf()) { c = *here++; return true; }
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 |
|
---|
51 | inline bool Peek (unsigned char &c) {
|
---|
52 | if (here != end || NextBuf()) { c = *here; return true; }
|
---|
53 | return false;
|
---|
54 | }
|
---|
55 |
|
---|
56 | inline bool Next () {
|
---|
57 | if (here != end || NextBuf()) { here++; return true; }
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 | };
|
---|
61 |
|
---|
62 |
|
---|
63 | #endif
|
---|