Added some more documentation
[openstranded.git] / src / bbfile.hh
blobd8a3991318656b0154323765a4cdba7fc3f3e1bb
1 /*
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
25 #include <stdint.h>
26 #include <fstream>
28 /**
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)
33 class BBFile
35 private:
36 /**
37 * The file object for access to the Blitz Basic file
39 std::fstream file;
41 public:
42 /**
43 * The constructor.
44 * Opens a Blitz Basic compatible file.
45 * @param filePath Path to the file to be opened
47 BBFile (const char *filePath);
49 /**
50 * The destructor.
51 * Closes the opened file.
53 ~BBFile ();
58 // Overloading the extraction operator
61 /**
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
66 * @see readLine()
67 * @see readString()
69 BBFile&
70 operator>> (std::string &strBuf);
72 /**
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
76 * @see readByte()
78 BBFile&
79 operator>> (uint8_t &byteBuf);
81 /**
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
85 * @see readShort()
87 BBFile&
88 operator>> (uint16_t &shortBuf);
90 /**
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
94 * @see readInt()
96 BBFile&
97 operator>> (int32_t &intBuf);
99 /**
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
103 * @see readFloat()
105 BBFile&
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
119 * @see writeString()
120 * @see writeLine()
122 BBFile&
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
129 * @see writeByte()
131 BBFile&
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
138 * @see writeShort()
140 BBFile&
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
147 * @see writeInt()
149 BBFile&
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
156 * @see writeFloat()
158 BBFile&
159 operator<< (float &floatBuf);
164 // Actual file reading methods
168 * Reads a line.
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
173 std::string
174 readLine ();
177 * Reads a 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
182 std::string
183 readString ();
186 * Reads a uint8_t (B3d: Byte) value from the stream and removes it afterwards.
187 * @return The read uint8_t value.
189 uint8_t
190 readByte ();
193 * Reads a uint16_t (B3d: Short) value from the stream and removes it afterwards.
194 * @return The read short value.
196 uint16_t
197 readShort ();
200 * Reads an int32_t (B3d: Int) value from the stream and removes it afterwards.
201 * @return The read int32_t value.
203 int32_t
204 readInt ();
207 * Reads a float value from the stream and removes it afterwards.
208 * @return The read float value.
210 float
211 readFloat ();
216 // Actual file writing methods
220 * Writes a string terminated by the ASCII symbols CR (0x0d) and LF (0x0a)
221 * to the stream.
222 * @param lineWritten The line to be written
224 void
225 writeLine (std::string &lineWritten);
228 * Writes a string to the stream.
229 * @param strWritten The string to be written
231 void
232 writeString (std::string &strWritten);
235 * Writes a uint8_t (B3d: Byte) to the stream.
236 * @param byteWritten The uint8_t to be written
238 void
239 writeByte (uint8_t &byteWritten);
242 * Writes a uint16_t (B3d: Short) to the stream.
243 * @param shortWritten The uint16_t to be written
245 void
246 writeShort (uint16_t &shortWritten);
249 * Writes a int32_t (B3d: Int) to the stream.
250 * @param intWritten The int32_t to be written
252 void
253 writeInt (int32_t &intWritten);
256 * Writes a float to the stream.
257 * @param floatWritten The float to be written
259 void
260 writeFloat (float &floatWritten);
265 // Input validation
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
273 bool
274 validLine (std::string &line);
278 #endif /* STRANDED_BBFILE_HH */