updated MemoryCopyWriter

This commit is contained in:
Jack Andersen
2015-07-07 20:34:59 -10:00
parent ec38ba088e
commit 44e25e09ca
2 changed files with 85 additions and 15 deletions

View File

@@ -27,7 +27,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
explicit MemoryWriter(atUint8* data = nullptr, atUint64 length = 0x10);
explicit MemoryWriter(atUint8* data, atUint64 length);
/*! \brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
@@ -103,12 +103,11 @@ public:
void writeUBytes(const atUint8* data, atUint64 len);
protected:
MemoryWriter() {}
atUint8* m_data;
atUint64 m_length;
atUint64 m_position;
std::string m_filepath; //!< Path to the target file
private:
void resize(atUint64 newSize);
};
class MemoryCopyWriter : public MemoryWriter
@@ -120,7 +119,7 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
explicit MemoryCopyWriter(atUint8* data, atUint64 length);
explicit MemoryCopyWriter(atUint8* data=nullptr, atUint64 length=0x10);
/*! \brief This constructor creates an instance from a file on disk.
*
@@ -128,10 +127,36 @@ public:
*/
MemoryCopyWriter(const std::string& filename);
/*! \brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* \param position where in the buffer to seek
* \param origin The Origin to seek \sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
/*! \brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
* if that was not the intent.<br />
* Once you pass the data to setData <b>DO NOT</b> delete the buffer
* as Stream now owns the address, this is done to keep memory usage down.
* \param data The new buffer.
* \param length The length of the new buffer.
* \throw IOException
*/
void setData(const atUint8* data, atUint64 length);
/*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
*
* \param data The buffer to write
* \param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
protected:
std::unique_ptr<atUint8[]> m_dataCopy;
private:
void resize(atUint64 newSize);
};
}