16 #ifndef MEMORYREADER_HPP
17 #define MEMORYREADER_HPP
19 #include "Athena/IStreamReader.hpp"
49 MemoryReader(
const std::string& filename, std::function<
void(
int)> progressFun =
nullptr);
88 void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
121 void setData(
const atUint8* data, atUint64 length);
131 atUint8*
data()
const;
181 atUint64 readBytesToBuf(
void* buf, atUint64 len) {
return readUBytesToBuf(buf, len);}
182 atUint64 readUBytesToBuf(
void* buf, atUint64 len);
285 void setProgressCallback(std::function<
void(
int)> cb);
292 atUint64 m_bitPosition;
294 std::function<void(int)> m_progressCallback;
300 #ifndef MEMORYREADER_BASE
301 #define MEMORYREADER_BASE() \
303 typedef Athena::io::MemoryReader base
305 #endif // MEMORYREADER_BASE
307 #endif // MEMORYREADER_HPP
bool atEnd() const
Returns whether or not the stream is at the end.
atUint64 position() const
Returns the current position in the stream.
void setEndian(Endian endian)
Sets the Endianss of the stream.
void seek(atInt64 pos, SeekOrigin origin=SeekOrigin::Current)
Sets the buffers position relative to the specified position. It seeks relative to the current posit...
bool isLittleEndian() const
Returns whether the stream is LittleEndian.
atUint16 readUint16()
Reads a Uint16 and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
atInt8 readByte()
Reads a byte at the current position and advances the current position.
void seekAlign32()
Sets the buffers position relative to the next 32-byte aligned position.
atUint8 * readUBytes(atUint64 length)
Reads a byte at the current position and advances the current position.
atUint64 length() const
Returns whether or not the stream is at the end.
std::string readString(atInt32 maxlen=-1)
Reads a string and advances the position in the file.
atUint64 readUint64()
Reads a Uint64 and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
std::string m_filepath
Path to the target file.
void seekBit(int bit)
Seeks to the specified bit within the current byte.
MemoryReader(const atUint8 *data, atUint64 length)
This constructor takes an existing buffer to read from.
double readDouble()
Reads a double and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
atUint32 readUint32()
Reads a Uint32 and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
bool isOpen() const
Retuns whether or not the Stream is open.
atInt64 readInt64()
Reads a Int64 and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
atUint8 * data() const
Returns a copy of the current buffer. Changes to the copy do not affect the buffer so it's perfectly...
float readFloat()
Reads a float and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
bool readBit()
Reads a bit at the current position and advances the current position.
atUint8 readUByte()
Reads a byte at the current position and advances the current position.
void setFilepath(const std::string &filepath)
Sets the target file.
atInt8 * readBytes(atUint64 length)
Reads a byte at the current position and advances the current position.
atInt16 readInt16()
Reads a Int16 and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
bool isBigEndian() const
Returns whether the stream is BigEndian.
bool readBool()
Reads a bool and advances the current position.
Endian endian() const
Returns the current Endianness of the stream.
atInt32 readInt32()
Reads a Int32 and swaps to proper endianness depending on platform and Stream settings, and advances the current position.
std::string filepath() const
Returns the target file.
std::string readUnicode(atInt32 maxlen=-1)
Reads a Unicode string and advances the position in the file.
void setData(const atUint8 *data, atUint64 length)
Sets the buffer to the given one, deleting the current one. BEWARE: As this deletes the current buff...