Debian Codegraph @

engine/include/iolib.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name iolib.h - The iolib functions header file. */
11 //
12 // (c) Copyright 2000-2007 by Andreas Arens
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27
28 #ifndef __IOLIB_H__
29 #define __IOLIB_H__
30
31 //@{
32
33 /*----------------------------------------------------------------------------
34 -- Includes
35 ----------------------------------------------------------------------------*/
36
37 #include <vector>
38 #include <zlib.h>
39
40 class CMapInfo;
41
42 /*----------------------------------------------------------------------------
43 -- Definitons
44 ----------------------------------------------------------------------------*/
45
46 /**
47 ** Exception thrown by FileWriter objects.
48 **/
49 class FileException
50 {
51 };
52
53
54 /**
55 ** Abstract class representing files one can write to.
56 */
57 class FileWriter
58 {
59 public:
60 virtual ~FileWriter() {}
61
62 void printf(const char *format, ...) GCC_ATTR((format(printf, 2, 3)));
63
64 virtual int write(const char *data, unsigned int size) = 0;
65 };
66
67
68 /**
69 ** Create a file writer object that works for the given file name.
70 **
71 ** If the file name ends with '.gz', the file writer returned
72 ** will compress the data with zlib.
73 */
74 FileWriter *CreateFileWriter(const std::string &filename);
75
76
77
78 /**
79 ** FileList struct used by directory access routine
80 */
81 class FileList {
82 public:
83 FileList() : name(NULL), type(0), xdata(NULL) {}
84
85 char *name; /// Name of the file
86 int type; /// Type of the file
87 CMapInfo *xdata; /// Extra data attached by high level
88 };
89
90
91 /**
92 ** Defines a library file
93 **
94 ** @todo zip archive support
95 */
96 class CFile {
97 public:
98 CFile();
99 ~CFile();
100
101 int open(const char *name, long flags);
102 int close();
103 void flush();
104 int read(void *buf, size_t len);
105 int seek(long offset, int whence);
106 long tell();
107 int printf(const char *format, ...) GCC_ATTR((format(printf, 2, 3)));
108
109 private:
110 int cl_type; /// type of CFile
111 FILE *cl_plain; /// standard file pointer
112 gzFile cl_gz; /// gzip file pointer
113 };
114
115 enum {
116 CLF_TYPE_INVALID, /// invalid file handle
117 CLF_TYPE_PLAIN, /// plain text file handle
118 CLF_TYPE_GZIP, /// gzip file handle
119 };
120
121 #define CL_OPEN_READ 0x1
122 #define CL_OPEN_WRITE 0x2
123 #define CL_WRITE_GZ 0x4
124
125 /*----------------------------------------------------------------------------
126 -- Functions
127 ----------------------------------------------------------------------------*/
128
129 /// Build libary path name
130 extern char *LibraryFileName(const char *file, char *buffer, size_t buffersize);
131
132 /// Read the contents of a directory
133 extern int ReadDataDirectory(const char *dirname, int (*filter)(char*, FileList *),
134 std::vector<FileList> &flp);
135
136 //@}
137
138 #endif // !__IOLIB_H__