1 | /* $Id: kFile.h,v 1.2 2000-05-27 02:14:21 bird Exp $
|
---|
2 | *
|
---|
3 | * kFile - Simple (for the time being) file class.
|
---|
4 | *
|
---|
5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | #ifndef _kFile_h_
|
---|
12 | #define _kFile_h_
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Simple file class.
|
---|
18 | * It uses a lazy algorithm for chaning the file position.
|
---|
19 | * It is extenable to do buffered reading too.
|
---|
20 | * @author knut st. osmundsen
|
---|
21 | */
|
---|
22 | class kFile
|
---|
23 | {
|
---|
24 | protected:
|
---|
25 | /** @cat Main datamembers */
|
---|
26 | HFILE hFile; /* Pointer to stdio filehandle */
|
---|
27 | BOOL fReadOnly; /* True if readonly access, False is readwrite. */
|
---|
28 | int rc; /* Last error (return code). */
|
---|
29 | FILESTATUS4 filestatus; /* Filestatus data. */
|
---|
30 | BOOL fStatusClean; /* True if filestatus is clean. False is not clean */
|
---|
31 | BOOL fThrowErrors; /* When true we'll throw the rc on errors, else return FALSE. */
|
---|
32 |
|
---|
33 | /** @cat Position datamembers */
|
---|
34 | unsigned long offVirtual; /* Virtual file position - lazy set. */
|
---|
35 | unsigned long offReal; /* Real file position. */
|
---|
36 |
|
---|
37 | /** @cat Buffering datamembers */
|
---|
38 |
|
---|
39 | /** @cat internal methods for maintaing internal structures. */
|
---|
40 | BOOL refreshFileStatus() throw(int);
|
---|
41 | BOOL position() throw(int);
|
---|
42 |
|
---|
43 | public:
|
---|
44 | /** @cat constructor */
|
---|
45 | kFile(const char *pszFilename, BOOL fReadOnly = TRUE) throw(int);
|
---|
46 | ~kFile();
|
---|
47 |
|
---|
48 | /** @cat File I/O methods */
|
---|
49 | BOOL read(void *pvBuffer, long cbBuffer) throw(int);
|
---|
50 | BOOL readAt(void *pvBuffer, long cbBuffer, long off) throw(int);
|
---|
51 |
|
---|
52 | BOOL write(void *pvBuffer, long cbBuffer) throw(int);
|
---|
53 | BOOL writeAt(void *pvBuffer, long cbBuffer, long off) throw(int);
|
---|
54 |
|
---|
55 | /** @cat File seek methods */
|
---|
56 | BOOL move(long off) throw(int);
|
---|
57 | BOOL set(long off) throw(int);
|
---|
58 | BOOL end() throw(int);
|
---|
59 | BOOL start();
|
---|
60 |
|
---|
61 | /** @cat Query methods */
|
---|
62 | long getSize() throw(int);
|
---|
63 | long getPos() const throw(int);
|
---|
64 | BOOL isEOF() throw(int);
|
---|
65 |
|
---|
66 | /** @cat Error handling */
|
---|
67 | BOOL setThrowOnErrors();
|
---|
68 | BOOL setFailOnErrors();
|
---|
69 | int getLastError() const;
|
---|
70 | };
|
---|
71 |
|
---|
72 | #endif
|
---|
73 |
|
---|