doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
File.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __FILE_H__
30 #define __FILE_H__
31 
32 /*
33 ==============================================================
34 
35  File Streams.
36 
37 ==============================================================
38 */
39 
40 // mode parm for Seek
41 typedef enum {
45 } fsOrigin_t;
46 
47 class idFileSystemLocal;
48 
49 
50 class idFile {
51 public:
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 );
71  // Seek on a file.
72  virtual int Seek( long offset, fsOrigin_t origin );
73  // Go back to the beginning of the file.
74  virtual void Rewind( void );
75  // Like fprintf.
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)));
81 
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 );
97 
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 );
113 };
114 
115 
116 class idFile_Memory : public idFile {
117  friend class idFileSystemLocal;
118 
119 public:
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 );
125 
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 );
136 
137  // changes memory file to read only
138  virtual void MakeReadOnly( void );
139  // clear the file
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; }
147 
148 private:
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
157 };
158 
159 
160 class idFile_BitMsg : public idFile {
161  friend class idFileSystemLocal;
162 
163 public:
164  idFile_BitMsg( idBitMsg &msg );
165  idFile_BitMsg( const idBitMsg &msg );
166  virtual ~idFile_BitMsg( void );
167 
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 );
178 
179 private:
180  idStr name; // name of the file
181  int mode; // open mode
183 };
184 
185 
186 class idFile_Permanent : public idFile {
187  friend class idFileSystemLocal;
188 
189 public:
190  idFile_Permanent( void );
191  virtual ~idFile_Permanent( void );
192 
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 );
203 
204  // returns file pointer
205  FILE * GetFilePtr( void ) { return o; }
206 
207 private:
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
214 };
215 
216 
217 class idFile_InZip : public idFile {
218  friend class idFileSystemLocal;
219 
220 public:
221  idFile_InZip( void );
222  virtual ~idFile_InZip( void );
223 
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 );
234 
235 private:
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
241 };
242 
243 #endif /* !__FILE_H__ */
virtual int WriteVec6(const idVec6 &vec)
Definition: File.cpp:592
GLubyte g
Definition: glext.h:4662
void SetGranularity(int g)
Definition: File.h:146
virtual int ReadUnsignedChar(unsigned char &value)
Definition: File.cpp:364
virtual int WriteUnsignedChar(const unsigned char value)
Definition: File.cpp:517
virtual int ReadShort(short &value)
Definition: File.cpp:333
GLsizei const GLfloat * value
Definition: glext.h:3614
virtual const char * GetFullPath(void)
Definition: File.h:194
int allocated
Definition: File.h:153
virtual int virtual int ReadInt(int &value)
Definition: File.cpp:311
assert(prefInfo.fullscreenBtn)
int fileSize
Definition: File.h:152
virtual int ReadChar(char &value)
Definition: File.cpp:355
virtual int ReadVec4(idVec4 &vec)
Definition: File.cpp:435
virtual const char * GetFullPath(void)
Definition: File.h:169
virtual void Rewind(void)
Definition: File.cpp:251
GLenum GLsizei GLenum format
Definition: glext.h:2846
virtual void ForceFlush(void)
Definition: File.cpp:226
idStr name
Definition: File.h:149
virtual ~idFile(void)
Definition: File.h:52
#define const
Definition: getdate.c:251
void * z
Definition: File.h:240
int granularity
Definition: File.h:154
idBitMsg * msg
Definition: File.h:182
Definition: Vector.h:316
virtual const char * GetFullPath(void)
Definition: File.h:225
bool handleSync
Definition: File.h:213
virtual int Tell(void)
Definition: File.cpp:217
FILE * o
Definition: File.h:212
virtual const char * GetFullPath(void)
Definition: File.h:127
GLenum GLsizei len
Definition: glext.h:3472
virtual int WriteChar(const char value)
Definition: File.cpp:508
virtual int WriteVec4(const idVec4 &vec)
Definition: File.cpp:581
virtual int WriteVec2(const idVec2 &vec)
Definition: File.cpp:559
virtual const char * GetName(void)
Definition: File.cpp:161
GLintptr offset
Definition: glext.h:3113
virtual const char * GetName(void)
Definition: File.h:224
idStr name
Definition: File.h:236
Definition: File.h:50
int zipFilePos
Definition: File.h:238
virtual int ReadUnsignedShort(unsigned short &value)
Definition: File.cpp:344
virtual void Flush(void)
Definition: File.cpp:234
Definition: Vector.h:52
virtual int WriteInt(const int value)
Definition: File.cpp:468
Definition: Vector.h:808
virtual int WriteString(const char *string)
Definition: File.cpp:546
const char * GetDataPtr(void) const
Definition: File.h:144
virtual int ReadVec2(idVec2 &vec)
Definition: File.cpp:413
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
virtual int ReadVec3(idVec3 &vec)
Definition: File.cpp:424
GLuint buffer
Definition: glext.h:3108
virtual int Read(void *buffer, int len)
Definition: File.cpp:179
int mode
Definition: File.h:150
virtual const char * GetName(void)
Definition: File.h:193
virtual int WriteFloatString(const char *fmt,...) id_attribute((format(printf
Definition: File.cpp:294
int maxSize
Definition: File.h:151
virtual int Seek(long offset, fsOrigin_t origin)
Definition: File.cpp:242
virtual int ReadBool(bool &value)
Definition: File.cpp:384
virtual ID_TIME_T Timestamp(void)
Definition: File.cpp:208
virtual int ReadUnsignedInt(unsigned int &value)
Definition: File.cpp:322
virtual const char * GetName(void)
Definition: File.h:168
Definition: Matrix.h:333
idStr fullPath
Definition: File.h:209
idStr fullPath
Definition: File.h:237
char * curPtr
Definition: File.h:156
#define id_attribute(x)
Definition: sys_public.h:139
virtual const char * GetName(void)
Definition: File.h:126
char * filePtr
Definition: File.h:155
virtual int WriteShort(const short value)
Definition: File.cpp:488
virtual int WriteUnsignedInt(const unsigned int value)
Definition: File.cpp:478
int mode
Definition: File.h:181
virtual int WriteFloat(const float value)
Definition: File.cpp:526
const GLcharARB * name
Definition: glext.h:3629
virtual int Write(const void *buffer, int len)
Definition: File.cpp:189
Definition: Str.h:116
GLsizei const GLcharARB const GLint * length
Definition: glext.h:3599
virtual int WriteMat3(const idMat3 &mat)
Definition: File.cpp:603
virtual int ReadVec6(idVec6 &vec)
Definition: File.cpp:446
int fileSize
Definition: File.h:211
virtual int ReadString(idStr &string)
Definition: File.cpp:396
virtual int ReadMat3(idMat3 &mat)
Definition: File.cpp:457
virtual int ReadFloat(float &value)
Definition: File.cpp:373
virtual int WriteBool(const bool value)
Definition: File.cpp:536
virtual int virtual int VPrintf(const char *fmt, va_list arg)
Definition: File.cpp:281
idStr name
Definition: File.h:208
virtual int WriteUnsignedShort(unsigned short value)
Definition: File.cpp:498
idStr name
Definition: File.h:180
virtual int Printf(const char *fmt,...) id_attribute((format(printf
Definition: File.cpp:260
virtual int Length(void)
Definition: File.cpp:199
virtual int WriteVec3(const idVec3 &vec)
Definition: File.cpp:570
virtual const char * GetFullPath(void)
Definition: File.cpp:170
fsOrigin_t
Definition: File.h:41
int fileSize
Definition: File.h:239
FILE * GetFilePtr(void)
Definition: File.h:205