2 * This file includes the class declaration of a Blitz Basic file
4 * Copyright (C) 2008 David Kolossa
6 * This file is part of OpenStranded.
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef STRANDED_BBFILE_HH
23 #define STRANDED_BBFILE_HH
29 * This is a wrapper class for Blitz3d files.
30 * It is used to provide compatibility with files created by
31 * Blitz Basic 3d (e.g. save files)
37 * The file object for access to the Blitz Basic file
44 * Opens a Blitz Basic compatible file.
45 * @param filePath Path to the file to be opened
47 BBFile (std::string filePath
);
51 * Closes the opened file.
58 // Check for file stream flags
65 fail() { return file
.fail(); }
71 eof() { return file
.eof(); }
77 bad() { return file
.bad(); }
83 good() { return file
.good(); }
88 // Overloading the ! operator
96 // Overloading the extraction operator
100 * Read a string from the file.
101 * Note: You can't read lines using this operator, use readLine() instead.
102 * @param strBuf The buffer into which the string is written
103 * @return A reference to the BBFile object
108 operator>> (std::string
&strBuf
);
111 * Read a uint8_t (In B3d: Byte) from the file.
112 * @param byteBuf The buffer into which the uint8_t is written
113 * @return A reference to the BBFile object
117 operator>> (uint8_t &byteBuf
);
120 * Read a uint16_t (In B3d: Short) from the file.
121 * @param shortBuf The buffer into which the uint16_t is written
122 * @return A reference to the BBFile object
126 operator>> (uint16_t &shortBuf
);
129 * Read an int32_t (In B3d: Int) from the file.
130 * @param intBuf The buffer into which the int32_t is written
131 * @return A reference to the BBFile object
135 operator>> (int32_t &intBuf
);
138 * Read a float (In B3d: Float) from the file.
139 * @param floatBuf Th buffer into which the float is written
140 * @return A reference to the BBFile object
144 operator>> (float &floatBuf
);
149 // Overloading the insertion operator
153 * Write a string to the file.
154 * Note: You can't write lines with that operator, use writeLine() instead.
155 * @param strBuf The buffer from which the string is read
156 * @return A reference to the BBFile object
161 operator<< (std::string
&strBuf
);
164 * Write a uint8_t (In B3d: Byte) to the file.
165 * @param byteBuf The buffer from which the uint8_t is read
166 * @return A reference to the BBFile object
170 operator<< (uint8_t &byteBuf
);
173 * Write a uint16_t (In B3d: Short) to the file.
174 * @param shortBuf The buffer from which the uint16_t is read
175 * @return A reference to the BBFile object
179 operator<< (uint16_t &shortBuf
);
182 * Write a int32_t (In B3d: Integer) to the file.
183 * @param intBuf The buffer from which the int32_t is read
184 * @return A reference to the BBFile object
188 operator<< (int32_t &intBuf
);
191 * Write a float (In B3d: Float) to the file.
192 * @param floatBuf The buffer from which the float is read
193 * @return A reference to the BBFile object
197 operator<< (float &floatBuf
);
202 // Actual file reading methods
207 * A line is terminated by the ASCII symbols CR (0x0d) and LF (0x0a).
208 * The read data is removed from the stream.
209 * @return The read string
216 * A string is preceded by its length as an int32_t. This method reads the
217 * string and removes it (including length indicator) from the stream.
218 * @return The read string
224 * Reads a uint8_t (B3d: Byte) value from the stream and removes it afterwards.
225 * @return The read uint8_t value.
231 * Reads a uint16_t (B3d: Short) value from the stream and removes it afterwards.
232 * @return The read short value.
238 * Reads an int32_t (B3d: Int) value from the stream and removes it afterwards.
239 * @return The read int32_t value.
245 * Reads a float value from the stream and removes it afterwards.
246 * @return The read float value.
252 * Reads raw data from the stream.
253 * @param buffer Buffer to which the bytes are written
254 * @param size Amount of data to be read
257 readData(void *buffer
, uint32_t size
);
260 // Actual file writing methods
264 * Writes a string terminated by the ASCII symbols CR (0x0d) and LF (0x0a)
266 * @param lineWritten The line to be written
269 writeLine (std::string
&lineWritten
);
272 * Writes a string to the stream.
273 * @param strWritten The string to be written
276 writeString (std::string
&strWritten
);
279 * Writes a uint8_t (B3d: Byte) to the stream.
280 * @param byteWritten The uint8_t to be written
283 writeByte (uint8_t &byteWritten
);
286 * Writes a uint16_t (B3d: Short) to the stream.
287 * @param shortWritten The uint16_t to be written
290 writeShort (uint16_t &shortWritten
);
293 * Writes a int32_t (B3d: Int) to the stream.
294 * @param intWritten The int32_t to be written
297 writeInt (int32_t &intWritten
);
300 * Writes a float to the stream.
301 * @param floatWritten The float to be written
304 writeFloat (float &floatWritten
);
313 * Checks whether a string is a valid B3d line
314 * @param line The string to be checked
315 * @return true if line is a valid b3d line, false if not
318 validLine (std::string
&line
);
322 #endif /* STRANDED_BBFILE_HH */