Athena IO Library
|
A Stream class for writing data to a memory position. More...
#include <MemoryWriter.hpp>
Public Member Functions | |
MemoryWriter (atUint8 *data, atUint64 length, bool takeOwnership=false) | |
This constructor references an existing buffer to write to in-place. More... | |
void | seek (atInt64 pos, SeekOrigin origin=SeekOrigin::Current) |
Sets the buffers position relative to the specified position. It seeks relative to the current position by default. More... | |
atUint64 | position () const |
Returns the current position in the stream. More... | |
atUint64 | length () const |
Returns the length of the stream. More... | |
bool | isOpen () const |
void | setData (atUint8 *data, atUint64 length, bool takeOwnership=false) |
Sets the buffer to the given one, deleting the current one if it owns it. More... | |
atUint8 * | data () const |
Returns a copy of the current buffer. Changes to the copy do not affect the buffer so it's perfectly safe to directly edit the buffer and use setData to set the new information. More... | |
void | setFilepath (const std::string &filepath) |
Sets the target file. More... | |
std::string | filepath () const |
Returns the target file. | |
void | save (const std::string &filename="") |
Saves the file to the specified file. More... | |
void | writeUBytes (const atUint8 *data, atUint64 len) |
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. If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead. More... | |
Public Member Functions inherited from athena::io::IStreamWriter | |
void | seekAlign32 () |
Sets the buffers position relative to the next 32-byte aligned position. | |
bool | atEnd () const |
Returns whether or not the stream is at the end. More... | |
void | writeUByte (atUint8 val) |
Writes a byte at the current position and advances the position by one byte. More... | |
void | writeVal (atUint8 val) |
void | writeValLittle (atUint8 val) |
void | writeValBig (atUint8 val) |
void | writeByte (atInt8 val) |
Writes a byte at the current position and advances the position by one byte. More... | |
void | writeVal (atInt8 val) |
void | writeValLittle (atInt8 val) |
void | writeValBig (atInt8 val) |
void | writeBytes (const void *data, atUint64 len) |
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. More... | |
void | writeInt16 (atInt16 val) |
Writes an Int16 to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (atInt16 val) |
void | writeInt16Little (atInt16 val) |
Writes an Int16 to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (atInt16 val) |
void | writeInt16Big (atInt16 val) |
Writes an Int16 to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (atInt16 val) |
void | writeUint16 (atUint16 val) |
Writes an Uint16 to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (atUint16 val) |
void | writeUint16Little (atUint16 val) |
Writes an Uint16 to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (atUint16 val) |
void | writeUint16Big (atUint16 val) |
Writes an Uint16 to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (atUint16 val) |
void | writeInt32 (atInt32 val) |
Writes an Int32 to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (atInt32 val) |
void | writeInt32Little (atInt32 val) |
Writes an Int32 to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (atInt32 val) |
void | writeInt32Big (atInt32 val) |
Writes an Int32 to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (atInt32 val) |
void | writeUint32 (atUint32 val) |
Writes an Uint32 to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (atUint32 val) |
void | writeUint32Little (atUint32 val) |
Writes an Uint32 to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (atUint32 val) |
void | writeUint32Big (atUint32 val) |
Writes an Uint32 to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (atUint32 val) |
void | writeInt64 (atInt64 val) |
Writes an Int64 to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (atInt64 val) |
void | writeInt64Little (atInt64 val) |
Writes an Int64 to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (atInt64 val) |
void | writeInt64Big (atInt64 val) |
Writes an Int64 to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (atInt64 val) |
void | writeUint64 (atUint64 val) |
Writes an Uint64 to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (atUint64 val) |
void | writeUint64Little (atUint64 val) |
Writes an Uint64 to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (atUint64 val) |
void | writeUint64Big (atUint64 val) |
Writes an Uint64 to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (atUint64 val) |
void | writeFloat (float val) |
Writes an float to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (float val) |
void | writeFloatLittle (float val) |
Writes an float to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (float val) |
void | writeFloatBig (float val) |
Writes an float to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (float val) |
void | writeDouble (double val) |
Writes an double to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (double val) |
void | writeDoubleLittle (double val) |
Writes an double to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (double val) |
void | writeDoubleBig (double val) |
Writes an double to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (double val) |
void | writeBool (bool val) |
Writes an bool to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (bool val) |
void | writeValLittle (bool val) |
void | writeValBig (bool val) |
void | writeVec2f (const atVec2f &vec) |
Writes an atVec2f (8 bytes) to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (const atVec2f &val) |
void | writeVec2fLittle (const atVec2f &vec) |
Writes an atVec2f (8 bytes) to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (const atVec2f &val) |
void | writeVec2fBig (const atVec2f &vec) |
Writes an atVec2f (8 bytes) to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (const atVec2f &val) |
void | writeVec3f (const atVec3f &vec) |
Writes an atVec3f (12 bytes) to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (const atVec3f &val) |
void | writeVec3fLittle (const atVec3f &vec) |
Writes an atVec3f (12 bytes) to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (const atVec3f &val) |
void | writeVec3fBig (const atVec3f &vec) |
Writes an atVec3f (12 bytes) to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (const atVec3f &val) |
void | writeVec4f (const atVec4f &vec) |
Writes an atVec4f (16 bytes) to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (const atVec4f &val) |
void | writeVec4fLittle (const atVec4f &vec) |
Writes an atVec4f (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (const atVec4f &val) |
void | writeVec4fBig (const atVec4f &vec) |
Writes an atVec4f (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (const atVec4f &val) |
void | writeVec2d (const atVec2d &vec) |
Writes an atVec2d (16 bytes) to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (const atVec2d &val) |
void | writeVec2dLittle (const atVec2d &vec) |
Writes an atVec2d (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (const atVec2d &val) |
void | writeVec2dBig (const atVec2d &vec) |
Writes an atVec2d (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (const atVec2d &val) |
void | writeVec3d (const atVec3d &vec) |
Writes an atVec3d (24 bytes) to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (const atVec3d &val) |
void | writeVec3dLittle (const atVec3d &vec) |
Writes an atVec3d (24 bytes) to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (const atVec3d &val) |
void | writeVec3dBig (const atVec3d &vec) |
Writes an atVec3d (24 bytes) to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (const atVec3d &val) |
void | writeVec4d (const atVec4d &vec) |
Writes an atVec4d (32 bytes) to the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeVal (const atVec4d &val) |
void | writeVec4dLittle (const atVec4d &vec) |
Writes an atVec4d (32 bytes) to the buffer and advances the buffer. It also swaps the bytes against little depending on the platform. More... | |
void | writeValLittle (const atVec4d &val) |
void | writeVec4dBig (const atVec4d &vec) |
Writes an atVec4d (32 bytes) to the buffer and advances the buffer. It also swaps the bytes against big depending on the platform. More... | |
void | writeValBig (const atVec4d &val) |
void | writeStringAsWString (const std::string &str, atInt32 fixedLen=-1) |
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeStringAsWStringLittle (const std::string &str, atInt32 fixedLen=-1) |
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeStringAsWStringBig (const std::string &str, atInt32 fixedLen=-1) |
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings. More... | |
void | writeString (const std::string &str, atInt32 fixedLen=-1) |
Writes an string to the buffer and advances the buffer. More... | |
void | writeVal (const std::string &val) |
void | writeWString (const std::wstring &str, atInt32 fixedLen=-1) |
Writes an wstring to the buffer and advances the buffer. More... | |
void | writeVal (const std::wstring &val) |
void | writeWStringLittle (const std::wstring &str, atInt32 fixedLen=-1) |
Writes an wstring to the buffer and advances the buffer. More... | |
void | writeValLittle (const std::wstring &val) |
void | writeWStringBig (const std::wstring &str, atInt32 fixedLen=-1) |
Writes an wstring to the buffer and advances the buffer. More... | |
void | writeValBig (const std::wstring &val) |
void | fill (atUint8 val, atUint64 length) |
void | fill (atInt8 val, atUint64 length) |
template<class T > | |
void | enumerate (const std::vector< T > &vector, typename std::enable_if< std::is_arithmetic< T >::value||std::is_same< T, atVec2f >::value||std::is_same< T, atVec3f >::value||std::is_same< T, atVec4f >::value >::type *=0) |
Performs automatic std::vector enumeration writes using numeric type T. More... | |
template<class T > | |
void | enumerateLittle (const std::vector< T > &vector, typename std::enable_if< std::is_arithmetic< T >::value||std::is_same< T, atVec2f >::value||std::is_same< T, atVec3f >::value||std::is_same< T, atVec4f >::value >::type *=0) |
Performs automatic std::vector enumeration writes using numeric type T. More... | |
template<class T > | |
void | enumerateBig (const std::vector< T > &vector, typename std::enable_if< std::is_arithmetic< T >::value||std::is_same< T, atVec2f >::value||std::is_same< T, atVec3f >::value||std::is_same< T, atVec4f >::value >::type *=0) |
Performs automatic std::vector enumeration writes using numeric type T. More... | |
template<class T > | |
void | enumerate (const std::vector< T > &vector, typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, atVec2f >::value &&!std::is_same< T, atVec3f >::value &&!std::is_same< T, atVec4f >::value >::type *=0) |
Performs automatic std::vector enumeration writes using non-numeric type T. More... | |
Public Member Functions inherited from athena::io::IStream | |
void | setEndian (Endian endian) |
Endian | endian () const |
bool | isBigEndian () const |
bool | isLittleEndian () const |
bool | hasError () const |
Protected Attributes | |
atUint8 * | m_data |
atUint64 | m_length |
atUint64 | m_position |
bool | m_bufferOwned |
std::string | m_filepath |
Path to the target file. | |
Protected Attributes inherited from athena::io::IStream | |
bool | m_hasError = false |
Endian | m_endian = BigEndian |
Additional Inherited Members | |
Protected Member Functions inherited from athena::io::IStream | |
void | setError () |
A Stream class for writing data to a memory position.
A Class for writing binary data to a file or memory stream, all work is done using a memory buffer, and not written directly to the disk this allows for fast, flexible code as well as the ability to quickly modify data
Definition at line 22 of file MemoryWriter.hpp.
|
explicit |
This constructor references an existing buffer to write to in-place.
data | The existing buffer |
length | The length of the existing buffer |
atUint8* athena::io::MemoryWriter::data | ( | ) | const |
Returns a copy of the current buffer.
Changes to the copy do not affect the buffer so it's perfectly safe to directly edit the buffer and use setData to set the new information.
|
inlinevirtual |
Returns the length of the stream.
Implements athena::io::IStreamWriter.
Definition at line 54 of file MemoryWriter.hpp.
|
inlinevirtual |
Returns the current position in the stream.
Implements athena::io::IStreamWriter.
Definition at line 47 of file MemoryWriter.hpp.
void athena::io::MemoryWriter::save | ( | const std::string & | filename = "" | ) |
Saves the file to the specified file.
filename | If not empty, the filename to save to |
|
virtual |
Sets the buffers position relative to the specified position.
It seeks relative to the current position by default.
position | where in the buffer to seek |
origin | The Origin to seek |
Implements athena::io::IStreamWriter.
Reimplemented in athena::io::MemoryCopyWriter.
void athena::io::MemoryWriter::setData | ( | atUint8 * | data, |
atUint64 | length, | ||
bool | takeOwnership = false |
||
) |
Sets the buffer to the given one, deleting the current one if it owns it.
data | The new buffer. |
length | The length of the new buffer. |
takeOwnership | Whether the Stream now owns the buffer. |
|
inline |
Sets the target file.
filepath | The path to write to. |
Definition at line 78 of file MemoryWriter.hpp.
|
virtual |
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. If you are needing to fill in an area please use IStreamWriter::fill(atUint64) instead.
data | The buffer to write |
length | The amount to write |
Implements athena::io::IStreamWriter.
Reimplemented in athena::io::MemoryCopyWriter.