source: trunk/gsdl/src/mgpp/text/FileBuf.h@ 855

Last change on this file since 855 was 855, checked in by sjboddie, 24 years ago

Rodgers new C++ mg

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
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 * $Id: FileBuf.h 855 2000-01-14 02:17:52Z sjboddie $
21 *
22 **************************************************************************/
23
24#ifndef FILEBUF_H
25#define FILEBUF_H
26
27#define FILEBUFSIZE 65536
28
29
30class FileBuf {
31protected:
32 unsigned char buf[FILEBUFSIZE];
33 unsigned char *here;
34 unsigned char *end;
35
36 int fd;
37
38 // gets a new buffer if need be, returns true if
39 // more could be got. if true is returned the caller
40 // can assume that here != end
41 bool NextBuf ();
42
43public:
44 FileBuf ();
45
46 void SetFD (int _fd);
47
48 inline bool Get (unsigned char &c) {
49 if (here != end || NextBuf()) { c = *here++; return true; }
50 return false;
51 }
52
53 inline bool Peek (unsigned char &c) {
54 if (here != end || NextBuf()) { c = *here; return true; }
55 return false;
56 }
57
58 inline bool Next () {
59 if (here != end || NextBuf()) { here++; return true; }
60 return false;
61 }
62};
63
64
65#endif
Note: See TracBrowser for help on using the repository browser.