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 | // some elderly windows compilers need to include <vector> (or something
|
---|
28 | // similar) here so that they know what a "bool" is
|
---|
29 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
30 | # include <ospace\std\vector>
|
---|
31 | #elif defined(GSDL_USE_STL_H)
|
---|
32 | # include <vector.h>
|
---|
33 | #else
|
---|
34 | # include <vector>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 |
|
---|
38 | class FileBuf {
|
---|
39 | protected:
|
---|
40 | unsigned char buf[FILEBUFSIZE];
|
---|
41 | unsigned char *here;
|
---|
42 | unsigned char *end;
|
---|
43 |
|
---|
44 | int fd;
|
---|
45 |
|
---|
46 | // gets a new buffer if need be, returns true if
|
---|
47 | // more could be got. if true is returned the caller
|
---|
48 | // can assume that here != end
|
---|
49 | bool NextBuf ();
|
---|
50 |
|
---|
51 | public:
|
---|
52 | FileBuf ();
|
---|
53 |
|
---|
54 | void SetFD (int _fd);
|
---|
55 |
|
---|
56 | inline bool Get (unsigned char &c) {
|
---|
57 | if (here != end || NextBuf()) { c = *here++; return true; }
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 |
|
---|
61 | inline bool Peek (unsigned char &c) {
|
---|
62 | if (here != end || NextBuf()) { c = *here; return true; }
|
---|
63 | return false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | inline bool Next () {
|
---|
67 | if (here != end || NextBuf()) { ++here; return true; }
|
---|
68 | return false;
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | #endif
|
---|