mirror of
https://github.com/libAthena/athena.git
synced 2025-12-09 21:47:52 +00:00
header-based read/write optimizations
This commit is contained in:
@@ -30,31 +30,6 @@ FileReader::~FileReader()
|
||||
close();
|
||||
}
|
||||
|
||||
std::string FileReader::filename() const
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
void FileReader::setEndian(Endian endian)
|
||||
{
|
||||
m_endian = endian;
|
||||
}
|
||||
|
||||
Endian FileReader::endian() const
|
||||
{
|
||||
return m_endian;
|
||||
}
|
||||
|
||||
bool FileReader::isBigEndian() const
|
||||
{
|
||||
return (m_endian == Endian::BigEndian);
|
||||
}
|
||||
|
||||
bool FileReader::isLittleEndian() const
|
||||
{
|
||||
return (m_endian == Endian::LittleEndian);
|
||||
}
|
||||
|
||||
void FileReader::open()
|
||||
{
|
||||
m_fileHandle = fopen(m_filename.c_str(), "rb");
|
||||
@@ -76,11 +51,6 @@ void FileReader::close()
|
||||
return;
|
||||
}
|
||||
|
||||
bool FileReader::isOpen() const
|
||||
{
|
||||
return m_fileHandle != NULL;
|
||||
}
|
||||
|
||||
void FileReader::seek(atInt64 pos, SeekOrigin origin)
|
||||
{
|
||||
if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
||||
@@ -158,14 +128,6 @@ atUint8 FileReader::readUByte()
|
||||
return val;
|
||||
}
|
||||
|
||||
atInt8 FileReader::readByte()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");
|
||||
|
||||
return (atInt8)readUByte();
|
||||
}
|
||||
|
||||
atUint8* FileReader::readUBytes(atUint64 len)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -186,14 +148,6 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
|
||||
return fread(buf, 1, len, m_fileHandle);
|
||||
}
|
||||
|
||||
atInt8* FileReader::readBytes(atUint64 len)
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN(nullptr, "File not open for reading");
|
||||
|
||||
return (atInt8*)readUBytes(len);
|
||||
}
|
||||
|
||||
atUint16 FileReader::readUint16()
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -209,14 +163,6 @@ atUint16 FileReader::readUint16()
|
||||
return val;
|
||||
}
|
||||
|
||||
atInt16 FileReader::readInt16()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");
|
||||
|
||||
return (atInt16)readUint16();
|
||||
}
|
||||
|
||||
atUint32 FileReader::readUint32()
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -232,14 +178,6 @@ atUint32 FileReader::readUint32()
|
||||
return val;
|
||||
}
|
||||
|
||||
atInt32 FileReader::readInt32()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");
|
||||
|
||||
return (atInt32)readUint32();
|
||||
}
|
||||
|
||||
atUint64 FileReader::readUint64()
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -255,14 +193,6 @@ atUint64 FileReader::readUint64()
|
||||
return val;
|
||||
}
|
||||
|
||||
atInt64 FileReader::readInt64()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");
|
||||
|
||||
return (atInt64)readUint64();
|
||||
}
|
||||
|
||||
double FileReader::readDouble()
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -293,14 +223,6 @@ float FileReader::readFloat()
|
||||
return val;
|
||||
}
|
||||
|
||||
bool FileReader::readBool()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN(false, "File not open for reading");
|
||||
|
||||
return (readByte() != 0);
|
||||
}
|
||||
|
||||
atVec3f FileReader::readVec3f()
|
||||
{
|
||||
atVec3f val = {};
|
||||
|
||||
@@ -33,26 +33,6 @@ FileWriter::~FileWriter()
|
||||
close();
|
||||
}
|
||||
|
||||
void FileWriter::setEndian(Endian endian)
|
||||
{
|
||||
m_endian = endian;
|
||||
}
|
||||
|
||||
Endian FileWriter::endian() const
|
||||
{
|
||||
return m_endian;
|
||||
}
|
||||
|
||||
bool FileWriter::isBigEndian() const
|
||||
{
|
||||
return (m_endian == Endian::BigEndian);
|
||||
}
|
||||
|
||||
bool FileWriter::isLittleEndian() const
|
||||
{
|
||||
return (m_endian == Endian::LittleEndian);
|
||||
}
|
||||
|
||||
void FileWriter::open(bool overwrite)
|
||||
{
|
||||
if (overwrite)
|
||||
@@ -77,11 +57,6 @@ void FileWriter::close()
|
||||
return;
|
||||
}
|
||||
|
||||
bool FileWriter::isOpen() const
|
||||
{
|
||||
return m_fileHandle != NULL;
|
||||
}
|
||||
|
||||
void FileWriter::seek(atInt64 pos, SeekOrigin origin)
|
||||
{
|
||||
if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
|
||||
@@ -150,11 +125,6 @@ void FileWriter::writeUByte(atUint8 val)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeByte(atInt8 val)
|
||||
{
|
||||
writeUByte(val);
|
||||
}
|
||||
|
||||
void FileWriter::writeUBytes(const atUint8* data, atUint64 len)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -166,11 +136,6 @@ void FileWriter::writeUBytes(const atUint8* data, atUint64 len)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeBytes(const atInt8* data, atUint64 len)
|
||||
{
|
||||
writeUBytes((atUint8*)data, len);
|
||||
}
|
||||
|
||||
void FileWriter::writeUint16(atUint16 val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -185,11 +150,6 @@ void FileWriter::writeUint16(atUint16 val)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeInt16(atInt16 val)
|
||||
{
|
||||
writeUint16(val);
|
||||
}
|
||||
|
||||
void FileWriter::writeUint32(atUint32 val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -204,11 +164,6 @@ void FileWriter::writeUint32(atUint32 val)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeInt32(atInt32 val)
|
||||
{
|
||||
writeUint32(val);
|
||||
}
|
||||
|
||||
void FileWriter::writeUint64(atUint64 val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -223,11 +178,6 @@ void FileWriter::writeUint64(atUint64 val)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeInt64(atInt64 val)
|
||||
{
|
||||
writeUint64(val);
|
||||
}
|
||||
|
||||
void FileWriter::writeDouble(double val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -256,11 +206,6 @@ void FileWriter::writeFloat(float val)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeBool(bool val)
|
||||
{
|
||||
writeByte(val);
|
||||
}
|
||||
|
||||
void FileWriter::writeVec3f(atVec3f vec)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -420,10 +365,5 @@ void FileWriter::fill(atInt8 byte, atUint64 len)
|
||||
fwrite(&byte, 1, len, m_fileHandle);
|
||||
}
|
||||
|
||||
void FileWriter::fill(atUint8 byte, atUint64 len)
|
||||
{
|
||||
fill((atInt8)byte, len);
|
||||
}
|
||||
|
||||
}
|
||||
} // Athena
|
||||
|
||||
@@ -54,31 +54,6 @@ MemoryReader::~MemoryReader()
|
||||
m_data = NULL;
|
||||
}
|
||||
|
||||
void MemoryReader::setEndian(Endian endian)
|
||||
{
|
||||
m_endian = endian;
|
||||
}
|
||||
|
||||
Endian MemoryReader::endian() const
|
||||
{
|
||||
return m_endian;
|
||||
}
|
||||
|
||||
bool MemoryReader::isBigEndian() const
|
||||
{
|
||||
return (m_endian == Endian::BigEndian);
|
||||
}
|
||||
|
||||
bool MemoryReader::isLittleEndian() const
|
||||
{
|
||||
return (m_endian == Endian::LittleEndian);
|
||||
}
|
||||
|
||||
bool MemoryReader::isOpen() const
|
||||
{
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
void MemoryReader::seek(atInt64 position, SeekOrigin origin)
|
||||
{
|
||||
switch (origin)
|
||||
@@ -106,21 +81,6 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin)
|
||||
}
|
||||
}
|
||||
|
||||
bool MemoryReader::atEnd() const
|
||||
{
|
||||
return m_position >= m_length;
|
||||
}
|
||||
|
||||
atUint64 MemoryReader::position() const
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
atUint64 MemoryReader::length() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
void MemoryReader::setData(const atUint8* data, atUint64 length)
|
||||
{
|
||||
if (m_data)
|
||||
@@ -140,16 +100,6 @@ atUint8* MemoryReader::data() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MemoryReader::setFilepath(const std::string& filepath)
|
||||
{
|
||||
m_filepath = filepath;
|
||||
}
|
||||
|
||||
std::string MemoryReader::filepath() const
|
||||
{
|
||||
return m_filepath;
|
||||
}
|
||||
|
||||
void MemoryReader::seekBit(int bit)
|
||||
{
|
||||
if (!m_data)
|
||||
@@ -285,11 +235,6 @@ atInt16 MemoryReader::readInt16()
|
||||
return ret;
|
||||
}
|
||||
|
||||
atUint16 MemoryReader::readUint16()
|
||||
{
|
||||
return readInt16();
|
||||
}
|
||||
|
||||
atInt32 MemoryReader::readInt32()
|
||||
{
|
||||
if (!m_data)
|
||||
@@ -315,10 +260,6 @@ atInt32 MemoryReader::readInt32()
|
||||
return ret;
|
||||
}
|
||||
|
||||
atUint32 MemoryReader::readUint32()
|
||||
{
|
||||
return readInt32();
|
||||
}
|
||||
|
||||
atInt64 MemoryReader::readInt64()
|
||||
{
|
||||
@@ -345,11 +286,6 @@ atInt64 MemoryReader::readInt64()
|
||||
return ret;
|
||||
}
|
||||
|
||||
atUint64 MemoryReader::readUint64()
|
||||
{
|
||||
return readInt64();
|
||||
}
|
||||
|
||||
float MemoryReader::readFloat()
|
||||
{
|
||||
if (!m_data)
|
||||
@@ -566,11 +502,6 @@ std::wstring MemoryReader::readWString(atInt32 fixedLen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MemoryReader::setProgressCallback(std::function<void (int)> cb)
|
||||
{
|
||||
m_progressCallback = cb;
|
||||
}
|
||||
|
||||
void MemoryReader::loadData()
|
||||
{
|
||||
FILE* in;
|
||||
|
||||
@@ -56,31 +56,6 @@ MemoryWriter::~MemoryWriter()
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
||||
void MemoryWriter::setEndian(Endian endian)
|
||||
{
|
||||
m_endian = endian;
|
||||
}
|
||||
|
||||
Endian MemoryWriter::endian() const
|
||||
{
|
||||
return m_endian;
|
||||
}
|
||||
|
||||
bool MemoryWriter::isBigEndian() const
|
||||
{
|
||||
return (m_endian == Endian::BigEndian);
|
||||
}
|
||||
|
||||
bool MemoryWriter::isLittleEndian() const
|
||||
{
|
||||
return (m_endian == Endian::LittleEndian);
|
||||
}
|
||||
|
||||
bool MemoryWriter::isOpen() const
|
||||
{
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
void MemoryWriter::seek(atInt64 position, SeekOrigin origin)
|
||||
{
|
||||
switch (origin)
|
||||
@@ -117,31 +92,6 @@ void MemoryWriter::seek(atInt64 position, SeekOrigin origin)
|
||||
}
|
||||
}
|
||||
|
||||
bool MemoryWriter::atEnd() const
|
||||
{
|
||||
return m_position >= m_length;
|
||||
}
|
||||
|
||||
atUint64 MemoryWriter::position() const
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
atUint64 MemoryWriter::length() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
void MemoryWriter::setFilepath(const std::string& filepath)
|
||||
{
|
||||
m_filepath = filepath;
|
||||
}
|
||||
|
||||
std::string MemoryWriter::filepath() const
|
||||
{
|
||||
return m_filepath;
|
||||
}
|
||||
|
||||
void MemoryWriter::setData(const atUint8* data, atUint64 length)
|
||||
{
|
||||
if (m_data)
|
||||
@@ -249,11 +199,6 @@ void MemoryWriter::writeUByte(atUint8 val)
|
||||
m_position++;
|
||||
}
|
||||
|
||||
void MemoryWriter::writeByte(atInt8 val)
|
||||
{
|
||||
writeUByte(val);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -276,11 +221,6 @@ void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length)
|
||||
m_position += length;
|
||||
}
|
||||
|
||||
void MemoryWriter::writeBytes(const atInt8* data, atUint64 length)
|
||||
{
|
||||
writeUBytes((atUint8*)data, length);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeInt16(atInt16 val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -304,11 +244,6 @@ void MemoryWriter::writeInt16(atInt16 val)
|
||||
m_position += sizeof(atInt16);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeUint16(atUint16 val)
|
||||
{
|
||||
writeInt16(val);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeInt32(atInt32 val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -332,11 +267,6 @@ void MemoryWriter::writeInt32(atInt32 val)
|
||||
m_position += sizeof(atInt32);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeUint32(atUint32 val)
|
||||
{
|
||||
writeInt32(val);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeInt64(atInt64 val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -361,11 +291,6 @@ void MemoryWriter::writeInt64(atInt64 val)
|
||||
m_position += sizeof(atInt64);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeUint64(atUint64 val)
|
||||
{
|
||||
writeInt64(val);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeFloat(float val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -599,16 +524,6 @@ void MemoryWriter::fill(atUint8 val, atUint64 length)
|
||||
writeUByte(val);
|
||||
}
|
||||
|
||||
void MemoryWriter::fill(atInt8 val, atUint64 length)
|
||||
{
|
||||
fill((atUint8)val, length);
|
||||
}
|
||||
|
||||
void MemoryWriter::setProgressCallback(std::function<void (int)> cb)
|
||||
{
|
||||
m_progressCallback = cb;
|
||||
}
|
||||
|
||||
void MemoryWriter::resize(atUint64 newSize)
|
||||
{
|
||||
if (newSize < m_length)
|
||||
|
||||
Reference in New Issue
Block a user