00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00071
00072 #if !defined __cplusplus
00073 #error C++ compiler required
00074 #endif
00075
00076
00077 #if !defined LUMP_H
00078 #define LUMP_H
00079
00080
00081 #include <exception>
00082 #include <iostream>
00083 #include <iterator>
00084 #include <fstream>
00085 #include <new>
00086 #include <stdexcept>
00087 #include <string>
00088
00089
00090 #include "global.hpp"
00091 #include "util.hpp"
00092
00093 namespace Doomwad
00094 {
00095 class WadEntry;
00096
00133 EXPORT class Lump
00134 {
00135 public:
00136
00138 typedef byte value_type;
00139
00141 typedef value_type* pointer;
00142
00144 typedef const value_type* const_pointer;
00145
00147 typedef value_type& reference;
00148
00150 typedef const value_type& const_reference;
00151
00153 typedef size_t size_type;
00154
00156 typedef __gnu_cxx::__normal_iterator<pointer,Lump> iterator;
00157
00159 typedef __gnu_cxx::__normal_iterator<const_pointer,Lump> const_iterator;
00160
00162 typedef std::reverse_iterator<iterator> reverse_iterator;
00163
00165 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00166
00168 static const size_t MAX_SIZE;
00169
00171 static const size_t MIN_SIZE;
00172
00173 protected:
00174
00179 std::string m_name;
00180
00182 size_t m_size;
00183
00185 pointer m_data;
00186
00187 public:
00188
00189
00190 Lump (void) throw ();
00191 Lump (const Lump&) throw (std::bad_alloc);
00192 Lump (const std::string&, size_t = 0) throw (std::bad_alloc);
00193 Lump (const std::string&, size_t, const_pointer) throw (std::bad_alloc, std::invalid_argument);
00194 Lump (const_iterator&, const_iterator&) throw ();
00195 Lump (const WadEntry&) throw ();
00196
00197
00198 virtual ~Lump (void) throw ();
00199
00200
00201 iterator begin (void) throw ();
00202 iterator end (void) throw ();
00203
00204
00205 const_iterator begin (void) const throw ();
00206 const_iterator end (void) const throw ();
00207
00208
00209 reverse_iterator rbegin (void) throw ();
00210 reverse_iterator rend (void) throw ();
00211
00212
00213 const_reverse_iterator rbegin (void) const throw ();
00214 const_reverse_iterator rend (void) const throw ();
00215
00216
00217 virtual Lump& operator= (const Lump&) throw (std::bad_alloc);
00218 virtual Lump& operator= (const WadEntry&) throw (std::bad_alloc);
00219 virtual Lump& operator+= (const Lump&) throw (std::bad_alloc, std::range_error);
00220 virtual Lump operator+ (const Lump&) const throw (std::bad_alloc, std::range_error);
00221
00222
00223 virtual bool operator== (const Lump&) const throw ();
00224 virtual bool operator!= (const Lump&) const throw ();
00225
00226
00227 operator std::string& (void) throw ();
00228 operator size_t (void) throw ();
00229 operator bool (void) throw ();
00230
00231
00232 reference operator[] (size_t) throw ();
00233 const_reference operator[] (size_t) const throw ();
00234
00235
00236 reference at (size_t) throw (std::out_of_range);
00237 const_reference at (size_t) const throw (std::out_of_range);
00238
00239
00240 virtual bool append (const_pointer, size_t) throw (std::invalid_argument, std::range_error);
00241 virtual bool append (const_iterator&, const_iterator&) throw (std::range_error);
00242 virtual bool assign (const_pointer, size_t) throw (std::invalid_argument, std::bad_alloc);
00243 virtual bool assign (const_iterator&, const_iterator&) throw (std::bad_alloc);
00244
00245
00246 std::string getName (void) const throw ();
00247 bool setName (const std::string&) throw ();
00248
00249
00250 virtual const_pointer getData (void) throw ();
00251
00252
00253 virtual bool grow (size_t) throw (std::range_error, std::bad_alloc);
00254 virtual bool shrink (size_t) throw (std::range_error, std::bad_alloc);
00255 virtual bool setSize (size_t) throw (std::bad_alloc);
00256
00257
00258 virtual bool readFromFile (std::ifstream&) throw (std::bad_alloc);
00259 virtual bool readFromFile (const std::string&) throw ();
00260 virtual bool writeToFile (std::ofstream&) const throw ();
00261 virtual bool writeToFile (const std::string&) const throw ();
00262
00263
00264 virtual bool readFromStream (std::istream&, size_t) throw ();
00265 virtual bool writeToStream (std::ostream&) const throw ();
00266 virtual bool writeToTextStream (std::ostream&, size_t = 32, char = '.') const throw ();
00267
00268
00269 virtual bool clear (void) throw ();
00270 bool clearData (void) throw ();
00271 bool clearName (void) throw ();
00272
00273
00274 bool empty (void) const throw ();
00275 size_t size (void) const throw ();
00276
00277
00278 virtual byte getByte (size_t = 0) const throw (std::range_error);
00279 virtual word getWord (size_t = 0) const throw (std::range_error);
00280 virtual dword getDWord (size_t = 0) const throw (std::range_error);
00281 virtual qword getQWord (size_t = 0) const throw (std::range_error);
00282 virtual int8 getInt8 (size_t = 0) const throw (std::range_error);
00283 virtual uint8 getUInt8 (size_t = 0) const throw (std::range_error);
00284 virtual int16 getInt16 (size_t = 0) const throw (std::range_error);
00285 virtual uint16 getUInt16 (size_t = 0) const throw (std::range_error);
00286 virtual int32 getInt32 (size_t = 0) const throw (std::range_error);
00287 virtual uint32 getUInt32 (size_t = 0) const throw (std::range_error);
00288 virtual int64 getInt64 (size_t = 0) const throw (std::range_error);
00289 virtual uint64 getUInt64 (size_t = 0) const throw (std::range_error);
00290
00291
00292 virtual bool setByte (byte = 0, size_t = 0) throw (std::range_error);
00293 virtual bool setWord (word = 0, size_t = 0) throw (std::range_error);
00294 virtual bool setDWord (dword = 0, size_t = 0) throw (std::range_error);
00295 virtual bool setQWord (qword = 0, size_t = 0) throw (std::range_error);
00296 virtual bool setInt8 (int8 = 0, size_t = 0) throw (std::range_error);
00297 virtual bool setUInt8 (uint8 = 0, size_t = 0) throw (std::range_error);
00298 virtual bool setInt16 (int16 = 0, size_t = 0) throw (std::range_error);
00299 virtual bool setUInt16 (uint16 = 0, size_t = 0) throw (std::range_error);
00300 virtual bool setInt32 (int32 = 0, size_t = 0) throw (std::range_error);
00301 virtual bool setUInt32 (uint32 = 0, size_t = 0) throw (std::range_error);
00302 virtual bool setInt64 (int64 = 0, size_t = 0) throw (std::range_error);
00303 virtual bool setUInt64 (uint64 = 0, size_t = 0) throw (std::range_error);
00304
00305
00306 virtual std::string getString (size_t = 0) const throw (std::range_error);
00307 virtual std::string getDString (size_t = 0) const throw (std::range_error);
00308
00309
00310 virtual bool setString (const std::string&, size_t = 0) throw (std::range_error);
00311 virtual bool setDString (const std::string&, size_t = 0) throw (std::range_error);
00312 };
00313 }
00314 #include "wadentry.hpp"
00315 #endif