* Refactor Stream and *Reader classes

This commit is contained in:
Phillip Stephens 2015-03-01 12:42:39 -08:00
parent 66962c554f
commit c28cfbaba6
40 changed files with 349 additions and 296 deletions

View File

@ -11,8 +11,8 @@ SOURCES += \
$$PWD/src/Athena/Utility.cpp \ $$PWD/src/Athena/Utility.cpp \
$$PWD/src/Athena/FileReader.cpp \ $$PWD/src/Athena/FileReader.cpp \
$$PWD/src/Athena/FileWriter.cpp \ $$PWD/src/Athena/FileWriter.cpp \
$$PWD/src/Athena/BinaryReader.cpp \ $$PWD/src/Athena/MemoryReader.cpp \
$$PWD/src/Athena/BinaryWriter.cpp \ $$PWD/src/Athena/MemoryWriter.cpp \
$$PWD/src/Athena/Global.cpp \ $$PWD/src/Athena/Global.cpp \
$$PWD/src/Athena/Checksums.cpp \ $$PWD/src/Athena/Checksums.cpp \
$$PWD/src/Athena/Compression.cpp \ $$PWD/src/Athena/Compression.cpp \
@ -24,7 +24,9 @@ SOURCES += \
win32:SOURCES += $$PWD/src/win32_largefilewrapper.c win32:SOURCES += $$PWD/src/win32_largefilewrapper.c
HEADERS += \ HEADERS += \
$$PWD/include/Athena/Stream.hpp \ $$PWD/include/Athena/IStream.hpp \
$$PWD/include/Athena/IStreamReader.hpp \
$$PWD/include/Athena/IStreamWriter.hpp \
$$PWD/include/Athena/Types.hpp \ $$PWD/include/Athena/Types.hpp \
$$PWD/include/Athena/Utility.hpp \ $$PWD/include/Athena/Utility.hpp \
$$PWD/include/Athena/Global.hpp \ $$PWD/include/Athena/Global.hpp \
@ -35,8 +37,8 @@ HEADERS += \
$$PWD/include/Athena/InvalidOperationException.hpp \ $$PWD/include/Athena/InvalidOperationException.hpp \
$$PWD/include/Athena/FileReader.hpp \ $$PWD/include/Athena/FileReader.hpp \
$$PWD/include/Athena/FileWriter.hpp \ $$PWD/include/Athena/FileWriter.hpp \
$$PWD/include/Athena/BinaryReader.hpp \ $$PWD/include/Athena/MemoryReader.hpp \
$$PWD/include/Athena/BinaryWriter.hpp \ $$PWD/include/Athena/MemoryWriter.hpp \
$$PWD/include/Athena/NotImplementedException.hpp \ $$PWD/include/Athena/NotImplementedException.hpp \
$$PWD/include/Athena/Checksums.hpp \ $$PWD/include/Athena/Checksums.hpp \
$$PWD/include/Athena/Compression.hpp \ $$PWD/include/Athena/Compression.hpp \

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ALTTP_ENUMS_HPP__ #ifndef ALTTP_ENUMS_HPP
#define __ALTTP_ENUMS_HPP__ #define ALTTP_ENUMS_HPP
#ifndef __DOXYGEN_IGNORE__ #ifndef __DOXYGEN_IGNORE__
@ -110,4 +110,4 @@ enum ALTTPTagAlong
} // zelda } // zelda
#endif // __DOXYGEN_IGNORE__ #endif // __DOXYGEN_IGNORE__
#endif // __ALTTP_ENUMS_HPP__ #endif // ALTTP_ENUMS_HPP

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ALTTP_FILE_HPP__ #ifndef ALTTP_FILE_HPP
#define __ALTTP_FILE_HPP__ #define ALTTP_FILE_HPP
#include "Athena/Types.hpp" #include "Athena/Types.hpp"
#include <vector> #include <vector>
@ -89,5 +89,5 @@ private:
}; };
} // zelda } // zelda
#endif // __ALTTP_FILE_HPP__ #endif // ALTTP_FILE_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ALTTP_FILE_READER_HPP__ #ifndef ALTTP_FILE_READER_HPP
#define __ALTTP_FILE_READER_HPP__ #define ALTTP_FILE_READER_HPP
#include <string> #include <string>
#include "Athena/Types.hpp" #include "Athena/Types.hpp"
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
#include "Athena/ALTTPQuest.hpp" #include "Athena/ALTTPQuest.hpp"
namespace Athena namespace Athena
@ -35,9 +35,9 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk. * all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader * \sa BinaryReader
*/ */
class ALTTPFileReader : protected BinaryReader class ALTTPFileReader : protected MemoryReader
{ {
BINARYREADER_BASE(); MEMORYREADER_BASE();
public: public:
/*! \brief This constructor takes an existing buffer to read from. /*! \brief This constructor takes an existing buffer to read from.
@ -66,5 +66,5 @@ private:
} // io } // io
} // zelda } // zelda
#endif // __ALTTP_FILE_READER_HPP__ #endif // ALTTP_FILE_READER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ALTTP_FILE_WRITER_HPP__ #ifndef ALTTP_FILE_WRITER_HPP
#define __ALTTP_FILE_WRITER_HPP__ #define ALTTP_FILE_WRITER_HPP
#include <string> #include <string>
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
#include "Athena/ALTTPQuest.hpp" #include "Athena/ALTTPQuest.hpp"
namespace Athena namespace Athena
@ -34,9 +34,9 @@ namespace io
* all work is done using a memory buffer, and not written directly to the disk. * all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader * \sa BinaryReader
*/ */
class ALTTPFileWriter : protected BinaryWriter class ALTTPFileWriter : protected MemoryWriter
{ {
BINARYWRITER_BASE(); MEMORYWRITER_BASE();
public: public:
/*! \brief This constructor takes an existing buffer to write to. /*! \brief This constructor takes an existing buffer to write to.
@ -68,5 +68,5 @@ private:
} // io } // io
} // zelda } // zelda
#endif // __ALTTP_FILE_WRITER_HPP__ #endif // ALTTP_FILE_WRITER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ALTTP_QUEST_HPP__ #ifndef ALTTP_QUEST_HPP
#define __ALTTP_QUEST_HPP__ #define ALTTP_QUEST_HPP
#include "Types.hpp" #include "Types.hpp"
#include <string> #include <string>
@ -684,5 +684,5 @@ private:
} // zelda } // zelda
#endif // __ALTTP_QUEST_HPP__ #endif // ALTTP_QUEST_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __ALTTP_STRUCTS_HPP__ #ifndef ALTTP_STRUCTS_HPP
#define __ALTTP_STRUCTS_HPP__ #define ALTTP_STRUCTS_HPP
#ifndef __DOXYGEN_IGNORE__ #ifndef __DOXYGEN_IGNORE__
@ -215,4 +215,4 @@ struct ALTTPProgressFlags2
} }
#endif // __DOXYGEN_IGNORE__ #endif // __DOXYGEN_IGNORE__
#endif // __ALTTP_STRUCTS_HPP__ #endif // ALTTP_STRUCTS_HPP

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __EXCEPTION_HPP__ #ifndef EXCEPTION_HPP
#define __EXCEPTION_HPP__ #define EXCEPTION_HPP
#include <string> #include <string>
#include <stdarg.h> #include <stdarg.h>
@ -93,4 +93,4 @@ protected:
} while(0) } while(0)
#endif #endif
#endif #endif // EXCEPTION_HPP

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __FILENOTFOUNDEXCEPTION_HPP__ #ifndef FILENOTFOUNDEXCEPTION_HPP
#define __FILENOTFOUNDEXCEPTION_HPP__ #define FILENOTFOUNDEXCEPTION_HPP
#include "Athena/Exception.hpp" #include "Athena/Exception.hpp"
@ -54,4 +54,4 @@ private:
#define THROW_FILE_NOT_FOUND_EXCEPTION(msg) \ #define THROW_FILE_NOT_FOUND_EXCEPTION(msg) \
do { throw Athena::error::FileNotFoundException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); } while(0) do { throw Athena::error::FileNotFoundException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); } while(0)
#endif #endif // FILENOTFOUNDEXCEPTION_HPP

View File

@ -16,7 +16,7 @@
#ifndef FILESTREAM_HPP #ifndef FILESTREAM_HPP
#define FILESTREAM_HPP #define FILESTREAM_HPP
#include "Athena/Stream.hpp" #include "Athena/IStreamReader.hpp"
#include <string> #include <string>
#include <cstdio> #include <cstdio>
@ -24,7 +24,7 @@ namespace Athena
{ {
namespace io namespace io
{ {
class FileReader : public Stream class FileReader : public IStreamReader
{ {
public: public:
FileReader(const std::string& filename); FileReader(const std::string& filename);

View File

@ -16,13 +16,13 @@
#ifndef FILEWRITER_HPP #ifndef FILEWRITER_HPP
#define FILEWRITER_HPP #define FILEWRITER_HPP
#include "Athena/Stream.hpp" #include "Athena/IStreamWriter.hpp"
namespace Athena namespace Athena
{ {
namespace io namespace io
{ {
class FileWriter : public Stream class FileWriter : public IStreamWriter
{ {
public: public:
FileWriter(const std::string& filename); FileWriter(const std::string& filename);
@ -71,7 +71,7 @@ private:
} // Athena } // Athena
#ifndef FILEWRITER_BASE #ifndef FILEWRITER_BASE
#define FILEWRITER_BASE \ #define FILEWRITER_BASE() \
private: \ private: \
typedef Athena::io::FileWriter base; typedef Athena::io::FileWriter base;

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __IOEXCEPTION_HPP__ #ifndef IOEXCEPTION_HPP
#define __IOEXCEPTION_HPP__ #define IOEXCEPTION_HPP
#include "Athena/Exception.hpp" #include "Athena/Exception.hpp"
@ -60,4 +60,5 @@ public:
throw Athena::error::IOException(std::string("IOException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ throw Athena::error::IOException(std::string("IOException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
} while(0) } while(0)
#endif #endif
#endif
#endif // IOEXCEPTION_HPP

View File

@ -0,0 +1,46 @@
// This file is part of libAthena.
//
// libAthena is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libAthena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef STREAM_HPP
#define STREAM_HPP
#include "Global.hpp"
#include "Athena/NotImplementedException.hpp"
namespace Athena
{
namespace io
{
std::ostream& operator<<(std::ostream& os, Endian& endian);
class IStream
{
public:
virtual ~IStream() {}
virtual void setEndian(Endian) = 0;
virtual Endian endian() const= 0;
virtual bool isBigEndian() const= 0;
virtual bool isLittleEndian()const= 0;
virtual bool isOpen() const= 0;
virtual void seek(atInt64, SeekOrigin)=0;
virtual bool atEnd() const= 0;
virtual atUint64 position() const= 0;
virtual atUint64 length() const= 0;
virtual void seekBit (int)=0;
};
}
}
#endif // STREAM_HPP

View File

@ -0,0 +1,44 @@
#ifndef ISTREAMREADER_HPP
#define ISTREAMREADER_HPP
#include "IStream.hpp"
namespace Athena
{
namespace io
{
class IStreamReader : public IStream
{
public:
virtual ~IStreamReader();
virtual void setEndian(Endian) = 0;
virtual Endian endian() const= 0;
virtual bool isBigEndian() const= 0;
virtual bool isLittleEndian()const= 0;
virtual bool isOpen() const= 0;
virtual void seek(atInt64, SeekOrigin)=0;
virtual bool atEnd() const= 0;
virtual atUint64 position() const= 0;
virtual atUint64 length() const= 0;
virtual void seekBit (int)=0;
virtual bool readBit()=0;
virtual atUint8 readUByte()=0;
virtual atInt8 readByte()=0;
virtual atUint8* readUBytes(atUint64)=0;
virtual atInt8* readBytes(atUint64)=0;
virtual atUint16 readUint16()=0;
virtual atInt16 readInt16()=0;
virtual atUint32 readUint32()=0;
virtual atInt32 readInt32()=0;
virtual atUint64 readUint64()=0;
virtual atInt64 readInt64()=0;
virtual double readDouble()=0;
virtual float readFloat()=0;
virtual bool readBool()=0;
virtual std::string readUnicode(atInt32)=0;
virtual std::string readString(atInt32)=0;
};
}
}
#endif // ISTREAMREADER

View File

@ -0,0 +1,46 @@
#ifndef ISTREAMWRITER_HPP
#define ISTREAMWRITER_HPP
#include "IStream.hpp"
namespace Athena
{
namespace io
{
class IStreamWriter : public IStream
{
public:
virtual ~IStreamWriter();
virtual void setEndian(Endian) = 0;
virtual Endian endian() const= 0;
virtual bool isBigEndian() const= 0;
virtual bool isLittleEndian()const= 0;
virtual bool isOpen() const= 0;
virtual void seek(atInt64, SeekOrigin)=0;
virtual bool atEnd() const= 0;
virtual atUint64 position() const= 0;
virtual atUint64 length() const= 0;
virtual void seekBit (int)=0;
virtual void writeBit (bool)=0;
virtual void writeUByte (atUint8)=0;
virtual void writeByte (atInt8)=0;
virtual void writeUBytes(atUint8*, atUint64)=0;
virtual void writeBytes (atInt8*, atUint64)=0;
virtual void writeUint16(atUint16)=0;
virtual void writeInt16 (atInt16)=0;
virtual void writeUint32(atUint32)=0;
virtual void writeInt32 (atInt32)=0;
virtual void writeUint64(atUint64)=0;
virtual void writeInt64 (atInt64)=0;
virtual void writeDouble(double)=0;
virtual void writeFloat (float)=0;
virtual void writeBool (bool)=0;
virtual void writeString(const std::string&)=0;
virtual void writeUnicode(const std::string&)=0;
virtual void fill(atUint8, atUint64)=0;
virtual void fill(atInt8, atUint64)=0;
};
}
}
#endif // STREAMWRITER_HPP

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __INVALID_OPERATION_EXCEPTION_HPP__ #ifndef INVALID_OPERATION_EXCEPTION_HPP
#define __INVALID_OPERATION_EXCEPTION_HPP__ #define INVALID_OPERATION_EXCEPTION_HPP
#include <string> #include <string>
#include <stdarg.h> #include <stdarg.h>
@ -60,4 +60,4 @@ public:
throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
} while(0) } while(0)
#endif #endif
#endif // __INVALID_OPERATION_EXCEPTION_HPP__ #endif // INVALID_OPERATION_EXCEPTION_HPP

View File

@ -13,8 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __MCFILE_HPP__ #ifndef MCFILE_HPP
#define __MCFILE_HPP__ #define MCFILE_HPP
#include "Athena/Global.hpp" #include "Athena/Global.hpp"
@ -48,4 +48,4 @@ private:
}; };
} // zelda } // zelda
#endif // __MCFILE_HPP__ #endif // MCFILE_HPP

View File

@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __MCFILEREADER_HPP__ #ifndef MCFILEREADER_HPP
#define __MCFILEREADER_HPP__ #define MCFILEREADER_HPP
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
namespace Athena namespace Athena
{ {
@ -34,9 +34,9 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk. * all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader * \sa BinaryReader
*/ */
class MCFileReader : public BinaryReader class MCFileReader : public MemoryReader
{ {
BINARYREADER_BASE(); MEMORYREADER_BASE();
public: public:
/*! /*!
* \brief This constructor takes an existing buffer to read from. * \brief This constructor takes an existing buffer to read from.
@ -64,5 +64,5 @@ public:
} // io } // io
} // zelda } // zelda
#endif // __MCFILEREADER_HPP__ #endif // MCFILEREADER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __MCFILEWRITER_HPP__ #ifndef MCFILEWRITER_HPP
#define __MCFILEWRITER_HPP__ #define MCFILEWRITER_HPP
#include "Athena/Types.hpp" #include "Athena/Types.hpp"
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
namespace Athena namespace Athena
{ {
@ -35,9 +35,9 @@ namespace io
* all work is done using a memory buffer, and not written directly from the disk. * all work is done using a memory buffer, and not written directly from the disk.
* \sa BinaryWriter * \sa BinaryWriter
*/ */
class MCFileWriter : protected BinaryWriter class MCFileWriter : protected MemoryWriter
{ {
BINARYWRITER_BASE(); MEMORYWRITER_BASE();
public: public:
/*! /*!
* \brief This constructor takes an existing buffer to write to. * \brief This constructor takes an existing buffer to write to.
@ -69,5 +69,5 @@ private:
} // io } // io
} // zelda } // zelda
#endif // __MCFILEWRITER_HPP__ #endif // MCFILEWRITER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -13,10 +13,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __BINARYREADER_HPP__ #ifndef MEMORYREADER_HPP
#define __BINARYREADER_HPP__ #define MEMORYREADER_HPP
#include "Athena/Stream.hpp" #include "Athena/IStreamReader.hpp"
#include <string> #include <string>
#include <functional> #include <functional>
@ -32,7 +32,7 @@ namespace io
* this allows for fast, flexible code as well as the ability to quickly modify data * this allows for fast, flexible code as well as the ability to quickly modify data
* \sa Stream * \sa Stream
*/ */
class BinaryReader : public Stream class MemoryReader : public IStreamReader
{ {
public: public:
/*! \brief This constructor takes an existing buffer to read from. /*! \brief This constructor takes an existing buffer to read from.
@ -40,15 +40,15 @@ public:
* \param data The existing buffer * \param data The existing buffer
* \param length The length of the existing buffer * \param length The length of the existing buffer
*/ */
BinaryReader(const atUint8* data, atUint64 length); MemoryReader(const atUint8* data, atUint64 length);
/*! \brief This constructor creates an instance from a file on disk. /*! \brief This constructor creates an instance from a file on disk.
* *
* \param filename The file to create the stream from * \param filename The file to create the stream from
*/ */
BinaryReader(const std::string& filename, std::function<void(int)> progressFun = nullptr); MemoryReader(const std::string& filename, std::function<void(int)> progressFun = nullptr);
virtual ~BinaryReader(); virtual ~MemoryReader();
/*! \brief Sets the Endianss of the stream /*! \brief Sets the Endianss of the stream
* *
@ -291,11 +291,11 @@ protected:
} // io } // io
} // Athena } // Athena
#ifndef BINARYREADER_BASE #ifndef MEMORYREADER_BASE
#define BINARYREADER_BASE() \ #define MEMORYREADER_BASE() \
private: \ private: \
typedef Athena::io::BinaryReader base typedef Athena::io::MemoryReader base
#endif // BINARYREADER_BASE #endif // MEMORYREADER_BASE
#endif // __BINARYREADER_HPP__ #endif // MEMORYREADER_HPP

View File

@ -13,10 +13,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __BINARYWRITER_HPP__ #ifndef MEMORYWRITER_HPP
#define __BINARYWRITER_HPP__ #define MEMORYWRITER_HPP
#include "Athena/Stream.hpp" #include "Athena/IStream.hpp"
#include <string> #include <string>
#include <functional> #include <functional>
@ -33,7 +33,7 @@ namespace io
* this allows for fast, flexible code as well as the ability to quickly modify data * this allows for fast, flexible code as well as the ability to quickly modify data
* \sa Stream * \sa Stream
*/ */
class BinaryWriter : public Stream class MemoryWriter : public IStream
{ {
public: public:
/*! \brief This constructor takes an existing buffer to write to. /*! \brief This constructor takes an existing buffer to write to.
@ -41,15 +41,15 @@ public:
* \param data The existing buffer * \param data The existing buffer
* \param length The length of the existing buffer * \param length The length of the existing buffer
*/ */
explicit BinaryWriter(atUint8* data = nullptr, atUint64 length=0x10); explicit MemoryWriter(atUint8* data = nullptr, atUint64 length=0x10);
/*! \brief This constructor creates an instance from a file on disk. /*! \brief This constructor creates an instance from a file on disk.
* *
* \param filename The file to create the stream from * \param filename The file to create the stream from
*/ */
BinaryWriter(const std::string& filename, std::function<void(int)> progressFun = nullptr); MemoryWriter(const std::string& filename, std::function<void(int)> progressFun = nullptr);
virtual ~BinaryWriter(); virtual ~MemoryWriter();
/*! \brief Sets the Endianss of the stream /*! \brief Sets the Endianss of the stream
* *
@ -291,9 +291,9 @@ private:
} }
} }
#ifndef BINARYWRITER_BASE #ifndef MEMORYWRITER_BASE
#define BINARYWRITER_BASE() \ #define MEMORYWRITER_BASE() \
private: \ private: \
typedef Athena::io::BinaryWriter base typedef Athena::io::MemoryWriter base
#endif // BINARYWRITER_BASE #endif // BINARYWRITER_BASE
#endif // __BINARY_WRITER_HPP__ #endif // MEMORYWRITER_HPP

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __SSFILE_HPP__ #ifndef SSFILE_HPP
#define __SSFILE_HPP__ #define SSFILE_HPP
#include "Athena/Global.hpp" #include "Athena/Global.hpp"
@ -62,5 +62,5 @@ private:
}; };
} }
#endif // __SSFILE_HPP__ #endif // SSFILE_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,19 +14,19 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __SSFILEREADER_HPP__ #ifndef SSFILEREADER_HPP
#define __SSFILEREADER_HPP__ #define SSFILEREADER_HPP
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
namespace Athena namespace Athena
{ {
class SkywardSwordFile; class SkywardSwordFile;
namespace io namespace io
{ {
class SkywardSwordFileReader : public BinaryReader class SkywardSwordFileReader : public MemoryReader
{ {
BINARYREADER_BASE(); MEMORYREADER_BASE();
public: public:
SkywardSwordFileReader(atUint8* data, atUint64 length); SkywardSwordFileReader(atUint8* data, atUint64 length);
@ -37,5 +37,5 @@ public:
} // io } // io
} // zelda } // zelda
#endif // __SSFILEREADER_HPP__ #endif // SSFILEREADER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __SSFILEWRITER_HPP__ #ifndef SSFILEWRITER_HPP
#define __SSFILEWRITER_HPP__ #define SSFILEWRITER_HPP
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
namespace Athena namespace Athena
{ {
@ -26,9 +26,9 @@ class SkywardSwordFile;
namespace io namespace io
{ {
class SkywardSwordFileWriter : public BinaryWriter class SkywardSwordFileWriter : public MemoryWriter
{ {
BINARYWRITER_BASE(); MEMORYWRITER_BASE();
public: public:
SkywardSwordFileWriter(atUint8* data, atUint64 len); SkywardSwordFileWriter(atUint8* data, atUint64 len);
SkywardSwordFileWriter(const std::string& filename); SkywardSwordFileWriter(const std::string& filename);
@ -37,5 +37,5 @@ public:
}; };
} }
} }
#endif // __SSFILEWRITER_HPP__ #endif // SSFILEWRITER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -17,7 +17,7 @@
#ifndef SSPRITEFILEREADER_HPP #ifndef SSPRITEFILEREADER_HPP
#define SSPRITEFILEREADER_HPP #define SSPRITEFILEREADER_HPP
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
namespace Athena namespace Athena
{ {
@ -29,9 +29,9 @@ class SpriteFile;
namespace io namespace io
{ {
class SpriteFileReader : public BinaryReader class SpriteFileReader : public MemoryReader
{ {
BINARYREADER_BASE(); MEMORYREADER_BASE();
public: public:
SpriteFileReader(atUint8* data, atUint64 length); SpriteFileReader(atUint8* data, atUint64 length);
SpriteFileReader(const std::string& filepath); SpriteFileReader(const std::string& filepath);

View File

@ -17,7 +17,7 @@
#ifndef SSPRITEFILEWRITER_HPP #ifndef SSPRITEFILEWRITER_HPP
#define SSPRITEFILEWRITER_HPP #define SSPRITEFILEWRITER_HPP
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
namespace Athena namespace Athena
{ {
@ -29,9 +29,9 @@ class SpriteFile;
namespace io namespace io
{ {
class SpriteFileWriter : public BinaryWriter class SpriteFileWriter : public MemoryWriter
{ {
BINARYWRITER_BASE(); MEMORYWRITER_BASE();
public: public:
SpriteFileWriter(atUint8* data, atUint64 length); SpriteFileWriter(atUint8* data, atUint64 length);

View File

@ -1,83 +0,0 @@
// This file is part of libAthena.
//
// libAthena is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libAthena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef STREAM_HPP
#define STREAM_HPP
#include "Global.hpp"
#include "Athena/NotImplementedException.hpp"
namespace Athena
{
namespace io
{
std::ostream& operator<<(std::ostream& os, Endian& endian);
class Stream
{
public:
virtual ~Stream() {}
virtual void setEndian(Endian) = 0;
virtual Endian endian() const= 0;
virtual bool isBigEndian() const= 0;
virtual bool isLittleEndian()const= 0;
virtual bool isOpen() const= 0;
virtual void seek(atInt64, SeekOrigin)=0;
virtual bool atEnd() const= 0;
virtual atUint64 position() const= 0;
virtual atUint64 length() const= 0;
public:
virtual void seekBit (int){THROW_NOT_IMPLEMENTED_EXCEPTION();}
// Reading
virtual bool readBit() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atUint8 readUByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atInt8 readByte() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atUint8* readUBytes(atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atInt8* readBytes(atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atUint16 readUint16() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atInt16 readInt16() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atUint32 readUint32() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atInt32 readInt32() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atUint64 readUint64() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual atInt64 readInt64() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual double readDouble() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual float readFloat() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual bool readBool() {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual std::string readUnicode(atInt32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual std::string readString(atInt32) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
// Writing
virtual void writeBit (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeUByte (atUint8){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeByte (atInt8){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeUBytes(atUint8*, atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeBytes (atInt8*, atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeUint16(atUint16){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeInt16 (atInt16){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeUint32(atUint32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeInt32 (atInt32){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeUint64(atUint64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeInt64 (atInt64){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeDouble(double){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeFloat (float){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeBool (bool){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeString(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void writeUnicode(const std::string&){THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void fill(atUint8, atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
virtual void fill(atInt8, atUint64) {THROW_NOT_IMPLEMENTED_EXCEPTION();}
};
}
}
#endif // STREAM_HPP

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __WIIIMAGE_HPP__ #ifndef WIIIMAGE_HPP
#define __WIIIMAGE_HPP__ #define WIIIMAGE_HPP
#include "Athena/Types.hpp" #include "Athena/Types.hpp"

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __WII__SAVE_HPP__ #ifndef WIISAVE_HPP
#define __WII__SAVE_HPP__ #define WIISAVE_HPP
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
@ -97,6 +97,6 @@ private:
}; };
} // zelda } // zelda
#endif // __WII__SAVE_HPP__ #endif // WIISAVE_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __WII_SAVE_READER_HPP__ #ifndef WIISAVEREADER_HPP
#define __WII_SAVE_READER_HPP__ #define WIISAVEREADER_HPP
#include "Athena/Global.hpp" #include "Athena/Global.hpp"
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
namespace Athena namespace Athena
{ {
@ -37,9 +37,9 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk. * all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader * \sa BinaryReader
*/ */
class WiiSaveReader : protected BinaryReader class WiiSaveReader : protected MemoryReader
{ {
BINARYREADER_BASE(); MEMORYREADER_BASE();
public: public:
/*! \brief This constructor takes an existing buffer to read from. /*! \brief This constructor takes an existing buffer to read from.
* *
@ -69,5 +69,5 @@ private:
} // io } // io
} // zelda } // zelda
#endif // __WII_SAVE_READER_HPP__ #endif // WIISAVEREADER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#ifndef __WII_SAVE_WRITER_HPP__ #ifndef WIISAVEWRITER_HPP
#define __WII_SAVE_WRITER_HPP__ #define WIISAVEWRITER_HPP
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
namespace Athena namespace Athena
{ {
@ -36,9 +36,9 @@ namespace io
* all work is done using a memory buffer, and not written directly to the disk. * all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader * \sa BinaryReader
*/ */
class WiiSaveWriter : protected BinaryWriter class WiiSaveWriter : protected MemoryWriter
{ {
BINARYWRITER_BASE(); MEMORYWRITER_BASE();
public: public:
/*! \brief This constructor creates an instance from a file on disk. /*! \brief This constructor creates an instance from a file on disk.
* *
@ -68,5 +68,5 @@ private:
} // io } // io
} // zelda } // zelda
#endif // __WII_SAVE_WRITER_HPP__ #endif // WIISAVEWRITER_HPP
#endif // ATHENA_NO_SAVES #endif // ATHENA_NO_SAVES

View File

@ -17,7 +17,7 @@
#ifndef __ZQUESTFILEREADER_HPP__ #ifndef __ZQUESTFILEREADER_HPP__
#define __ZQUESTFILEREADER_HPP__ #define __ZQUESTFILEREADER_HPP__
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
namespace Athena namespace Athena
{ {
@ -29,9 +29,9 @@ namespace io
/*! /*!
* \brief The ZQuestFileReader class * \brief The ZQuestFileReader class
*/ */
class ZQuestFileReader : protected BinaryReader class ZQuestFileReader : protected MemoryReader
{ {
BINARYREADER_BASE(); MEMORYREADER_BASE();
public: public:
/*! /*!

View File

@ -17,7 +17,7 @@
#ifndef __ZQUESTFILEWRITER_HPP__ #ifndef __ZQUESTFILEWRITER_HPP__
#define __ZQUESTFILEWRITER_HPP__ #define __ZQUESTFILEWRITER_HPP__
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
namespace Athena namespace Athena
{ {
@ -29,9 +29,9 @@ namespace io
/*! /*!
* \brief The ZQuestFileWriter class * \brief The ZQuestFileWriter class
*/ */
class ZQuestFileWriter : protected BinaryWriter class ZQuestFileWriter : protected MemoryWriter
{ {
BINARYWRITER_BASE(); MEMORYWRITER_BASE();
public: public:
/*! /*!

View File

@ -13,7 +13,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
#include "Athena/IOException.hpp" #include "Athena/IOException.hpp"
#include "Athena/FileNotFoundException.hpp" #include "Athena/FileNotFoundException.hpp"
#include "Athena/InvalidDataException.hpp" #include "Athena/InvalidDataException.hpp"
@ -34,7 +34,7 @@ namespace Athena
{ {
namespace io namespace io
{ {
BinaryReader::BinaryReader(const atUint8* data, atUint64 length) MemoryReader::MemoryReader(const atUint8* data, atUint64 length)
: m_length(length), : m_length(length),
m_position(0), m_position(0),
m_bitPosition(0), m_bitPosition(0),
@ -50,7 +50,7 @@ BinaryReader::BinaryReader(const atUint8* data, atUint64 length)
memcpy(m_data, data, m_length); memcpy(m_data, data, m_length);
} }
BinaryReader::BinaryReader(const std::string& filename, std::function<void(int)> progFun) MemoryReader::MemoryReader(const std::string& filename, std::function<void(int)> progFun)
: m_data(NULL), : m_data(NULL),
m_length(0), m_length(0),
m_filepath(filename), m_filepath(filename),
@ -62,38 +62,38 @@ BinaryReader::BinaryReader(const std::string& filename, std::function<void(int)>
loadData(); loadData();
} }
BinaryReader::~BinaryReader() MemoryReader::~MemoryReader()
{ {
delete[] m_data; delete[] m_data;
m_data = NULL; m_data = NULL;
} }
void BinaryReader::setEndian(Endian endian) void MemoryReader::setEndian(Endian endian)
{ {
m_endian = endian; m_endian = endian;
} }
Endian BinaryReader::endian() const Endian MemoryReader::endian() const
{ {
return m_endian; return m_endian;
} }
bool BinaryReader::isBigEndian() const bool MemoryReader::isBigEndian() const
{ {
return (m_endian == Endian::BigEndian); return (m_endian == Endian::BigEndian);
} }
bool BinaryReader::isLittleEndian() const bool MemoryReader::isLittleEndian() const
{ {
return (m_endian == Endian::LittleEndian); return (m_endian == Endian::LittleEndian);
} }
bool BinaryReader::isOpen() const bool MemoryReader::isOpen() const
{ {
return m_data != nullptr; return m_data != nullptr;
} }
void BinaryReader::seek(atInt64 position, SeekOrigin origin) void MemoryReader::seek(atInt64 position, SeekOrigin origin)
{ {
switch (origin) switch (origin)
{ {
@ -115,22 +115,22 @@ void BinaryReader::seek(atInt64 position, SeekOrigin origin)
} }
} }
bool BinaryReader::atEnd() const bool MemoryReader::atEnd() const
{ {
return m_position >= m_length; return m_position >= m_length;
} }
atUint64 BinaryReader::position() const atUint64 MemoryReader::position() const
{ {
return m_position; return m_position;
} }
atUint64 BinaryReader::length() const atUint64 MemoryReader::length() const
{ {
return m_length; return m_length;
} }
void BinaryReader::setData(const atUint8* data, atUint64 length) void MemoryReader::setData(const atUint8* data, atUint64 length)
{ {
if (m_data) if (m_data)
delete[] m_data; delete[] m_data;
@ -141,7 +141,7 @@ void BinaryReader::setData(const atUint8* data, atUint64 length)
m_bitPosition = 0; m_bitPosition = 0;
} }
atUint8* BinaryReader::data() const atUint8* MemoryReader::data() const
{ {
atUint8* ret = new atUint8[m_length]; atUint8* ret = new atUint8[m_length];
memset(ret, 0, m_length); memset(ret, 0, m_length);
@ -149,17 +149,17 @@ atUint8* BinaryReader::data() const
return ret; return ret;
} }
void BinaryReader::setFilepath(const std::string& filepath) void MemoryReader::setFilepath(const std::string& filepath)
{ {
m_filepath = filepath; m_filepath = filepath;
} }
std::string BinaryReader::filepath() const std::string MemoryReader::filepath() const
{ {
return m_filepath; return m_filepath;
} }
void BinaryReader::seekBit(int bit) void MemoryReader::seekBit(int bit)
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -170,7 +170,7 @@ void BinaryReader::seekBit(int bit)
m_bitPosition = bit; m_bitPosition = bit;
} }
bool BinaryReader::readBit() bool MemoryReader::readBit()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -189,7 +189,7 @@ bool BinaryReader::readBit()
return ret; return ret;
} }
atInt8 BinaryReader::readByte() atInt8 MemoryReader::readByte()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -205,7 +205,7 @@ atInt8 BinaryReader::readByte()
return *(atInt8*)(m_data + m_position++); return *(atInt8*)(m_data + m_position++);
} }
atUint8 BinaryReader::readUByte() atUint8 MemoryReader::readUByte()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -224,12 +224,12 @@ atUint8 BinaryReader::readUByte()
return *(atUint8*)(m_data + m_position++); return *(atUint8*)(m_data + m_position++);
} }
atInt8* BinaryReader::readBytes(atUint64 length) atInt8* MemoryReader::readBytes(atUint64 length)
{ {
return (atInt8*)readUBytes(length); return (atInt8*)readUBytes(length);
} }
atUint8* BinaryReader::readUBytes(atUint64 length) atUint8* MemoryReader::readUBytes(atUint64 length)
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -251,7 +251,7 @@ atUint8* BinaryReader::readUBytes(atUint64 length)
return ret; return ret;
} }
atInt16 BinaryReader::readInt16() atInt16 MemoryReader::readInt16()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -275,12 +275,12 @@ atInt16 BinaryReader::readInt16()
return ret; return ret;
} }
atUint16 BinaryReader::readUint16() atUint16 MemoryReader::readUint16()
{ {
return readInt16(); return readInt16();
} }
atInt32 BinaryReader::readInt32() atInt32 MemoryReader::readInt32()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -304,12 +304,12 @@ atInt32 BinaryReader::readInt32()
return ret; return ret;
} }
atUint32 BinaryReader::readUint32() atUint32 MemoryReader::readUint32()
{ {
return readInt32(); return readInt32();
} }
atInt64 BinaryReader::readInt64() atInt64 MemoryReader::readInt64()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -333,12 +333,12 @@ atInt64 BinaryReader::readInt64()
return ret; return ret;
} }
atUint64 BinaryReader::readUint64() atUint64 MemoryReader::readUint64()
{ {
return readInt64(); return readInt64();
} }
float BinaryReader::readFloat() float MemoryReader::readFloat()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -362,7 +362,7 @@ float BinaryReader::readFloat()
return ret; return ret;
} }
double BinaryReader::readDouble() double MemoryReader::readDouble()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -385,7 +385,7 @@ double BinaryReader::readDouble()
return ret; return ret;
} }
bool BinaryReader::readBool() bool MemoryReader::readBool()
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -403,7 +403,7 @@ bool BinaryReader::readBool()
return ret; return ret;
} }
std::string BinaryReader::readUnicode(atInt32 maxlen) std::string MemoryReader::readUnicode(atInt32 maxlen)
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -428,7 +428,7 @@ std::string BinaryReader::readUnicode(atInt32 maxlen)
return ret; return ret;
} }
std::string BinaryReader::readString(atInt32 maxlen) std::string MemoryReader::readString(atInt32 maxlen)
{ {
std::string ret = ""; std::string ret = "";
atUint8 chr = readByte(); atUint8 chr = readByte();
@ -447,12 +447,12 @@ std::string BinaryReader::readString(atInt32 maxlen)
return ret; return ret;
} }
void BinaryReader::setProgressCallback(std::function<void (int)> cb) void MemoryReader::setProgressCallback(std::function<void (int)> cb)
{ {
m_progressCallback = cb; m_progressCallback = cb;
} }
void BinaryReader::loadData() void MemoryReader::loadData()
{ {
FILE* in; FILE* in;
atUint64 length; atUint64 length;

View File

@ -13,7 +13,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with libAthena. If not, see <http://www.gnu.org/licenses/> // along with libAthena. If not, see <http://www.gnu.org/licenses/>
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
#include "Athena/IOException.hpp" #include "Athena/IOException.hpp"
#include "Athena/InvalidOperationException.hpp" #include "Athena/InvalidOperationException.hpp"
#include "Athena/InvalidDataException.hpp" #include "Athena/InvalidDataException.hpp"
@ -34,7 +34,7 @@ namespace Athena
namespace io namespace io
{ {
BinaryWriter::BinaryWriter(atUint8* data, atUint64 length) MemoryWriter::MemoryWriter(atUint8* data, atUint64 length)
: m_data((atUint8*)data), : m_data((atUint8*)data),
m_length(length), m_length(length),
m_position(0), m_position(0),
@ -46,7 +46,7 @@ BinaryWriter::BinaryWriter(atUint8* data, atUint64 length)
m_data = new atUint8[m_length]; m_data = new atUint8[m_length];
} }
BinaryWriter::BinaryWriter(const std::string& filename, std::function<void(int)> progressFun) MemoryWriter::MemoryWriter(const std::string& filename, std::function<void(int)> progressFun)
: m_length(0), : m_length(0),
m_filepath(filename), m_filepath(filename),
m_position(0), m_position(0),
@ -65,38 +65,38 @@ BinaryWriter::BinaryWriter(const std::string& filename, std::function<void(int)>
memset(m_data, 0, m_length); memset(m_data, 0, m_length);
} }
BinaryWriter::~BinaryWriter() MemoryWriter::~MemoryWriter()
{ {
delete[] m_data; delete[] m_data;
m_data = nullptr; m_data = nullptr;
} }
void BinaryWriter::setEndian(Endian endian) void MemoryWriter::setEndian(Endian endian)
{ {
m_endian = endian; m_endian = endian;
} }
Endian BinaryWriter::endian() const Endian MemoryWriter::endian() const
{ {
return m_endian; return m_endian;
} }
bool BinaryWriter::isBigEndian() const bool MemoryWriter::isBigEndian() const
{ {
return (m_endian == Endian::BigEndian); return (m_endian == Endian::BigEndian);
} }
bool BinaryWriter::isLittleEndian() const bool MemoryWriter::isLittleEndian() const
{ {
return (m_endian == Endian::LittleEndian); return (m_endian == Endian::LittleEndian);
} }
bool BinaryWriter::isOpen() const bool MemoryWriter::isOpen() const
{ {
return m_data != nullptr; return m_data != nullptr;
} }
void BinaryWriter::seek(atInt64 position, SeekOrigin origin) void MemoryWriter::seek(atInt64 position, SeekOrigin origin)
{ {
switch (origin) switch (origin)
{ {
@ -128,32 +128,32 @@ void BinaryWriter::seek(atInt64 position, SeekOrigin origin)
} }
} }
bool BinaryWriter::atEnd() const bool MemoryWriter::atEnd() const
{ {
return m_position >= m_length; return m_position >= m_length;
} }
atUint64 BinaryWriter::position() const atUint64 MemoryWriter::position() const
{ {
return m_position; return m_position;
} }
atUint64 BinaryWriter::length() const atUint64 MemoryWriter::length() const
{ {
return m_length; return m_length;
} }
void BinaryWriter::setFilepath(const std::string& filepath) void MemoryWriter::setFilepath(const std::string& filepath)
{ {
m_filepath = filepath; m_filepath = filepath;
} }
std::string BinaryWriter::filepath() const std::string MemoryWriter::filepath() const
{ {
return m_filepath; return m_filepath;
} }
void BinaryWriter::setData(const atUint8* data, atUint64 length) void MemoryWriter::setData(const atUint8* data, atUint64 length)
{ {
if (m_data) if (m_data)
delete[] m_data; delete[] m_data;
@ -164,7 +164,7 @@ void BinaryWriter::setData(const atUint8* data, atUint64 length)
m_bitPosition = 0; m_bitPosition = 0;
} }
atUint8* BinaryWriter::data() const atUint8* MemoryWriter::data() const
{ {
atUint8* ret = new atUint8[m_length]; atUint8* ret = new atUint8[m_length];
memset(ret, 0, m_length); memset(ret, 0, m_length);
@ -173,7 +173,7 @@ atUint8* BinaryWriter::data() const
} }
void BinaryWriter::save(const std::string& filename) void MemoryWriter::save(const std::string& filename)
{ {
if (filename.empty() && m_filepath.empty()) if (filename.empty() && m_filepath.empty())
THROW_INVALID_OPERATION_EXCEPTION("No file specified, cannot save."); THROW_INVALID_OPERATION_EXCEPTION("No file specified, cannot save.");
@ -205,7 +205,7 @@ void BinaryWriter::save(const std::string& filename)
fclose(out); fclose(out);
} }
void BinaryWriter::seekBit(int bit) void MemoryWriter::seekBit(int bit)
{ {
if (bit < 0 || bit > 7) if (bit < 0 || bit > 7)
THROW_INVALID_OPERATION_EXCEPTION("bit out of range"); THROW_INVALID_OPERATION_EXCEPTION("bit out of range");
@ -213,7 +213,7 @@ void BinaryWriter::seekBit(int bit)
m_bitPosition = bit; m_bitPosition = bit;
} }
void BinaryWriter::writeBit(bool val) void MemoryWriter::writeBit(bool val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -233,7 +233,7 @@ void BinaryWriter::writeBit(bool val)
} }
} }
void BinaryWriter::writeUByte(atUint8 val) void MemoryWriter::writeUByte(atUint8 val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -251,7 +251,7 @@ void BinaryWriter::writeUByte(atUint8 val)
m_position++; m_position++;
} }
void BinaryWriter::writeByte(atInt8 val) void MemoryWriter::writeByte(atInt8 val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -259,7 +259,7 @@ void BinaryWriter::writeByte(atInt8 val)
writeUByte(val); writeUByte(val);
} }
void BinaryWriter::writeUBytes(atUint8* data, atUint64 length) void MemoryWriter::writeUBytes(atUint8* data, atUint64 length)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -280,7 +280,7 @@ void BinaryWriter::writeUBytes(atUint8* data, atUint64 length)
m_position += length; m_position += length;
} }
void BinaryWriter::writeBytes(atInt8* data, atUint64 length) void MemoryWriter::writeBytes(atInt8* data, atUint64 length)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -288,7 +288,7 @@ void BinaryWriter::writeBytes(atInt8* data, atUint64 length)
writeUBytes((atUint8*)data, length); writeUBytes((atUint8*)data, length);
} }
void BinaryWriter::writeInt16(atInt16 val) void MemoryWriter::writeInt16(atInt16 val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -311,7 +311,7 @@ void BinaryWriter::writeInt16(atInt16 val)
m_position += sizeof(atInt16); m_position += sizeof(atInt16);
} }
void BinaryWriter::writeUint16(atUint16 val) void MemoryWriter::writeUint16(atUint16 val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -319,7 +319,7 @@ void BinaryWriter::writeUint16(atUint16 val)
writeInt16(val); writeInt16(val);
} }
void BinaryWriter::writeInt32(atInt32 val) void MemoryWriter::writeInt32(atInt32 val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -342,7 +342,7 @@ void BinaryWriter::writeInt32(atInt32 val)
m_position += sizeof(atInt32); m_position += sizeof(atInt32);
} }
void BinaryWriter::writeUint32(atUint32 val) void MemoryWriter::writeUint32(atUint32 val)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing"); THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
@ -350,7 +350,7 @@ void BinaryWriter::writeUint32(atUint32 val)
writeInt32(val); writeInt32(val);
} }
void BinaryWriter::writeInt64(atInt64 val) void MemoryWriter::writeInt64(atInt64 val)
{ {
if (m_bitPosition > 0) if (m_bitPosition > 0)
{ {
@ -371,7 +371,7 @@ void BinaryWriter::writeInt64(atInt64 val)
m_position += sizeof(atInt64); m_position += sizeof(atInt64);
} }
void BinaryWriter::writeUint64(atUint64 val) void MemoryWriter::writeUint64(atUint64 val)
{ {
if (m_bitPosition > 0) if (m_bitPosition > 0)
{ {
@ -392,7 +392,7 @@ void BinaryWriter::writeUint64(atUint64 val)
m_position += sizeof(atUint64); m_position += sizeof(atUint64);
} }
void BinaryWriter::writeFloat(float val) void MemoryWriter::writeFloat(float val)
{ {
if (m_bitPosition > 0) if (m_bitPosition > 0)
{ {
@ -413,7 +413,7 @@ void BinaryWriter::writeFloat(float val)
m_position += sizeof(float); m_position += sizeof(float);
} }
void BinaryWriter::writeDouble(double val) void MemoryWriter::writeDouble(double val)
{ {
if (m_bitPosition > 0) if (m_bitPosition > 0)
{ {
@ -433,7 +433,7 @@ void BinaryWriter::writeDouble(double val)
m_position += sizeof(double); m_position += sizeof(double);
} }
void BinaryWriter::writeBool(bool val) void MemoryWriter::writeBool(bool val)
{ {
if (m_bitPosition > 0) if (m_bitPosition > 0)
{ {
@ -448,7 +448,7 @@ void BinaryWriter::writeBool(bool val)
m_position += sizeof(bool); m_position += sizeof(bool);
} }
void BinaryWriter::writeUnicode(const std::string& str) void MemoryWriter::writeUnicode(const std::string& str)
{ {
std::string tmpStr = "\xEF\xBB\xBF" + str; std::string tmpStr = "\xEF\xBB\xBF" + str;
@ -464,7 +464,7 @@ void BinaryWriter::writeUnicode(const std::string& str)
writeInt16(0); writeInt16(0);
} }
void BinaryWriter::writeString(const std::string& str) void MemoryWriter::writeString(const std::string& str)
{ {
for (atUint8 c : str) for (atUint8 c : str)
{ {
@ -475,23 +475,23 @@ void BinaryWriter::writeString(const std::string& str)
writeUByte(0); writeUByte(0);
} }
void BinaryWriter::fill(atUint8 val, atUint64 length) void MemoryWriter::fill(atUint8 val, atUint64 length)
{ {
while ((length--) > 0) while ((length--) > 0)
writeUByte(val); writeUByte(val);
} }
void BinaryWriter::fill(atInt8 val, atUint64 length) void MemoryWriter::fill(atInt8 val, atUint64 length)
{ {
fill((atUint8)val, length); fill((atUint8)val, length);
} }
void BinaryWriter::setProgressCallback(std::function<void (int)> cb) void MemoryWriter::setProgressCallback(std::function<void (int)> cb)
{ {
m_progressCallback = cb; m_progressCallback = cb;
} }
void BinaryWriter::resize(atUint64 newSize) void MemoryWriter::resize(atUint64 newSize)
{ {
if (newSize < m_length) if (newSize < m_length)
THROW_INVALID_OPERATION_EXCEPTION("Stream::resize() -> New size cannot be less to the old size."); THROW_INVALID_OPERATION_EXCEPTION("Stream::resize() -> New size cannot be less to the old size.");

View File

@ -17,8 +17,8 @@
#include "Athena/WiiSave.hpp" #include "Athena/WiiSave.hpp"
#include "Athena/WiiFile.hpp" #include "Athena/WiiFile.hpp"
#include "Athena/WiiBanner.hpp" #include "Athena/WiiBanner.hpp"
#include "Athena/BinaryReader.hpp" #include "Athena/MemoryReader.hpp"
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
#include "Athena/Utility.hpp" #include "Athena/Utility.hpp"
#include "aes.h" #include "aes.h"
#include "ec.h" #include "ec.h"

View File

@ -68,13 +68,10 @@ WiiSave* WiiSaveReader::readSave()
THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header size"); THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header size");
atUint32 bkMagic = base::readUint32(); atUint32 bkMagic = base::readUint32();
bkMagic = bkMagic;
if (bkMagic != 0x426B0001) if (bkMagic != 0x426B0001)
THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header magic"); THROW_INVALID_DATA_EXCEPTION("Invalid BacKup header magic");
atUint32 ngId = base::readUint32(); atUint32 ngId = base::readUint32();
ngId = ngId;
atUint32 numFiles = base::readUint32(); atUint32 numFiles = base::readUint32();
/*int fileSize =*/ base::readUint32(); /*int fileSize =*/ base::readUint32();

View File

@ -22,7 +22,7 @@
#include "Athena/WiiSave.hpp" #include "Athena/WiiSave.hpp"
#include "Athena/WiiFile.hpp" #include "Athena/WiiFile.hpp"
#include "Athena/WiiBanner.hpp" #include "Athena/WiiBanner.hpp"
#include "Athena/BinaryWriter.hpp" #include "Athena/MemoryWriter.hpp"
#include "Athena/Utility.hpp" #include "Athena/Utility.hpp"
#include "Athena/InvalidOperationException.hpp" #include "Athena/InvalidOperationException.hpp"
#include "Athena/InvalidDataException.hpp" #include "Athena/InvalidDataException.hpp"

View File

@ -1,6 +1,6 @@
#include "LZ77/LZLookupTable.hpp" #include "LZ77/LZLookupTable.hpp"
#include "LZ77/LZType10.hpp" #include "LZ77/LZType10.hpp"
#include <Athena/BinaryWriter.hpp> #include <Athena/MemoryWriter.hpp>
#include <memory.h> #include <memory.h>
LZType10::LZType10(atInt32 MinimumOffset, atInt32 SlidingWindow, atInt32 MinimumMatch, atInt32 BlockSize) LZType10::LZType10(atInt32 MinimumOffset, atInt32 SlidingWindow, atInt32 MinimumMatch, atInt32 BlockSize)
@ -16,7 +16,7 @@ atUint32 LZType10::compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLe
atUint32 encodeSize=(srcLength<<8)|(0x10); atUint32 encodeSize=(srcLength<<8)|(0x10);
encodeSize = Athena::utility::LittleUint32(encodeSize); //File size needs to be written as little endian always encodeSize = Athena::utility::LittleUint32(encodeSize); //File size needs to be written as little endian always
Athena::io::BinaryWriter outbuf("tmp"); Athena::io::MemoryWriter outbuf("tmp");
outbuf.writeUint32(encodeSize); outbuf.writeUint32(encodeSize);
atUint8* ptrStart=(atUint8*)src; atUint8* ptrStart=(atUint8*)src;

View File

@ -1,6 +1,6 @@
#include "LZ77/LZLookupTable.hpp" #include "LZ77/LZLookupTable.hpp"
#include "LZ77/LZType11.hpp" #include "LZ77/LZType11.hpp"
#include <Athena/BinaryWriter.hpp> #include <Athena/MemoryWriter.hpp>
#include <memory.h> #include <memory.h>
@ -13,7 +13,7 @@ LZType11::LZType11(atInt32 minimumOffset, atInt32 slidingWindow, atInt32 minimum
atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLength) atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLength)
{ {
Athena::io::BinaryWriter outbuff("tmp"); Athena::io::MemoryWriter outbuff("tmp");
if (srcLength>0xFFFFFF){// If length is greater than 24 bits or 16 Megs if (srcLength>0xFFFFFF){// If length is greater than 24 bits or 16 Megs
atUint32 encodeFlag=0x11; atUint32 encodeFlag=0x11;
Athena::utility::LittleUint32(encodeFlag); Athena::utility::LittleUint32(encodeFlag);