2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
33 ==============================================================
37 ==============================================================
47 class idFileSystemLocal;
52 virtual ~idFile( void ) {};
53 // Get the name of the file.
54 virtual const char * GetName( void );
55 // Get the full file path.
56 virtual const char * GetFullPath( void );
57 // Read data from the file to the buffer.
58 virtual int Read( void *buffer, int len );
59 // Write data from the buffer to the file.
60 virtual int Write( const void *buffer, int len );
61 // Returns the length of the file.
62 virtual int Length( void );
63 // Return a time value for reload operations.
64 virtual ID_TIME_T Timestamp( void );
65 // Returns offset in file.
66 virtual int Tell( void );
67 // Forces flush on files being writting to.
68 virtual void ForceFlush( void );
69 // Causes any buffered data to be written to the file.
70 virtual void Flush( void );
72 virtual int Seek( long offset, fsOrigin_t origin );
73 // Go back to the beginning of the file.
74 virtual void Rewind( void );
76 virtual int Printf( const char *fmt, ... ) id_attribute((format(printf,2,3)));
77 // Like fprintf but with argument pointer
78 virtual int VPrintf( const char *fmt, va_list arg );
79 // Write a string with high precision floating point numbers to the file.
80 virtual int WriteFloatString( const char *fmt, ... ) id_attribute((format(printf,2,3)));
82 // Endian portable alternatives to Read(...)
83 virtual int ReadInt( int &value );
84 virtual int ReadUnsignedInt( unsigned int &value );
85 virtual int ReadShort( short &value );
86 virtual int ReadUnsignedShort( unsigned short &value );
87 virtual int ReadChar( char &value );
88 virtual int ReadUnsignedChar( unsigned char &value );
89 virtual int ReadFloat( float &value );
90 virtual int ReadBool( bool &value );
91 virtual int ReadString( idStr &string );
92 virtual int ReadVec2( idVec2 &vec );
93 virtual int ReadVec3( idVec3 &vec );
94 virtual int ReadVec4( idVec4 &vec );
95 virtual int ReadVec6( idVec6 &vec );
96 virtual int ReadMat3( idMat3 &mat );
98 // Endian portable alternatives to Write(...)
99 virtual int WriteInt( const int value );
100 virtual int WriteUnsignedInt( const unsigned int value );
101 virtual int WriteShort( const short value );
102 virtual int WriteUnsignedShort( unsigned short value );
103 virtual int WriteChar( const char value );
104 virtual int WriteUnsignedChar( const unsigned char value );
105 virtual int WriteFloat( const float value );
106 virtual int WriteBool( const bool value );
107 virtual int WriteString( const char *string );
108 virtual int WriteVec2( const idVec2 &vec );
109 virtual int WriteVec3( const idVec3 &vec );
110 virtual int WriteVec4( const idVec4 &vec );
111 virtual int WriteVec6( const idVec6 &vec );
112 virtual int WriteMat3( const idMat3 &mat );
116 class idFile_Memory : public idFile {
117 friend class idFileSystemLocal;
120 idFile_Memory( void ); // file for writing without name
121 idFile_Memory( const char *name ); // file for writing
122 idFile_Memory( const char *name, char *data, int length ); // file for writing
123 idFile_Memory( const char *name, const char *data, int length ); // file for reading
124 virtual ~idFile_Memory( void );
126 virtual const char * GetName( void ) { return name.c_str(); }
127 virtual const char * GetFullPath( void ) { return name.c_str(); }
128 virtual int Read( void *buffer, int len );
129 virtual int Write( const void *buffer, int len );
130 virtual int Length( void );
131 virtual ID_TIME_T Timestamp( void );
132 virtual int Tell( void );
133 virtual void ForceFlush( void );
134 virtual void Flush( void );
135 virtual int Seek( long offset, fsOrigin_t origin );
137 // changes memory file to read only
138 virtual void MakeReadOnly( void );
140 virtual void Clear( bool freeMemory = true );
141 // set data for reading
142 void SetData( const char *data, int length );
143 // returns const pointer to the memory buffer
144 const char * GetDataPtr( void ) const { return filePtr; }
145 // set the file granularity
146 void SetGranularity( int g ) { assert( g > 0 ); granularity = g; }
149 idStr name; // name of the file
150 int mode; // open mode
151 int maxSize; // maximum size of file
152 int fileSize; // size of the file
153 int allocated; // allocated size
154 int granularity; // file granularity
155 char * filePtr; // buffer holding the file data
156 char * curPtr; // current read/write pointer
160 class idFile_BitMsg : public idFile {
161 friend class idFileSystemLocal;
164 idFile_BitMsg( idBitMsg &msg );
165 idFile_BitMsg( const idBitMsg &msg );
166 virtual ~idFile_BitMsg( void );
168 virtual const char * GetName( void ) { return name.c_str(); }
169 virtual const char * GetFullPath( void ) { return name.c_str(); }
170 virtual int Read( void *buffer, int len );
171 virtual int Write( const void *buffer, int len );
172 virtual int Length( void );
173 virtual ID_TIME_T Timestamp( void );
174 virtual int Tell( void );
175 virtual void ForceFlush( void );
176 virtual void Flush( void );
177 virtual int Seek( long offset, fsOrigin_t origin );
180 idStr name; // name of the file
181 int mode; // open mode
186 class idFile_Permanent : public idFile {
187 friend class idFileSystemLocal;
190 idFile_Permanent( void );
191 virtual ~idFile_Permanent( void );
193 virtual const char * GetName( void ) { return name.c_str(); }
194 virtual const char * GetFullPath( void ) { return fullPath.c_str(); }
195 virtual int Read( void *buffer, int len );
196 virtual int Write( const void *buffer, int len );
197 virtual int Length( void );
198 virtual ID_TIME_T Timestamp( void );
199 virtual int Tell( void );
200 virtual void ForceFlush( void );
201 virtual void Flush( void );
202 virtual int Seek( long offset, fsOrigin_t origin );
204 // returns file pointer
205 FILE * GetFilePtr( void ) { return o; }
208 idStr name; // relative path of the file - relative path
209 idStr fullPath; // full file path - OS path
210 int mode; // open mode
211 int fileSize; // size of the file
212 FILE * o; // file handle
213 bool handleSync; // true if written data is immediately flushed
217 class idFile_InZip : public idFile {
218 friend class idFileSystemLocal;
221 idFile_InZip( void );
222 virtual ~idFile_InZip( void );
224 virtual const char * GetName( void ) { return name.c_str(); }
225 virtual const char * GetFullPath( void ) { return fullPath.c_str(); }
226 virtual int Read( void *buffer, int len );
227 virtual int Write( const void *buffer, int len );
228 virtual int Length( void );
229 virtual ID_TIME_T Timestamp( void );
230 virtual int Tell( void );
231 virtual void ForceFlush( void );
232 virtual void Flush( void );
233 virtual int Seek( long offset, fsOrigin_t origin );
236 idStr name; // name of the file in the pak
237 idStr fullPath; // full file path including pak file name
238 int zipFilePos; // zip file info position in pak
239 int fileSize; // size of the file
240 void * z; // unzip info
243 #endif /* !__FILE_H__ */