Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

lump.hpp

Go to the documentation of this file.
00001 // libdoomwad: manipulates Doom wad files.
00002 // Copyright (C) 2005  John Gaughan
00003 //
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 // This library is distributed with the full text of the LGPL. Please see
00019 // the accompanying file named COPYING.
00020 // 
00021 // You may contact the author at john@johngaughan.net
00022 
00071 // C++ required.
00072 #if !defined __cplusplus
00073 #error C++ compiler required
00074 #endif
00075 
00076 // Include guard
00077 #if !defined LUMP_H
00078 #define LUMP_H
00079 
00080 // C++ headers
00081 #include <exception>
00082 #include <iostream>
00083 #include <iterator>
00084 #include <fstream>
00085 #include <new>
00086 #include <stdexcept>
00087 #include <string>
00088 
00089 // Doom headers
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     // Constructors
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     // Destructor
00198     virtual ~Lump (void) throw ();
00199 
00200     // Iterators
00201     iterator begin (void) throw ();
00202     iterator end (void) throw ();
00203 
00204     // Const iterators
00205     const_iterator begin (void) const throw ();
00206     const_iterator end (void) const throw ();
00207 
00208     // Reverse iterators
00209     reverse_iterator rbegin (void) throw ();
00210     reverse_iterator rend (void) throw ();
00211 
00212     // Const reverse iterators
00213     const_reverse_iterator rbegin (void) const throw ();
00214     const_reverse_iterator rend (void) const throw ();
00215 
00216     // Assignment and arithmetic
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     // Comparison
00223     virtual bool operator== (const Lump&) const throw ();
00224     virtual bool operator!= (const Lump&) const throw ();
00225 
00226     // Casting
00227     operator std::string& (void) throw ();
00228     operator size_t (void) throw ();
00229     operator bool (void) throw ();
00230 
00231     // Array index
00232     reference operator[] (size_t) throw ();
00233     const_reference operator[] (size_t) const throw ();
00234 
00235     // Bounds-safe array index (a la std::vector)
00236     reference at (size_t) throw (std::out_of_range);
00237     const_reference at (size_t) const throw (std::out_of_range);
00238 
00239     // Append/assign data
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     // Name management
00246     std::string getName (void) const throw ();
00247     bool setName (const std::string&) throw ();
00248 
00249     // Data management
00250     virtual const_pointer getData (void) throw ();
00251 
00252     // Size management
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     // File stream input and output (binary)
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     // Stream I/O
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     // Clear data
00269     virtual bool clear (void) throw ();
00270     bool clearData (void) throw ();
00271     bool clearName (void) throw ();
00272 
00273     // Get other information
00274     bool empty (void) const throw ();
00275     size_t size (void) const throw ();
00276 
00277     // Get integer types
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     // Set integer types
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     // Get string types
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     // Set string types
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

Generated on Fri Jun 10 19:38:51 2005 for libdoomwad by  doxygen 1.4.0