|
0
|
1 |
// Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca>
|
|
|
2 |
//
|
|
|
3 |
// This program is free software; you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation; either version 2 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// This program is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with this program; if not, write to the Free Software
|
|
|
15 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
16 |
|
|
|
17 |
#ifndef FDBUF__FDIBUF__H__
|
|
|
18 |
#define FDBUF__FDIBUF__H__
|
|
|
19 |
|
|
|
20 |
class fdibuf : protected fdbuf
|
|
|
21 |
{
|
|
|
22 |
public:
|
|
|
23 |
fdibuf(const char* filename, unsigned bufsz = FDBUF_SIZE);
|
|
|
24 |
fdibuf(int fdesc, bool dc = false, unsigned bufsz = FDBUF_SIZE);
|
|
|
25 |
virtual ~fdibuf();
|
|
|
26 |
bool close() { lock(); bool r = fdbuf::close(); unlock(); return r; }
|
|
|
27 |
bool eof() const;
|
|
|
28 |
bool operator!() const ;
|
|
|
29 |
operator bool() const { return !operator!(); }
|
|
|
30 |
virtual bool get(char& ch);
|
|
|
31 |
virtual bool getline(mystring& out, char terminator = '\n');
|
|
|
32 |
virtual bool getnetstring(mystring& out);
|
|
|
33 |
virtual bool read(char*, unsigned);
|
|
|
34 |
virtual bool read_large(char*, unsigned);
|
|
|
35 |
bool read(unsigned char* b, unsigned l) { return read((char*)b, l); }
|
|
|
36 |
bool read(signed char* b, unsigned l) { return read((char*)b, l); }
|
|
|
37 |
unsigned last_count() { return count; }
|
|
|
38 |
bool seek(unsigned o);
|
|
|
39 |
bool seekfwd(unsigned o);
|
|
|
40 |
bool rewind() { return seek(0); }
|
|
|
41 |
unsigned tell() const { return offset-buflength+bufstart; }
|
|
|
42 |
int error_number() const { return errnum; }
|
|
|
43 |
protected:
|
|
|
44 |
unsigned count; // Number of bytes read by last operation
|
|
|
45 |
bool refill();
|
|
|
46 |
};
|
|
|
47 |
|
|
|
48 |
extern fdibuf fin;
|
|
|
49 |
|
|
|
50 |
#endif // FDBUF__FDIBUF__H__
|