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 (const char *filePath
);
51 * Closes the opened file.
58 // Overloading the extraction operator
62 * Read a string from the file.
63 * Note: You can't read lines using this operator, use readLine() instead.
64 * @param strBuf The buffer into which the string is written
65 * @return A reference to the BBFile object
70 operator>> (std::string
&strBuf
);
73 * Read a uint8_t (In B3d: Byte) from the file.
74 * @param byteBuf The buffer into which the uint8_t is written
75 * @return A reference to the BBFile object
79 operator>> (uint8_t &byteBuf
);
82 * Read a uint16_t (In B3d: Short) from the file.
83 * @param shortBuf The buffer into which the uint16_t is written
84 * @return A reference to the BBFile object
88 operator>> (uint16_t &shortBuf
);
91 * Read an int32_t (In B3d: Int) from the file.
92 * @param intBuf The buffer into which the int32_t is written
93 * @return A reference to the BBFile object
97 operator>> (int32_t &intBuf
);
100 * Read a float (In B3d: Float) from the file.
101 * @param floatBuf Th buffer into which the float is written
102 * @return A reference to the BBFile object
106 operator>> (float &floatBuf
);
111 // Overloading the insertion operator
115 * Write a string to the file.
116 * Note: You can't write lines with that operator, use writeLine() instead.
117 * @param strBuf The buffer from which the string is read
118 * @return A reference to the BBFile object
123 operator<< (std::string
&strBuf
);
126 * Write a uint8_t (In B3d: Byte) to the file.
127 * @param byteBuf The buffer from which the uint8_t is read
128 * @return A reference to the BBFile object
132 operator<< (uint8_t &byteBuf
);
135 * Write a uint16_t (In B3d: Short) to the file.
136 * @param shortBuf The buffer from which the uint16_t is read
137 * @return A reference to the BBFile object
141 operator<< (uint16_t &shortBuf
);
144 * Write a int32_t (In B3d: Integer) to the file.
145 * @param intBuf The buffer from which the int32_t is read
146 * @return A reference to the BBFile object
150 operator<< (int32_t &intBuf
);
153 * Write a float (In B3d: Float) to the file.
154 * @param floatBuf The buffer from which the float is read
155 * @return A reference to the BBFile object
159 operator<< (float &floatBuf
);
164 // Actual file reading methods
169 * A line is terminated by the ASCII symbols CR (0x0d) and LF (0x0a).
170 * The read data is removed from the stream.
171 * @return The read string
178 * A string is preceded by its length as an int32_t. This method reads the
179 * string and removes it (including length indicator) from the stream.
180 * @return The read string
186 * Reads a uint8_t (B3d: Byte) value from the stream and removes it afterwards.
187 * @return The read uint8_t value.
193 * Reads a uint16_t (B3d: Short) value from the stream and removes it afterwards.
194 * @return The read short value.
200 * Reads an int32_t (B3d: Int) value from the stream and removes it afterwards.
201 * @return The read int32_t value.
207 * Reads a float value from the stream and removes it afterwards.
208 * @return The read float value.
216 // Actual file writing methods
220 * Writes a string terminated by the ASCII symbols CR (0x0d) and LF (0x0a)
222 * @param lineWritten The line to be written
225 writeLine (std::string
&lineWritten
);
228 * Writes a string to the stream.
229 * @param strWritten The string to be written
232 writeString (std::string
&strWritten
);
235 * Writes a uint8_t (B3d: Byte) to the stream.
236 * @param byteWritten The uint8_t to be written
239 writeByte (uint8_t &byteWritten
);
242 * Writes a uint16_t (B3d: Short) to the stream.
243 * @param shortWritten The uint16_t to be written
246 writeShort (uint16_t &shortWritten
);
249 * Writes a int32_t (B3d: Int) to the stream.
250 * @param intWritten The int32_t to be written
253 writeInt (int32_t &intWritten
);
256 * Writes a float to the stream.
257 * @param floatWritten The float to be written
260 writeFloat (float &floatWritten
);
269 * Checks whether a string is a valid B3d line
270 * @param line The string to be checked
271 * @return true if line is a valid b3d line, false if not
274 validLine (std::string
&line
);
278 #endif /* STRANDED_BBFILE_HH */