27 #include <SDL/SDL_endian.h>
47 if (is_open ()) gzclose (file);
52 if (t == READ) file = gzopen (fname.c_str (),
"rb6");
53 else file = gzopen (fname.c_str (),
"wb6");
54 if (!file)
return false;
61 if (is_open ()) gzclose (file);
86 gzread (gfile.
file, &b, sizeof (b));
94 gzread (
file, &b,
sizeof (b));
101 gzread (gfile.
file, &n, sizeof (n));
108 gzread (
file, to, size);
114 gzread(gfile.
file, &n, sizeof (n));
122 gzread (
file, &n,
sizeof (n));
129 gzread(gfile.
file, &n, sizeof (n));
137 gzread (
file, &n,
sizeof (n));
144 gzread(gfile.
file, &n, sizeof (n));
153 gzread (
file, &n,
sizeof (n));
154 return SDL_SwapLE16(n);
160 gzread(gfile.
file, &n, sizeof (n));
169 gzread (
file, &n,
sizeof (n));
170 return SDL_SwapLE16(n);
176 gzread(gfile.
file, &n, sizeof (n));
185 gzread (
file, &n,
sizeof (n));
186 return SDL_SwapLE32(n);
192 gzread(gfile.
file, &n, sizeof (n));
201 gzread (
file, &n,
sizeof (n));
202 return SDL_SwapLE32(n);
236 sscanf (sf.c_str (),
"%f", &f);
269 gzwrite (
file, to, size);
276 gzwrite (gfile.
file, &b, sizeof (b));
283 gzwrite (gfile.
file, (
char *) &n, sizeof (n));
290 gzwrite(gfile.
file, (
u_int8 *) &n, sizeof (n));
297 gzwrite(gfile.
file, (
s_int8 *) &n, sizeof (n));
340 for (i = ((
string&) s).begin (); i != ((
string&) s).end (); i++)
351 snprintf (sf, 16,
"%f", f);
372 if (name ==
"") name =
"<unknown>";
377 cerr <<
"Version information missing in file \"" << name << endl;
378 cerr <<
"You should get a more recent data package.\n";
385 if (version < min || version > max)
387 cerr <<
"File \"" << name <<
"\" has\nversion number " << version <<
", ";
388 cerr <<
"but I was expecting " << min <<
" <= version <= " << max << endl;
392 cerr <<
"You should get an up-to-date version of this program.\n\n";
395 cerr <<
"You should probably get a more recent data package.\n";
Class to write data from a Gzip compressed file.
void close()
Close the file that was opened.
bool & operator<<(bool &n, igzstream &gfile)
Reads a boolean.
gzFile file
The actual gzFile.
#define s_int32
32 bits long signed integer
Class to read data from a Gzip compressed file.
u_int32 get_uint32()
Reads a u_int32.
#define u_int16
16 bits long unsigned integer
#define u_int32
32 bits long unsigned integer
#define u_int8
8 bits long unsigned integer
s_int8 get_sint8()
Reads a s_int8.
s_int16 get_sint16()
Reads a s_int16.
bool open(const string &fname)
Opens a file for write access.
bool open(const string &fname)
Opens a file for read access.
float get_float()
Reads a float.
static bool get_version(igzstream &file, u_int16 min, u_int16 max, string name)
ogzstream()
Default constructor.
igzstream()
Default constructor.
gz_type
Enumeration to know whether a file is read or write opened.
bool open(const string &fname, gz_type t)
Opens a file.
#define s_int16
16 bits long signed integer
u_int16 get_uint16()
Reads a u_int16.
virtual ~gz_file()
Destructor.
const bool & operator>>(const bool &n, ogzstream &gfile)
Writes a boolean.
gz_file()
Default constructor.
static void put_version(ogzstream &file, u_int16 version)
Sets the version number of a file.
s_int32 get_sint32()
Reads a s_int32.
Declares the igzstream, ogzstream and fileops classes.
bool get_bool()
Reads a boolean.
string get_string()
Reads a string.
#define s_int8
8 bits long signed integer
void get_block(void *to, u_int32 size)
Reads a block of bytes from the file.
Base class for igzstream and ogzstream.
void put_block(void *to, u_int32 size)
Writes a block of bytes to the file.
u_int8 get_uint8()
Reads a u_int8.