source: trunk/tools/common/kFile.h@ 4402

Last change on this file since 4402 was 4402, checked in by bird, 25 years ago

Implemented .Def to WLINK directives/options converter.

File size: 3.0 KB
Line 
1/* $Id: kFile.h,v 1.6 2000-10-03 05:42:38 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 */
22class kFile
23{
24protected:
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 */
46private:
47 kFile(HFILE hFile, BOOL fReadOnly);
48public:
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 BOOL readln(char *pszBuffer, long cchBuffer);
57
58 BOOL write(void *pvBuffer, long cbBuffer) throw(int);
59 BOOL writeAt(void *pvBuffer, long cbBuffer, long off) throw(int);
60
61 int printf(const char *pszFormat, ...) throw (int);
62
63 BOOL setSize(unsigned long cbFile = ~0UL);
64
65 kFile & operator+=(kFile &AppendFile);
66
67 /** @cat File seek methods */
68 BOOL move(long off) throw(int);
69 BOOL set(long off) throw(int);
70 BOOL end() throw(int);
71 BOOL start();
72
73 /** @cat Query methods */
74 long getSize() throw(int);
75 long getPos() const throw(int);
76 BOOL isEOF() throw(int);
77 const char * getFilename() { return pszFilename; }
78
79 /** @cat Error handling */
80 BOOL setThrowOnErrors();
81 BOOL setFailOnErrors();
82 int getLastError() const;
83
84 /** standard files */
85 static kFile StdOut;
86 static kFile StdIn;
87 static kFile StdErr;
88};
89
90#endif
91
Note: See TracBrowser for help on using the repository browser.