Anyway, the goal of this class is to encapsulate one of those lumps in a Wad file. While it does not inherit from the STL Container library, it behaves in a similar manner. It has bidirectional iterators and the functions that come with them. It does not, however, have an allocator, because it handles allocation on its own. It has standard typedefs for its value type. It uses operator overloading in a sensible manner. Most of the functions are fairly self-explanatory.
Essentially, a lump is a sequence of bytes of fixed length. Resizing is possible, but not in the same way a vector or string allows insertions in the middle. Since there are various types of lumps and each has its own internal format, this class merely holds data while other classes read and write to it. For example, if a lump is of type Vertexes, use the Vertexes class to read the data from the lump. Manipulate it with the other class, then create a new Lump from the Vertexes object and save it to disk or put it in a Wad or whatever.
There are several convenience functions for reading and writing to streams and file names: use them. My intention is, for example, that you can read and write raw Lump data to files, or you can use the stream functions if you handle the file yourself, want to use standard I/O, or are using string streams. Whatever. The logic is already here to do all that.
Definition at line 133 of file lump.hpp.
Public Types | |
|
typedef __gnu_cxx::__normal_iterator< const_pointer, Lump > | const_iterator |
| Const iterator. | |
| typedef const value_type * | const_pointer |
| Const pointer to data type. | |
| typedef const value_type & | const_reference |
| Const reference to data type. | |
|
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
| Const reverse iterator. | |
|
typedef __gnu_cxx::__normal_iterator< pointer, Lump > | iterator |
| Bidirectional iterator. | |
| typedef value_type * | pointer |
| Pointer to data type. | |
| typedef value_type & | reference |
| Reference to data type. | |
|
typedef std::reverse_iterator< iterator > | reverse_iterator |
| Bidirectional reverse iterator. | |
| typedef size_t | size_type |
| Integer that can hold all valid sizes of data. | |
| typedef byte | value_type |
| Type of data in the buffer. | |
Public Member Functions | |
| virtual bool | append (const_iterator &, const_iterator &) throw (std::range_error) |
| Append data between two iterators. | |
| virtual bool | append (const_pointer, size_t) throw (std::invalid_argument, std::range_error) |
| Append a char array. | |
| virtual bool | assign (const_iterator &, const_iterator &) throw (std::bad_alloc) |
| Assign data from iterators. | |
| virtual bool | assign (const_pointer, size_t) throw (std::invalid_argument, std::bad_alloc) |
| Assign data from a pointer. | |
| const_reference | at (size_t) const throw (std::out_of_range) |
| Index function. | |
| reference | at (size_t) throw (std::out_of_range) |
| Index function. | |
| const_iterator | begin (void) const throw () |
| Get constant iterator to start of data. | |
| iterator | begin (void) throw () |
| Get iterator to start of data. | |
| virtual bool | clear (void) throw () |
| Clear all Lump contents. | |
| bool | clearData (void) throw () |
| Clear the data buffer. | |
| bool | clearName (void) throw () |
| Clear the name. | |
| bool | empty (void) const throw () |
| Check if the Lump has no data. | |
| const_iterator | end (void) const throw () |
| Get constant iterator to end of data. | |
| iterator | end (void) throw () |
| Get iterator to end of data. | |
| virtual byte | getByte (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual const_pointer | getData (void) throw () |
| Get a pointer to the data. | |
| virtual std::string | getDString (size_t=0) const throw (std::range_error) |
| Get a Doom string from inside a Lump. | |
| virtual dword | getDWord (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual int16 | getInt16 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual int32 | getInt32 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual int64 | getInt64 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual int8 | getInt8 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| std::string | getName (void) const throw () |
| Get the name. | |
| virtual qword | getQWord (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual std::string | getString (size_t=0) const throw (std::range_error) |
| Get a string from inside a Lump. | |
| virtual uint16 | getUInt16 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual uint32 | getUInt32 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual uint64 | getUInt64 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual uint8 | getUInt8 (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual word | getWord (size_t=0) const throw (std::range_error) |
| Get an integer from inside a Lump. | |
| virtual bool | grow (size_t) throw (std::range_error, std::bad_alloc) |
| Increase the size of the Lump's data. | |
| Lump (const WadEntry &) throw () | |
| Construct from a WadEntry. | |
| Lump (const_iterator &, const_iterator &) throw () | |
| Construct from two iterators. | |
| Lump (const std::string &, size_t, const_pointer) throw (std::bad_alloc, std::invalid_argument) | |
| Construct with a name and data buffer. | |
| Lump (const std::string &, size_t=0) throw (std::bad_alloc) | |
| Construct with a name and a blank data buffer. | |
| Lump (const Lump &) throw (std::bad_alloc) | |
| Copy constructor. | |
| Lump (void) throw () | |
| Default constructor. | |
| operator bool (void) throw () | |
| Cast to bool. | |
| operator size_t (void) throw () | |
| Cast to size_t. | |
| operator std::string & (void) throw () | |
| Cast to std::string reference. | |
| virtual bool | operator!= (const Lump &) const throw () |
| Inequality operator. | |
| virtual Lump | operator+ (const Lump &) const throw (std::bad_alloc, std::range_error) |
| Addition operator. | |
| virtual Lump & | operator+= (const Lump &) throw (std::bad_alloc, std::range_error) |
| Concatenation operator. | |
| virtual Lump & | operator= (const WadEntry &) throw (std::bad_alloc) |
| Assign from a WadEntry. | |
| virtual Lump & | operator= (const Lump &) throw (std::bad_alloc) |
| Assignment operator. | |
| virtual bool | operator== (const Lump &) const throw () |
| Equality operator. | |
| const_reference | operator[] (size_t) const throw () |
| Array index operator. | |
| reference | operator[] (size_t) throw () |
| Array index operator. | |
| const_reverse_iterator | rbegin (void) const throw () |
| Get constant reverse iterator to end of data. | |
| reverse_iterator | rbegin (void) throw () |
| Get reverse iterator to end of data. | |
| virtual bool | readFromFile (const std::string &) throw () |
| Read from a file given a filename. | |
| virtual bool | readFromFile (std::ifstream &) throw (std::bad_alloc) |
| Read from a file stream. | |
| virtual bool | readFromStream (std::istream &, size_t) throw () |
| Read from an input stream. | |
| const_reverse_iterator | rend (void) const throw () |
| Get constant reverse iterator to beginning of data. | |
| reverse_iterator | rend (void) throw () |
| Get reverse iterator to beginning of data. | |
| virtual bool | setByte (byte=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setDString (const std::string &, size_t=0) throw (std::range_error) |
| Set a Doom string at a location in a Lump. | |
| virtual bool | setDWord (dword=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setInt16 (int16=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setInt32 (int32=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setInt64 (int64=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setInt8 (int8=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| bool | setName (const std::string &) throw () |
| Set the name. | |
| virtual bool | setQWord (qword=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setSize (size_t) throw (std::bad_alloc) |
| Set the size of the Lump's data. | |
| virtual bool | setString (const std::string &, size_t=0) throw (std::range_error) |
| Set a string at a location in a Lump. | |
| virtual bool | setUInt16 (uint16=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setUInt32 (uint32=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setUInt64 (uint64=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setUInt8 (uint8=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | setWord (word=0, size_t=0) throw (std::range_error) |
| Set an integer at a location in a Lump. | |
| virtual bool | shrink (size_t) throw (std::range_error, std::bad_alloc) |
| Decrease the size of the Lump's data. | |
| size_t | size (void) const throw () |
| Get the length of the data. | |
| virtual bool | writeToFile (const std::string &) const throw () |
| Write to a file given a filename. | |
| virtual bool | writeToFile (std::ofstream &) const throw () |
| Write to a file stream. | |
| virtual bool | writeToStream (std::ostream &) const throw () |
| Write to an output stream. | |
| virtual bool | writeToTextStream (std::ostream &, size_t=32, char= '.') const throw () |
| Write to an output stream. | |
| virtual | ~Lump (void) throw () |
| Destructor. | |
Static Public Attributes | |
| static const size_t | MAX_SIZE = std::numeric_limits<size_t>::max () |
| Maximum size of a Lump data buffer. | |
| static const size_t | MIN_SIZE = std::numeric_limits<size_t>::min () |
| Minimum size of a Lump data buffer. | |
Protected Attributes | |
| pointer | m_data |
| Internal data buffer. | |
| std::string | m_name |
| size_t | m_size |
| Size of the Lump in bytes. This is also the length of the data buffer. | |
|
|
Default constructor. Create an empty Lump with no data and an empty name. |
|
|
Copy constructor. Create an exact copy of another Lump. This constructor is guaranteed to be atomic. If memory allocation fails, it cleans up after itself and rethrows the bad_alloc exception. According to section 15.2 of the C++ standard, if a constructor throws an exception the stack unwinds to the nearest try block's catch. This calls destructors for partially constructed objects. In practice, it is better to ensure that individual functions (methods? Do we speak Java?) are atomic because not all compilers are compliant with this part of the standard, not even all recent versions.
Definition at line 88 of file lump.cpp. References m_data, m_name, m_size, and Doomwad::EventLog::printLine(). |
|
||||||||||||
|
Construct with a name and a blank data buffer. Constructs a Lump with a string name and a data buffer of a given size initialized to all nulls. If memory allocation fails, the constructor will clean up after itself and when the stack unwinds this object will be destroyed.
Definition at line 134 of file lump.cpp. References Doomwad::EventLog::printLine(). |
|
||||||||||||||||
|
Construct with a name and data buffer. Constructs a Lump with a string name and a data buffer of a given size initialized to a copy of the contents of the given buffer. If memory allocation fails, the constructor will clean up after itself and let stack unwinding take care of the rest.
Definition at line 186 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
||||||||||||
|
Construct from two iterators. Constructs a Lump from two iterators. All of the elements between the two iterators, starting with the element pointed to by the first element and ending with the one before the last element, are copied into the new object. Note that if the iterators do not belong to the same Lump that the behavior of this constructor is not defined. Please play nicely.
Definition at line 257 of file lump.cpp. References assign(). |
|
|
Construct from a WadEntry.
|
|
|
Destructor. Destroys a Lump object. Never call it explicitly. It is guaranteed not to throw any exceptions. We are good citizens and clean up after ourselves. Definition at line 280 of file lump.cpp. References clear(). |
|
||||||||||||
|
Append data between two iterators. Works much like the other Lump::append() function, except this one uses iterators to mark the beginning and end rather than a pointer and integer size.
Definition at line 852 of file lump.cpp. References append(). |
|
||||||||||||
|
Append a char array. Appends a raw char array onto the end of this Lump. Acts similar to the other overloaded member function except this one throws an exception if the pointer is null and the length is positive. This is designed to facilitate handling lumps in a loop by simplifying the use of the class: do not worry about zero length entries, the class handles it for you.
Definition at line 770 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). Referenced by append(), and readFromFile(). |
|
||||||||||||
|
Assign data from iterators. Assigns data to a Lump given two iterators from another Lump. This function follows the standard practice of the last iterator pointing to one past the last element desired.
Definition at line 943 of file lump.cpp. References assign(). |
|
||||||||||||
|
Assign data from a pointer. Assigns new data to a Lump. Copies the contents of a data buffer into this Lump. If the pointer to the input buffer is null and the size is not zero, this function throws an exception. Assigning with a null pointer and zero size is acceptable. It will clear the buffer. If a memory error occurs, it throws a std::bad_alloc. This function is atomic: if a memory error occurs, it does not overwrite its data.
Definition at line 885 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). Referenced by assign(), Lump(), Doomwad::Wad::readFromFile(), readFromFile(), and Doomwad::TextWadEntry::toLump(). |
|
|
Index function. Gets a const reference to the element at a specified location. This is like Lump::operator[] except this function checks array bounds and throws an exception if it is out of bounds.
Definition at line 739 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Index function. Gets a reference to the element at a specified location. This is like Lump::operator[] except this function checks array bounds and throws an exception if it is out of bounds.
Definition at line 713 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get constant iterator to start of data. Gets a const_iterator to the first data element.
|
|
|
Get iterator to start of data. Gets an iterator to the first data element.
Definition at line 293 of file lump.cpp. Referenced by setDString(). |
|
|
Clear all Lump contents. Erases all contents.
Definition at line 1390 of file lump.cpp. References clearData(), and clearName(). Referenced by clearName(), and ~Lump(). |
|
|
Clear the data buffer. Erases all data and sets the buffer to zero length.
Definition at line 1404 of file lump.cpp. References m_data, and m_size. Referenced by clear(), operator+=(), and operator=(). |
|
|
Clear the name. Clear the name and set to an empty string.
Definition at line 1422 of file lump.cpp. References clear(), and m_name. Referenced by clear(). |
|
|
Check if the Lump has no data. Checks the length of the Lump to see if it is zero.
Definition at line 1435 of file lump.cpp. References m_size. |
|
|
Get constant iterator to end of data. Gets a const_iterator to one past the last data element.
|
|
|
Get iterator to end of data. Gets an iterator to one past the last data element.
|
|
|
Get an integer from inside a Lump.
Definition at line 1461 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get a pointer to the data. Gets a const pointer to the data buffer.
Definition at line 993 of file lump.cpp. References m_data. |
|
|
Get a Doom string from inside a Lump.
Definition at line 2038 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1505 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1593 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). Referenced by Doomwad::GLNode::read(). |
|
|
Get an integer from inside a Lump.
Definition at line 1637 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1681 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1549 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get the name. Gets the name of this Lump.
Definition at line 964 of file lump.cpp. References m_name. |
|
|
Get an integer from inside a Lump.
Definition at line 1527 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get a string from inside a Lump.
Definition at line 2013 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1615 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). Referenced by Doomwad::GLNode::read(). |
|
|
Get an integer from inside a Lump.
Definition at line 1659 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1703 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1571 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Get an integer from inside a Lump.
Definition at line 1483 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Increase the size of the Lump's data. Grows the data buffer by a specified amount, padding with nulls. The amount is not the new amount, it is a relative size. For example, 5 means "grow by five bytes."
Definition at line 1013 of file lump.cpp. References Doomwad::exceptionString(), and Doomwad::EventLog::printLine(). |
|
|
Cast to bool. Tests whether there is data in the buffer (i.e. the length is greater than zero).
Definition at line 664 of file lump.cpp. References m_size. |
|
|
Cast to size_t. Gets the size of the data buffer.
Definition at line 651 of file lump.cpp. References m_size. |
|
|
Cast to std::string reference. Gets a reference to the object's name.
Definition at line 639 of file lump.cpp. References m_name. |
|
|
Inequality operator. Tests for inequality between two Lumps. See Lump::operator==().
Definition at line 627 of file lump.cpp. References m_name. |
|
|
Addition operator. Creates a new, temporary Lump that is a concatenation of this one and another. If a memory allocation error occurs, the function throws a bad_alloc.
Definition at line 547 of file lump.cpp. References Doomwad::exceptionString(), m_data, m_name, m_size, MAX_SIZE, and Doomwad::EventLog::printLine(). |
|
|
Concatenation operator. Appends the contents of a Lump object onto another. Name is not copied, but the contents of the source's data buffer is. Guaranteed to be atomic. If a memory allocation error occurs, no changes are made, and the function throws a bad_alloc. Will be efficient in terms of empty buffers (i.e. short circuit logic).
Definition at line 466 of file lump.cpp. References clearData(), Doomwad::exceptionString(), m_data, m_size, MAX_SIZE, and Doomwad::EventLog::printLine(). |
|
|
Assign from a WadEntry.
|
|
|
Assignment operator. Deeply copies a Lump object into this one. Guaranteed to be atomic. If an error occurs, the function does not make any changes and it throws a bad_alloc exception to the caller. After this is done, *this == lump.
Definition at line 395 of file lump.cpp. References clearData(), m_data, m_name, m_size, and Doomwad::EventLog::printLine(). |
|
|
Equality operator. Tests for equality between two Lumps. Two lumps are equal if their names are equal in accordance with std::string::operator==, their lengths are equal, and their data is equal in accordance with std::memcmp().
Definition at line 613 of file lump.cpp. References m_name. |
|