| 1 | /* $Id: kFile.h,v 1.4 2000-08-31 03:00:13 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 | APIRET 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 | PSZ pszFilename; /* Pointer to filename. */
|
|---|
| 33 |
|
|---|
| 34 | /** @cat Position datamembers */
|
|---|
| 35 | unsigned long offVirtual; /* Virtual file position - lazy set. */
|
|---|
| 36 | unsigned long offReal; /* Real file position. */
|
|---|
| 37 |
|
|---|
| 38 | /** @cat Buffering datamembers */
|
|---|
| 39 |
|
|---|
| 40 | /** @cat internal methods for maintaing internal structures. */
|
|---|
| 41 | BOOL refreshFileStatus() throw(int);
|
|---|
| 42 | BOOL position() throw(int);
|
|---|
| 43 |
|
|---|
| 44 | public:
|
|---|
| 45 | /** @cat constructor */
|
|---|
| 46 | kFile(const char *pszFilename, BOOL fReadOnly = TRUE) throw(int);
|
|---|
| 47 | ~kFile();
|
|---|
| 48 |
|
|---|
| 49 | /** @cat File I/O methods */
|
|---|
| 50 | BOOL read(void *pvBuffer, long cbBuffer) throw(int);
|
|---|
| 51 | BOOL readAt(void *pvBuffer, long cbBuffer, long off) throw(int);
|
|---|
| 52 | void * readFile() throw(int);
|
|---|
| 53 |
|
|---|
| 54 | BOOL write(void *pvBuffer, long cbBuffer) throw(int);
|
|---|
| 55 | BOOL writeAt(void *pvBuffer, long cbBuffer, long off) throw(int);
|
|---|
| 56 |
|
|---|
| 57 | int printf(const char *pszFormat, ...) throw (int);
|
|---|
| 58 |
|
|---|
| 59 | BOOL setSize(unsigned long cbFile = ~0UL);
|
|---|
| 60 |
|
|---|
| 61 | /** @cat File seek methods */
|
|---|
| 62 | BOOL move(long off) throw(int);
|
|---|
| 63 | BOOL set(long off) throw(int);
|
|---|
| 64 | BOOL end() throw(int);
|
|---|
| 65 | BOOL start();
|
|---|
| 66 |
|
|---|
| 67 | /** @cat Query methods */
|
|---|
| 68 | long getSize() throw(int);
|
|---|
| 69 | long getPos() const throw(int);
|
|---|
| 70 | BOOL isEOF() throw(int);
|
|---|
| 71 | const char * getFilename() { return pszFilename; }
|
|---|
| 72 |
|
|---|
| 73 | /** @cat Error handling */
|
|---|
| 74 | BOOL setThrowOnErrors();
|
|---|
| 75 | BOOL setFailOnErrors();
|
|---|
| 76 | int getLastError() const;
|
|---|
| 77 | };
|
|---|
| 78 |
|
|---|
| 79 | #endif
|
|---|
| 80 |
|
|---|