Changeset 8003 for trunk/tools/common/kFile.h
- Timestamp:
- Feb 24, 2002, 3:47:28 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFile.h
r7093 r8003 1 /* $Id: kFile.h,v 1. 9 2001-10-17 14:22:33bird Exp $1 /* $Id: kFile.h,v 1.10 2002-02-24 02:47:24 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 22 22 class kFile 23 23 { 24 /** @cat constructors */ 25 private: 26 #ifndef __OS2DEFS__ 27 kFile(unsigned long hFile, KBOOL fReadOnly); 28 #else 29 kFile(HFILE hFile, KBOOL fReadOnly); 30 #endif 31 public: 32 kFile(const char *pszFilename, KBOOL fReadOnly = TRUE) throw(kError); 33 ~kFile(); 34 35 /** @cat File I/O methods */ 36 int read(void *pvBuffer, long cbBuffer) throw(kError); 37 int readAt(void *pvBuffer, long cbBuffer, long off) throw(kError); 38 int readln(char *pszBuffer, long cchBuffer); 39 40 int write(const void *pvBuffer, long cbBuffer) throw(kError); 41 int writeAt(const void *pvBuffer, long cbBuffer, long off) throw(kError); 42 43 int printf(const char *pszFormat, ...) throw(kError); 44 45 int setSize(unsigned long cbFile = ~0UL); 46 47 kFile & operator+=(kFile &AppendFile); 48 49 void * mapFile() throw(kError); 50 static void * mapFile(const char *pszFilename) throw(kError); 51 static void mapFree(void *pvFileMapping) throw(kError); 52 53 54 /** @cat File seek methods */ 55 int move(long off) throw(kError); 56 int set(long off) throw(kError); 57 int end() throw(kError); 58 int start(); 59 60 /** @cat Query methods */ 61 long getSize() throw(kError); 62 long getPos() const throw(kError); 63 KBOOL isEOF() throw(kError); 64 const char * getFilename() { return pszFilename; } 65 66 /** @cat Error handling */ 67 void setThrowOnErrors(); 68 void setFailOnErrors(); 69 int getLastError() const; 70 71 /** standard files */ 72 static kFile StdOut; 73 static kFile StdIn; 74 static kFile StdErr; 75 76 24 77 protected: 25 78 /** @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. */ 79 KBOOL fReadOnly; /* True if readonly access, False is readwrite. */ 80 KBOOL fStdDev; /* True if stdio, stderr or stdin. Filestatus is invalid with this is set.*/ 81 unsigned long rc; /* Last error (return code). */ 82 KBOOL fStatusClean; /* True if filestatus is clean. False is not clean */ 83 KBOOL fThrowErrors; /* When true we'll throw the rc on errors, else return FALSE. */ 84 char * pszFilename; /* Pointer to filename. */ 34 85 35 86 /** @cat Position datamembers */ … … 42 93 unsigned long offBuffer; /* Virtual file offset where the buffer starts. */ 43 94 unsigned long cbBufferValid; /* Count of valid bytes in the buffer. */ 44 BOOL fBufferDirty; /* Dirty flag. Set when the buffer needs to be committed. */ 95 KBOOL fBufferDirty; /* Dirty flag. Set when the buffer needs to be committed. */ 96 97 /** @cat OS specific data */ 98 union _kFileOSSpecific 99 { 100 char achFiller[14+2 + 16]; /* OS2 uses 16 bytes currently. Add 16-bytes just in case. */ 101 #ifdef __OS2DEF__ 102 struct _kFileOS2 103 { 104 HFILE hFile; /* Pointer to stdio filehandle */ 105 FILESTATUS4 filestatus; /* Filestatus data. */ 106 } os2; 107 #endif 108 } OSData; 45 109 46 110 /** @cat internal buffer methods */ 47 BOOL bufferRead(ULONG offFile) throw (int);48 BOOL bufferCommit(void) throw (int);111 KBOOL bufferRead(unsigned long offFile) throw(kError); 112 KBOOL bufferCommit(void) throw(kError); 49 113 50 114 /** @cat internal methods for maintaing internal structures. */ 51 BOOL refreshFileStatus() throw(int);52 BOOL position() throw(int);115 KBOOL refreshFileStatus() throw(kError); 116 KBOOL position() throw(kError); 53 117 54 /** @cat constructors */55 private:56 kFile(HFILE hFile, BOOL fReadOnly);57 public:58 kFile(const char *pszFilename, BOOL fReadOnly = TRUE) throw(int);59 ~kFile();60 61 /** @cat File I/O methods */62 BOOL read(void *pvBuffer, long cbBuffer) throw(int);63 BOOL readAt(void *pvBuffer, long cbBuffer, long off) throw(int);64 void * readFile() throw(int);65 static void * readFile(const char *pszFilename) throw(int);66 BOOL readln(char *pszBuffer, long cchBuffer);67 68 BOOL write(const void *pv, long cb) throw(int);69 BOOL writeAt(void *pvBuffer, long cbBuffer, long off) throw(int);70 71 int printf(const char *pszFormat, ...) throw (int);72 73 BOOL setSize(unsigned long cbFile = ~0UL);74 75 kFile & operator+=(kFile &AppendFile);76 77 /** @cat File seek methods */78 BOOL move(long off) throw(int);79 BOOL set(long off) throw(int);80 BOOL end() throw(int);81 BOOL start();82 83 /** @cat Query methods */84 long getSize() throw(int);85 long getPos() const throw(int);86 BOOL isEOF() throw(int);87 const char * getFilename() { return pszFilename; }88 89 /** @cat Error handling */90 BOOL setThrowOnErrors();91 BOOL setFailOnErrors();92 int getLastError() const;93 94 /** standard files */95 static kFile StdOut;96 static kFile StdIn;97 static kFile StdErr;98 118 }; 99 119
Note:
See TracChangeset
for help on using the changeset viewer.