1 | /* $Id: kFile.h,v 1.5 2000-10-02 04:01:39 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 | BOOL fStdDev; /* True if stdio, stderr or stdin. Filestatus is invalid with this is set.*/
|
---|
29 | APIRET rc; /* Last error (return code). */
|
---|
30 | FILESTATUS4 filestatus; /* Filestatus data. */
|
---|
31 | BOOL fStatusClean; /* True if filestatus is clean. False is not clean */
|
---|
32 | BOOL fThrowErrors; /* When true we'll throw the rc on errors, else return FALSE. */
|
---|
33 | PSZ pszFilename; /* Pointer to filename. */
|
---|
34 |
|
---|
35 | /** @cat Position datamembers */
|
---|
36 | unsigned long offVirtual; /* Virtual file position - lazy set. */
|
---|
37 | unsigned long offReal; /* Real file position. */
|
---|
38 |
|
---|
39 | /** @cat Buffering datamembers */
|
---|
40 |
|
---|
41 | /** @cat internal methods for maintaing internal structures. */
|
---|
42 | BOOL refreshFileStatus() throw(int);
|
---|
43 | BOOL position() throw(int);
|
---|
44 |
|
---|
45 | /** @cat constructors */
|
---|
46 | private:
|
---|
47 | kFile(HFILE hFile, BOOL fReadOnly);
|
---|
48 | public:
|
---|
49 | kFile(const char *pszFilename, BOOL fReadOnly = TRUE) throw(int);
|
---|
50 | ~kFile();
|
---|
51 |
|
---|
52 | /** @cat File I/O methods */
|
---|
53 | BOOL read(void *pvBuffer, long cbBuffer) throw(int);
|
---|
54 | BOOL readAt(void *pvBuffer, long cbBuffer, long off) throw(int);
|
---|
55 | void * readFile() throw(int);
|
---|
56 |
|
---|
57 | BOOL write(void *pvBuffer, long cbBuffer) throw(int);
|
---|
58 | BOOL writeAt(void *pvBuffer, long cbBuffer, long off) throw(int);
|
---|
59 |
|
---|
60 | int printf(const char *pszFormat, ...) throw (int);
|
---|
61 |
|
---|
62 | BOOL setSize(unsigned long cbFile = ~0UL);
|
---|
63 |
|
---|
64 | /** @cat File seek methods */
|
---|
65 | BOOL move(long off) throw(int);
|
---|
66 | BOOL set(long off) throw(int);
|
---|
67 | BOOL end() throw(int);
|
---|
68 | BOOL start();
|
---|
69 |
|
---|
70 | /** @cat Query methods */
|
---|
71 | long getSize() throw(int);
|
---|
72 | long getPos() const throw(int);
|
---|
73 | BOOL isEOF() throw(int);
|
---|
74 | const char * getFilename() { return pszFilename; }
|
---|
75 |
|
---|
76 | /** @cat Error handling */
|
---|
77 | BOOL setThrowOnErrors();
|
---|
78 | BOOL setFailOnErrors();
|
---|
79 | int getLastError() const;
|
---|
80 |
|
---|
81 | /** standard files */
|
---|
82 | static kFile StdOut;
|
---|
83 | static kFile StdIn;
|
---|
84 | static kFile StdErr;
|
---|
85 | };
|
---|
86 |
|
---|
87 | #endif
|
---|
88 |
|
---|