mirror of https://github.com/libAthena/athena.git
* Get libzelda compiling
This commit is contained in:
parent
24f6a1715a
commit
2a5f4add1c
|
@ -12,11 +12,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 libZelda. If not, see <http://www.gnu.org/licenses/>
|
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
|
||||||
#ifndef __BINARYWRITER_HPP__
|
#ifndef __BINARYWRITER_HPP__
|
||||||
#define __BINARYWRITER_HPP__
|
#define __BINARYWRITER_HPP__
|
||||||
|
|
||||||
#include "Stream.hpp"
|
#include "Stream.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/*! \class BinaryWriter
|
/*! \class BinaryWriter
|
||||||
* \brief A Stream class for writing binary data
|
* \brief A Stream class for writing binary data
|
||||||
|
@ -25,40 +25,40 @@
|
||||||
* 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
|
||||||
* 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 BinaryWriter : public Stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*! \brief This constructor takes an existing buffer to write to.
|
/*! \brief This constructor takes an existing buffer to write to.
|
||||||
*
|
*
|
||||||
* \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
|
||||||
*/
|
*/
|
||||||
BinaryWriter(const Uint8* data, Uint64 length);
|
BinaryWriter(const Uint8* data, Uint64 length);
|
||||||
|
|
||||||
/*! \brief This constructor takes an existing Stream to write to.
|
/*! \brief This constructor takes an existing Stream to write to.
|
||||||
*
|
*
|
||||||
* \param stream The stream to write data to
|
* \param stream The stream to write data to
|
||||||
*/
|
*/
|
||||||
BinaryWriter(const Stream& stream);
|
BinaryWriter(const Stream& stream);
|
||||||
/*! \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);
|
BinaryWriter(const std::string& filename);
|
||||||
|
|
||||||
/*! \brief Saves the file to the specified file.
|
/*! \brief Saves the file to the specified file.
|
||||||
*
|
*
|
||||||
* \param filename If not empty, the filename to save to
|
* \param filename If not empty, the filename to save to
|
||||||
*/
|
*/
|
||||||
void save(const std::string& filename="");
|
void save(const std::string& filename="");
|
||||||
|
|
||||||
/*! \brief Writes an Int16 to the buffer and advances the buffer.
|
/*! \brief Writes an Int16 to the buffer and advances the buffer.
|
||||||
* It also swaps the bytes depending on the platform and Stream settings.
|
* It also swaps the bytes depending on the platform and Stream settings.
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeInt16(Int16 val);
|
void writeInt16(Int16 val);
|
||||||
|
|
||||||
/*! \brief Writes an Uint16 to the buffer and advances the buffer.
|
/*! \brief Writes an Uint16 to the buffer and advances the buffer.
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUInt16(Uint16);
|
void writeUInt16(Uint16);
|
||||||
|
|
||||||
/*! \brief Writes an Int32 to the buffer and advances the buffer.
|
/*! \brief Writes an Int32 to the buffer and advances the buffer.
|
||||||
|
@ -74,7 +74,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeInt32(Int32);
|
void writeInt32(Int32);
|
||||||
|
|
||||||
/*! \brief Writes an Uint32 to the buffer and advances the buffer.
|
/*! \brief Writes an Uint32 to the buffer and advances the buffer.
|
||||||
|
@ -82,7 +82,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUInt32(Uint32);
|
void writeUInt32(Uint32);
|
||||||
|
|
||||||
/*! \brief Writes an Int64 to the buffer and advances the buffer.
|
/*! \brief Writes an Int64 to the buffer and advances the buffer.
|
||||||
|
@ -90,7 +90,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeInt64(Int64);
|
void writeInt64(Int64);
|
||||||
|
|
||||||
/*! \brief Writes an Uint64 to the buffer and advances the buffer.
|
/*! \brief Writes an Uint64 to the buffer and advances the buffer.
|
||||||
|
@ -98,7 +98,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUInt64(Uint64);
|
void writeUInt64(Uint64);
|
||||||
|
|
||||||
/*! \brief Writes an float to the buffer and advances the buffer.
|
/*! \brief Writes an float to the buffer and advances the buffer.
|
||||||
|
@ -106,7 +106,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeFloat(float);
|
void writeFloat(float);
|
||||||
|
|
||||||
/*! \brief Writes an double to the buffer and advances the buffer.
|
/*! \brief Writes an double to the buffer and advances the buffer.
|
||||||
|
@ -114,7 +114,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeDouble(double);
|
void writeDouble(double);
|
||||||
|
|
||||||
/*! \brief Writes an bool to the buffer and advances the buffer.
|
/*! \brief Writes an bool to the buffer and advances the buffer.
|
||||||
|
@ -122,7 +122,7 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param val The value to write to the buffer
|
* \param val The value to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeBool(bool);
|
void writeBool(bool);
|
||||||
|
|
||||||
/*! \brief Writes an unicode string to the buffer and advances the buffer.
|
/*! \brief Writes an unicode string to the buffer and advances the buffer.
|
||||||
|
@ -130,13 +130,13 @@ public:
|
||||||
*
|
*
|
||||||
* \sa Endian
|
* \sa Endian
|
||||||
* \param str The string to write to the buffer
|
* \param str The string to write to the buffer
|
||||||
*/
|
*/
|
||||||
void writeUnicode(const std::string& str);
|
void writeUnicode(const std::string& str);
|
||||||
protected:
|
protected:
|
||||||
Int8 readByte();
|
Int8 readByte();
|
||||||
Int8* readBytes(Int64);
|
Int8* readBytes(Int64);
|
||||||
bool isOpenForReading();
|
bool isOpenForReading();
|
||||||
std::string m_filename;
|
std::string m_filepath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,11 +18,9 @@ public:
|
||||||
WiiSave();
|
WiiSave();
|
||||||
virtual ~WiiSave();
|
virtual ~WiiSave();
|
||||||
|
|
||||||
bool saveToFile(const std::string& filepath, Uint8* macAddress, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId);
|
|
||||||
|
|
||||||
void addFile(const std::string& filename, WiiFile* file);
|
void addFile(const std::string& filename, WiiFile* file);
|
||||||
WiiFile* getFile(const std::string& filename) const;
|
WiiFile* file(const std::string& filename) const;
|
||||||
std::unordered_map<std::string, WiiFile*>& getFileList();
|
std::unordered_map<std::string, WiiFile*>& fileList();
|
||||||
|
|
||||||
void setBanner(WiiBanner* banner);
|
void setBanner(WiiBanner* banner);
|
||||||
WiiBanner* banner() const;
|
WiiBanner* banner() const;
|
||||||
|
|
|
@ -13,49 +13,49 @@
|
||||||
// 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 libZelda. If not, see <http://www.gnu.org/licenses/>
|
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
#include "BinaryWriter.hpp"
|
#include "BinaryWriter.hpp"
|
||||||
#include "IOException.hpp"
|
#include "IOException.hpp"
|
||||||
#include "FileNotFoundException.hpp"
|
#include "FileNotFoundException.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
BinaryWriter::BinaryWriter(const Uint8* data, Uint64 length)
|
BinaryWriter::BinaryWriter(const Uint8* data, Uint64 length)
|
||||||
: Stream(data, length)
|
: Stream(data, length)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BinaryWriter::BinaryWriter(const Stream& stream) :
|
BinaryWriter::BinaryWriter(const Stream& stream) :
|
||||||
Stream(stream)
|
Stream(stream)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BinaryWriter::BinaryWriter(const std::string& filename)
|
BinaryWriter::BinaryWriter(const std::string& filename)
|
||||||
: m_filename(filename)
|
: m_filepath(filename)
|
||||||
{
|
{
|
||||||
m_length = 0x10;
|
m_length = 0x10;
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_data = new Uint8[m_length];
|
m_data = new Uint8[m_length];
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
throw IOException("Could not allocate memory!");
|
throw IOException("Could not allocate memory!");
|
||||||
memset(m_data, 0, m_length);
|
memset(m_data, 0, m_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::save(const std::string& filename)
|
void BinaryWriter::save(const std::string& filename)
|
||||||
{
|
{
|
||||||
if (filename.empty() && m_filename.empty())
|
if (filename.empty() && m_filepath.empty())
|
||||||
throw Exception("InvalidOperationException: BinaryWriter::Save() -> No file specified, cannot save.");
|
throw Exception("InvalidOperationException: BinaryWriter::Save() -> No file specified, cannot save.");
|
||||||
|
|
||||||
if (!filename.empty())
|
if (!filename.empty())
|
||||||
m_filename = filename;
|
m_filepath = filename;
|
||||||
|
|
||||||
FILE* out = fopen(m_filename.c_str(), "wb");
|
FILE* out = fopen(m_filepath.c_str(), "wb");
|
||||||
if (!out)
|
if (!out)
|
||||||
throw FileNotFoundException(m_filename);
|
throw FileNotFoundException(m_filepath);
|
||||||
|
|
||||||
Uint32 done = 0;
|
Uint32 done = 0;
|
||||||
Uint32 blocksize = BLOCKSZ;
|
Uint32 blocksize = BLOCKSZ;
|
||||||
|
@ -73,203 +73,203 @@ void BinaryWriter::save(const std::string& filename)
|
||||||
|
|
||||||
done += blocksize;
|
done += blocksize;
|
||||||
std::cout << "Wrote " << done << " bytes" << std::endl;
|
std::cout << "Wrote " << done << " bytes" << std::endl;
|
||||||
}while (done < m_length);
|
}while (done < m_length);
|
||||||
|
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8 BinaryWriter::readByte()
|
Int8 BinaryWriter::readByte()
|
||||||
{
|
{
|
||||||
throw IOException("Stream not open for reading");
|
throw IOException("Stream not open for reading");
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8* BinaryWriter::readBytes(Int64)
|
Int8* BinaryWriter::readBytes(Int64)
|
||||||
{
|
{
|
||||||
throw IOException("Stream not open for reading");
|
throw IOException("Stream not open for reading");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeInt16(Int16 val)
|
void BinaryWriter::writeInt16(Int16 val)
|
||||||
{
|
{
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(Uint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Int16) > m_length && m_autoResize)
|
if (m_position + sizeof(Int16) > m_length && m_autoResize)
|
||||||
resize(m_position + sizeof(Int16));
|
resize(m_position + sizeof(Int16));
|
||||||
else if (m_position > m_length)
|
else if (m_position > m_length)
|
||||||
throw IOException("BinaryWriter::WriteInt16() -> Position outside stream bounds");
|
throw IOException("BinaryWriter::WriteInt16() -> Position outside stream bounds");
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
val = swap16(val);
|
val = swap16(val);
|
||||||
|
|
||||||
*(Int16*)(m_data + m_position) = val;
|
*(Int16*)(m_data + m_position) = val;
|
||||||
m_position += sizeof(Int16);
|
m_position += sizeof(Int16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUInt16(Uint16 val)
|
void BinaryWriter::writeUInt16(Uint16 val)
|
||||||
{
|
{
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(Uint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Uint16) > m_length && m_autoResize)
|
if (m_position + sizeof(Uint16) > m_length && m_autoResize)
|
||||||
resize(m_position + sizeof(Uint16));
|
resize(m_position + sizeof(Uint16));
|
||||||
else if (m_position > m_length)
|
else if (m_position > m_length)
|
||||||
throw IOException("BinaryWriter::WriteUInt16() -> Position outside stream bounds");
|
throw IOException("BinaryWriter::WriteUInt16() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
val = swapU16(val);
|
val = swapU16(val);
|
||||||
|
|
||||||
*(Uint16*)(m_data + m_position) = val;
|
|
||||||
m_position += sizeof(Uint16);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeInt32(Int32 val)
|
|
||||||
{
|
|
||||||
if (m_bitPosition > 0)
|
|
||||||
{
|
|
||||||
m_bitPosition = 0;
|
|
||||||
m_position += sizeof(Uint8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_position + sizeof(Int32) > m_length && m_autoResize)
|
|
||||||
resize(m_position + sizeof(Int32));
|
|
||||||
else if (m_position > m_length)
|
|
||||||
throw IOException("BinaryWriter::WriteInt32() -> Position outside stream bounds");
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
*(Uint16*)(m_data + m_position) = val;
|
||||||
val = swap32(val);
|
m_position += sizeof(Uint16);
|
||||||
|
}
|
||||||
*(Int32*)(m_data + m_position) = val;
|
|
||||||
m_position += sizeof(Int32);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeUInt32(Uint32 val)
|
|
||||||
{
|
|
||||||
if (m_bitPosition > 0)
|
|
||||||
{
|
|
||||||
m_bitPosition = 0;
|
|
||||||
m_position += sizeof(Uint8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_position + sizeof(Uint32) > m_length && m_autoResize)
|
|
||||||
resize(m_position + sizeof(Uint32));
|
|
||||||
else if (m_position > m_length)
|
|
||||||
throw IOException("BinaryWriter::WriteUInt32() -> Position outside stream bounds");
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
|
||||||
val = swap32(val);
|
|
||||||
|
|
||||||
*(Uint32*)(m_data + m_position) = val;
|
|
||||||
m_position += sizeof(Uint32);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeInt64(Int64 val)
|
|
||||||
{
|
|
||||||
if (m_bitPosition > 0)
|
|
||||||
{
|
|
||||||
m_bitPosition = 0;
|
|
||||||
m_position += sizeof(Uint8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_position + sizeof(Int64) > m_length && m_autoResize)
|
|
||||||
resize(m_position + sizeof(Int64));
|
|
||||||
else if (m_position > m_length)
|
|
||||||
throw IOException("BinaryWriter::WriteInt64() -> Position outside stream bounds");
|
|
||||||
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
void BinaryWriter::writeInt32(Int32 val)
|
||||||
val = swap64(val);
|
|
||||||
|
|
||||||
*(Int64*)(m_data + m_position) = val;
|
|
||||||
m_position += sizeof(Int64);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeUInt64(Uint64 val)
|
|
||||||
{
|
{
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(Uint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(Uint64) > m_length && m_autoResize)
|
if (m_position + sizeof(Int32) > m_length && m_autoResize)
|
||||||
resize(m_position + sizeof(Uint64));
|
resize(m_position + sizeof(Int32));
|
||||||
else if (m_position > m_length)
|
else if (m_position > m_length)
|
||||||
throw IOException("BinaryWriter::WriteUInt64() -> Position outside stream bounds");
|
throw IOException("BinaryWriter::WriteInt32() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
|
val = swap32(val);
|
||||||
|
|
||||||
|
*(Int32*)(m_data + m_position) = val;
|
||||||
|
m_position += sizeof(Int32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryWriter::writeUInt32(Uint32 val)
|
||||||
|
{
|
||||||
|
if (m_bitPosition > 0)
|
||||||
|
{
|
||||||
|
m_bitPosition = 0;
|
||||||
|
m_position += sizeof(Uint8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_position + sizeof(Uint32) > m_length && m_autoResize)
|
||||||
|
resize(m_position + sizeof(Uint32));
|
||||||
|
else if (m_position > m_length)
|
||||||
|
throw IOException("BinaryWriter::WriteUInt32() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
|
val = swap32(val);
|
||||||
|
|
||||||
|
*(Uint32*)(m_data + m_position) = val;
|
||||||
|
m_position += sizeof(Uint32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryWriter::writeInt64(Int64 val)
|
||||||
|
{
|
||||||
|
if (m_bitPosition > 0)
|
||||||
|
{
|
||||||
|
m_bitPosition = 0;
|
||||||
|
m_position += sizeof(Uint8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_position + sizeof(Int64) > m_length && m_autoResize)
|
||||||
|
resize(m_position + sizeof(Int64));
|
||||||
|
else if (m_position > m_length)
|
||||||
|
throw IOException("BinaryWriter::WriteInt64() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
val = swap64(val);
|
val = swap64(val);
|
||||||
|
|
||||||
*(Uint64*)(m_data + m_position) = val;
|
|
||||||
m_position += sizeof(Uint64);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeFloat(float val)
|
|
||||||
{
|
|
||||||
if (m_bitPosition > 0)
|
|
||||||
{
|
|
||||||
m_bitPosition = 0;
|
|
||||||
m_position += sizeof(Uint8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_position + sizeof(float) > m_length && m_autoResize)
|
|
||||||
resize(m_position + sizeof(float));
|
|
||||||
else if (m_position > m_length)
|
|
||||||
throw IOException("BinaryWriter::WriteFloat() -> Position outside stream bounds");
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
*(Int64*)(m_data + m_position) = val;
|
||||||
|
m_position += sizeof(Int64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryWriter::writeUInt64(Uint64 val)
|
||||||
|
{
|
||||||
|
if (m_bitPosition > 0)
|
||||||
|
{
|
||||||
|
m_bitPosition = 0;
|
||||||
|
m_position += sizeof(Uint8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_position + sizeof(Uint64) > m_length && m_autoResize)
|
||||||
|
resize(m_position + sizeof(Uint64));
|
||||||
|
else if (m_position > m_length)
|
||||||
|
throw IOException("BinaryWriter::WriteUInt64() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
|
val = swap64(val);
|
||||||
|
|
||||||
|
*(Uint64*)(m_data + m_position) = val;
|
||||||
|
m_position += sizeof(Uint64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryWriter::writeFloat(float val)
|
||||||
|
{
|
||||||
|
if (m_bitPosition > 0)
|
||||||
|
{
|
||||||
|
m_bitPosition = 0;
|
||||||
|
m_position += sizeof(Uint8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_position + sizeof(float) > m_length && m_autoResize)
|
||||||
|
resize(m_position + sizeof(float));
|
||||||
|
else if (m_position > m_length)
|
||||||
|
throw IOException("BinaryWriter::WriteFloat() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
val = swapFloat(val);
|
val = swapFloat(val);
|
||||||
|
|
||||||
*(float*)(m_data + m_position) = val;
|
|
||||||
m_position += sizeof(float);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeDouble(double val)
|
|
||||||
{
|
|
||||||
if (m_bitPosition > 0)
|
|
||||||
{
|
|
||||||
m_bitPosition = 0;
|
|
||||||
m_position += sizeof(Uint8);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_position + sizeof(double) > m_length && m_autoResize)
|
|
||||||
resize(m_position + sizeof(double));
|
|
||||||
else if (m_position > m_length)
|
|
||||||
throw IOException("BinaryWriter::WriteDouble() -> Position outside stream bounds");
|
|
||||||
|
|
||||||
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
*(float*)(m_data + m_position) = val;
|
||||||
val = swapDouble(val);
|
m_position += sizeof(float);
|
||||||
|
}
|
||||||
*(double*)(m_data + m_position)= val;
|
|
||||||
m_position += sizeof(double);
|
void BinaryWriter::writeDouble(double val)
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryWriter::writeBool(bool val)
|
|
||||||
{
|
{
|
||||||
if (m_bitPosition > 0)
|
if (m_bitPosition > 0)
|
||||||
{
|
{
|
||||||
m_bitPosition = 0;
|
m_bitPosition = 0;
|
||||||
m_position += sizeof(Uint8);
|
m_position += sizeof(Uint8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_position + sizeof(bool) > m_length && m_autoResize)
|
if (m_position + sizeof(double) > m_length && m_autoResize)
|
||||||
resize(m_position + sizeof(bool));
|
resize(m_position + sizeof(double));
|
||||||
else if (m_position > m_length)
|
else if (m_position > m_length)
|
||||||
|
throw IOException("BinaryWriter::WriteDouble() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
|
||||||
|
val = swapDouble(val);
|
||||||
|
|
||||||
|
*(double*)(m_data + m_position)= val;
|
||||||
|
m_position += sizeof(double);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinaryWriter::writeBool(bool val)
|
||||||
|
{
|
||||||
|
if (m_bitPosition > 0)
|
||||||
|
{
|
||||||
|
m_bitPosition = 0;
|
||||||
|
m_position += sizeof(Uint8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_position + sizeof(bool) > m_length && m_autoResize)
|
||||||
|
resize(m_position + sizeof(bool));
|
||||||
|
else if (m_position > m_length)
|
||||||
throw IOException("BinaryWriter::WriteBool() -> Position outside stream bounds");
|
throw IOException("BinaryWriter::WriteBool() -> Position outside stream bounds");
|
||||||
|
|
||||||
|
|
||||||
*(bool*)(m_data + m_position) = val;
|
*(bool*)(m_data + m_position) = val;
|
||||||
m_position += sizeof(bool);
|
m_position += sizeof(bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryWriter::writeUnicode(const std::string& str)
|
void BinaryWriter::writeUnicode(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string tmpStr = "\xEF\xBB\xBF" + str;
|
std::string tmpStr = "\xEF\xBB\xBF" + str;
|
||||||
|
|
||||||
std::vector<short> tmp;
|
std::vector<short> tmp;
|
||||||
|
@ -280,11 +280,11 @@ void BinaryWriter::writeUnicode(const std::string& str)
|
||||||
{
|
{
|
||||||
if (chr != 0xFEFF)
|
if (chr != 0xFEFF)
|
||||||
writeInt16(chr);
|
writeInt16(chr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BinaryWriter::isOpenForReading()
|
bool BinaryWriter::isOpenForReading()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue