2015-03-01 20:42:39 +00:00
|
|
|
#ifndef ISTREAMWRITER_HPP
|
|
|
|
#define ISTREAMWRITER_HPP
|
|
|
|
|
2015-08-31 21:11:42 +00:00
|
|
|
#include "utf8proc.h"
|
2015-03-01 20:42:39 +00:00
|
|
|
#include "IStream.hpp"
|
|
|
|
|
|
|
|
namespace Athena
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
|
|
|
class IStreamWriter : public IStream
|
|
|
|
{
|
|
|
|
public:
|
2015-03-01 21:22:59 +00:00
|
|
|
virtual ~IStreamWriter() {}
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Sets the Endianness of the stream
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param endian The Endianness to set
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void setEndian(Endian endian)
|
|
|
|
{m_endian = endian;}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Returns the current Endianness of the stream
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @return The current Stream Endianness
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline Endian endian() const
|
|
|
|
{return m_endian;}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Returns whether the stream is BigEndian
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @return True for BigEndian; False for LittleEndian
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline bool isBigEndian() const
|
|
|
|
{return (m_endian == Endian::BigEndian);}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Returns whether the stream is LittleEndian
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @return True for LittleEndian; False for BigEndian
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline bool isLittleEndian() const
|
|
|
|
{return (m_endian == Endian::LittleEndian);}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Sets the buffers position relative to the specified position.<br />
|
2015-07-08 02:53:39 +00:00
|
|
|
* It seeks relative to the current position by default.
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param position where in the buffer to seek
|
|
|
|
* @param origin The location to seek relative to
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
virtual void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current)=0;
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Sets the buffers position relative to the next 32-byte aligned position.<br />
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Returns whether or not the stream is at the end.
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @return True if at end; False otherwise.
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline bool atEnd() const {return position() >= length();}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Returns the current position in the stream.
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @return The current position in the stream.
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
virtual atUint64 position() const=0;
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Returns whether or not the stream is at the end.
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @return True if at end; False otherwise.
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
virtual atUint64 length() const=0;
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes a byte at the current position and advances the position by one byte.
|
|
|
|
* @param val The value to write
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeUByte(atUint8 val) {writeUBytes(&val, 1);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atUint8 val) {writeUByte(val);}
|
|
|
|
inline void writeValLittle(atUint8 val) {writeUByte(val);}
|
|
|
|
inline void writeValBig(atUint8 val) {writeUByte(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes a byte at the current position and advances the position by one byte.
|
|
|
|
* @param val The value to write
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeByte(atInt8 val) {writeUByte(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atInt8 val) {writeByte(val);}
|
|
|
|
inline void writeValLittle(atInt8 val) {writeByte(val);}
|
|
|
|
inline void writeValBig(atInt8 val) {writeByte(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes the given buffer with the specified length, buffers can be bigger than the length
|
2015-07-08 02:53:39 +00:00
|
|
|
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param data The buffer to write
|
|
|
|
* @param length The amount to write
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
virtual void writeUBytes(const atUint8* data, atUint64 len)=0;
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes the given buffer with the specified length, buffers can be bigger than the length
|
2015-07-08 02:53:39 +00:00
|
|
|
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param data The buffer to write
|
|
|
|
* @param length The amount to write
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeBytes(const atInt8* data, atUint64 len) {writeUBytes((atUint8*)data, len);}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int16 to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeInt16(atInt16 val)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
utility::BigInt16(val);
|
|
|
|
else
|
|
|
|
utility::LittleInt16(val);
|
|
|
|
writeUBytes((atUint8*)&val, 2);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atInt16 val) {writeInt16(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int16 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeInt16Little(atInt16 val)
|
|
|
|
{
|
|
|
|
utility::LittleInt16(val);
|
|
|
|
writeUBytes((atUint8*)&val, 2);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atInt16 val) {writeInt16Little(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int16 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeInt16Big(atInt16 val)
|
|
|
|
{
|
|
|
|
utility::BigInt16(val);
|
|
|
|
writeUBytes((atUint8*)&val, 2);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atInt16 val) {writeInt16Big(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint16 to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeUint16(atUint16 val) {writeInt16(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atUint16 val) {writeUint16(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint16 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeUint16Little(atUint16 val) {writeInt16Little(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atUint16 val) {writeUint16Little(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint16 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeUint16Big(atUint16 val) {writeInt16Big(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atUint16 val) {writeUint16Big(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int32 to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeInt32(atInt32 val)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
utility::BigInt32(val);
|
|
|
|
else
|
|
|
|
utility::LittleInt32(val);
|
|
|
|
writeUBytes((atUint8*)&val, 4);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atInt32 val) {writeInt32(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int32 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeInt32Little(atInt32 val)
|
|
|
|
{
|
|
|
|
utility::LittleInt32(val);
|
|
|
|
writeUBytes((atUint8*)&val, 4);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atInt32 val) {writeInt32Little(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int32 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeInt32Big(atInt32 val)
|
|
|
|
{
|
|
|
|
utility::BigInt32(val);
|
|
|
|
writeUBytes((atUint8*)&val, 4);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atInt32 val) {writeInt32Big(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint32 to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeUint32(atUint32 val) {writeInt32(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atUint32 val) {writeUint32(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint32 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeUint32Little(atUint32 val) {writeInt32Little(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atUint32 val) {writeUint32Little(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint32 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeUint32Big(atUint32 val) {writeInt32Big(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atUint32 val) {writeUint32Big(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int64 to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeInt64(atInt64 val)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
utility::BigInt64(val);
|
|
|
|
else
|
|
|
|
utility::LittleInt64(val);
|
|
|
|
writeUBytes((atUint8*)&val, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atInt64 val) {writeInt64(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int64 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeInt64Little(atInt64 val)
|
|
|
|
{
|
|
|
|
utility::LittleInt64(val);
|
|
|
|
writeUBytes((atUint8*)&val, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atInt64 val) {writeInt64Little(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Int64 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeInt64Big(atInt64 val)
|
|
|
|
{
|
|
|
|
utility::BigInt64(val);
|
|
|
|
writeUBytes((atUint8*)&val, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atInt64 val) {writeInt64Big(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint64 to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeUint64(atUint64 val) {writeInt64(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atUint64 val) {writeUint64(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint64 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeUint64Little(atUint64 val) {writeInt64Little(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atUint64 val) {writeUint64Little(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an Uint64 to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeUint64Big(atUint64 val) {writeInt64Big(val);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atUint64 val) {writeUint64Big(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an float to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeFloat(float val)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
utility::BigFloat(val);
|
|
|
|
else
|
|
|
|
utility::LittleFloat(val);
|
|
|
|
writeUBytes((atUint8*)&val, 4);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(float val) {writeFloat(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an float to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeFloatLittle(float val)
|
|
|
|
{
|
|
|
|
utility::LittleFloat(val);
|
|
|
|
writeUBytes((atUint8*)&val, 4);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(float val) {writeFloatLittle(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an float to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeFloatBig(float val)
|
|
|
|
{
|
|
|
|
utility::BigFloat(val);
|
|
|
|
writeUBytes((atUint8*)&val, 4);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(float val) {writeFloatBig(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an double to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeDouble(double val)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
utility::BigDouble(val);
|
|
|
|
else
|
|
|
|
utility::LittleDouble(val);
|
|
|
|
writeUBytes((atUint8*)&val, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(double val) {writeDouble(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an double to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeDoubleLittle(double val)
|
|
|
|
{
|
|
|
|
utility::LittleDouble(val);
|
|
|
|
writeUBytes((atUint8*)&val, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(double val) {writeDoubleLittle(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an double to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param val The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeDoubleBig(double val)
|
|
|
|
{
|
|
|
|
utility::BigDouble(val);
|
|
|
|
writeUBytes((atUint8*)&val, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(double val) {writeDoubleBig(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an bool to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param val The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeBool(bool val) {writeUBytes((atUint8*)&val, 1);}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(bool val) {writeBool(val);}
|
2015-09-25 00:55:11 +00:00
|
|
|
inline void writeValLittle(bool val) {writeBool(val);}
|
|
|
|
inline void writeValBig(bool val) {writeBool(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec2f (8 bytes) to the buffer and advances the buffer.
|
2015-07-11 01:45:26 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param vec The value to write to the buffer
|
2015-07-11 01:45:26 +00:00
|
|
|
*/
|
|
|
|
inline void writeVec2f(atVec2f vec)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
{
|
|
|
|
utility::BigFloat(vec.vec[0]);
|
|
|
|
utility::BigFloat(vec.vec[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utility::LittleFloat(vec.vec[0]);
|
|
|
|
utility::LittleFloat(vec.vec[1]);
|
|
|
|
}
|
|
|
|
writeUBytes((atUint8*)&vec, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atVec2f val) {writeVec2f(val);}
|
2015-07-11 01:45:26 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec2f (8 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeVec2fLittle(atVec2f vec)
|
|
|
|
{
|
|
|
|
utility::LittleFloat(vec.vec[0]);
|
|
|
|
utility::LittleFloat(vec.vec[1]);
|
|
|
|
writeUBytes((atUint8*)&vec, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atVec2f val) {writeVec2fLittle(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec2f (8 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeVec2fBig(atVec2f vec)
|
|
|
|
{
|
|
|
|
utility::BigFloat(vec.vec[0]);
|
|
|
|
utility::BigFloat(vec.vec[1]);
|
|
|
|
writeUBytes((atUint8*)&vec, 8);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atVec2f val) {writeVec2fBig(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec3f (12 bytes) to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param vec The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeVec3f(atVec3f vec)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
{
|
|
|
|
utility::BigFloat(vec.vec[0]);
|
|
|
|
utility::BigFloat(vec.vec[1]);
|
|
|
|
utility::BigFloat(vec.vec[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utility::LittleFloat(vec.vec[0]);
|
|
|
|
utility::LittleFloat(vec.vec[1]);
|
|
|
|
utility::LittleFloat(vec.vec[2]);
|
|
|
|
}
|
|
|
|
writeUBytes((atUint8*)&vec, 12);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atVec3f val) {writeVec3f(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec3f (12 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeVec3fLittle(atVec3f vec)
|
|
|
|
{
|
|
|
|
utility::LittleFloat(vec.vec[0]);
|
|
|
|
utility::LittleFloat(vec.vec[1]);
|
|
|
|
utility::LittleFloat(vec.vec[2]);
|
|
|
|
writeUBytes((atUint8*)&vec, 12);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atVec3f val) {writeVec3fLittle(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec3f (12 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeVec3fBig(atVec3f vec)
|
|
|
|
{
|
|
|
|
utility::BigFloat(vec.vec[0]);
|
|
|
|
utility::BigFloat(vec.vec[1]);
|
|
|
|
utility::BigFloat(vec.vec[2]);
|
|
|
|
writeUBytes((atUint8*)&vec, 12);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atVec3f val) {writeVec3fBig(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec4f (16 bytes) to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param vec The value to write to the buffer
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeVec4f(atVec4f vec)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
{
|
|
|
|
utility::BigFloat(vec.vec[0]);
|
|
|
|
utility::BigFloat(vec.vec[1]);
|
|
|
|
utility::BigFloat(vec.vec[2]);
|
|
|
|
utility::BigFloat(vec.vec[3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utility::LittleFloat(vec.vec[0]);
|
|
|
|
utility::LittleFloat(vec.vec[1]);
|
|
|
|
utility::LittleFloat(vec.vec[2]);
|
|
|
|
utility::LittleFloat(vec.vec[3]);
|
|
|
|
}
|
|
|
|
writeUBytes((atUint8*)&vec, 16);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(atVec4f val) {writeVec4f(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec4f (16 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeVec4fLittle(atVec4f vec)
|
|
|
|
{
|
|
|
|
utility::LittleFloat(vec.vec[0]);
|
|
|
|
utility::LittleFloat(vec.vec[1]);
|
|
|
|
utility::LittleFloat(vec.vec[2]);
|
|
|
|
utility::LittleFloat(vec.vec[3]);
|
|
|
|
writeUBytes((atUint8*)&vec, 16);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(atVec4f val) {writeVec4fLittle(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an atVec4f (16 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeVec4fBig(atVec4f vec)
|
|
|
|
{
|
|
|
|
utility::BigFloat(vec.vec[0]);
|
|
|
|
utility::BigFloat(vec.vec[1]);
|
|
|
|
utility::BigFloat(vec.vec[2]);
|
|
|
|
utility::BigFloat(vec.vec[3]);
|
|
|
|
writeUBytes((atUint8*)&vec, 16);
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(atVec4f val) {writeVec4fBig(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-10-15 21:54:42 +00:00
|
|
|
/** @brief Writes an atVec2d (16 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec2d(atVec2d vec)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
{
|
|
|
|
utility::BigDouble(vec.vec[0]);
|
|
|
|
utility::BigDouble(vec.vec[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utility::LittleDouble(vec.vec[0]);
|
|
|
|
utility::LittleDouble(vec.vec[1]);
|
|
|
|
}
|
|
|
|
writeUBytes((atUint8*)&vec, 16);
|
|
|
|
}
|
|
|
|
inline void writeVal(atVec2d val) {writeVec2d(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec2d (16 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec2dLittle(atVec2d vec)
|
|
|
|
{
|
|
|
|
utility::LittleDouble(vec.vec[0]);
|
|
|
|
utility::LittleDouble(vec.vec[1]);
|
|
|
|
writeUBytes((atUint8*)&vec, 16);
|
|
|
|
}
|
|
|
|
inline void writeValLittle(atVec2d val) {writeVec2dLittle(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec2d (16 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec2dBig(atVec2d vec)
|
|
|
|
{
|
|
|
|
utility::BigDouble(vec.vec[0]);
|
|
|
|
utility::BigDouble(vec.vec[1]);
|
|
|
|
writeUBytes((atUint8*)&vec, 16);
|
|
|
|
}
|
|
|
|
inline void writeValBig(atVec2d val) {writeVec2dBig(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec3d (24 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec3d(atVec3d vec)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
{
|
|
|
|
utility::BigDouble(vec.vec[0]);
|
|
|
|
utility::BigDouble(vec.vec[1]);
|
|
|
|
utility::BigDouble(vec.vec[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utility::LittleDouble(vec.vec[0]);
|
|
|
|
utility::LittleDouble(vec.vec[1]);
|
|
|
|
utility::LittleDouble(vec.vec[2]);
|
|
|
|
}
|
|
|
|
writeUBytes((atUint8*)&vec, 24);
|
|
|
|
}
|
|
|
|
inline void writeVal(atVec3d val) {writeVec3d(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec3d (24 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec3dLittle(atVec3d vec)
|
|
|
|
{
|
|
|
|
utility::LittleDouble(vec.vec[0]);
|
|
|
|
utility::LittleDouble(vec.vec[1]);
|
|
|
|
utility::LittleDouble(vec.vec[2]);
|
|
|
|
writeUBytes((atUint8*)&vec, 24);
|
|
|
|
}
|
|
|
|
inline void writeValLittle(atVec3d val) {writeVec3dLittle(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec3d (24 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec3dBig(atVec3d vec)
|
|
|
|
{
|
|
|
|
utility::BigDouble(vec.vec[0]);
|
|
|
|
utility::BigDouble(vec.vec[1]);
|
|
|
|
utility::BigDouble(vec.vec[2]);
|
|
|
|
writeUBytes((atUint8*)&vec, 24);
|
|
|
|
}
|
|
|
|
inline void writeValBig(atVec3d val) {writeVec3dBig(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec4d (32 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec4d(atVec4d vec)
|
|
|
|
{
|
|
|
|
if (m_endian == BigEndian)
|
|
|
|
{
|
|
|
|
utility::BigDouble(vec.vec[0]);
|
|
|
|
utility::BigDouble(vec.vec[1]);
|
|
|
|
utility::BigDouble(vec.vec[2]);
|
|
|
|
utility::BigDouble(vec.vec[3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utility::LittleDouble(vec.vec[0]);
|
|
|
|
utility::LittleDouble(vec.vec[1]);
|
|
|
|
utility::LittleDouble(vec.vec[2]);
|
|
|
|
utility::LittleDouble(vec.vec[3]);
|
|
|
|
}
|
|
|
|
writeUBytes((atUint8*)&vec, 32);
|
|
|
|
}
|
|
|
|
inline void writeVal(atVec4d val) {writeVec4d(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec4d (32 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against little depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec4dLittle(atVec4d vec)
|
|
|
|
{
|
|
|
|
utility::LittleDouble(vec.vec[0]);
|
|
|
|
utility::LittleDouble(vec.vec[1]);
|
|
|
|
utility::LittleDouble(vec.vec[2]);
|
|
|
|
utility::LittleDouble(vec.vec[3]);
|
|
|
|
writeUBytes((atUint8*)&vec, 32);
|
|
|
|
}
|
|
|
|
inline void writeValLittle(atVec4d val) {writeVec4dLittle(val);}
|
|
|
|
|
|
|
|
/** @brief Writes an atVec4d (32 bytes) to the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes against big depending on the platform.
|
|
|
|
*
|
|
|
|
* @param vec The value to write to the buffer
|
|
|
|
*/
|
|
|
|
inline void writeVec4dBig(atVec4d vec)
|
|
|
|
{
|
|
|
|
utility::BigDouble(vec.vec[0]);
|
|
|
|
utility::BigDouble(vec.vec[1]);
|
|
|
|
utility::BigDouble(vec.vec[2]);
|
|
|
|
utility::BigDouble(vec.vec[3]);
|
|
|
|
writeUBytes((atUint8*)&vec, 32);
|
|
|
|
}
|
|
|
|
inline void writeValBig(atVec4d val) {writeVec4dBig(val);}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Converts a UTF8 string to a wide-char string in the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
|
|
|
*
|
|
|
|
* Endianness is set with setEndian
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
2015-07-21 19:04:25 +00:00
|
|
|
inline void writeStringAsWString(const std::string& str, atInt32 fixedLen = -1)
|
2015-07-08 02:53:39 +00:00
|
|
|
{
|
2015-08-25 06:48:53 +00:00
|
|
|
std::string tmpStr = "\xEF\xBB\xBF" + str;
|
2015-08-31 21:11:42 +00:00
|
|
|
const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(tmpStr.c_str());
|
2015-08-30 05:07:00 +00:00
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
while (*buf)
|
2015-08-30 05:07:00 +00:00
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
utf8proc_int32_t wc;
|
|
|
|
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
|
|
|
if (len < 0)
|
2015-08-30 05:07:00 +00:00
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
atWarning("invalid UTF-8 character while decoding");
|
|
|
|
return;
|
2015-08-30 05:07:00 +00:00
|
|
|
}
|
2015-08-31 21:11:42 +00:00
|
|
|
buf += len;
|
2015-08-25 06:48:53 +00:00
|
|
|
if (wc != 0xFEFF)
|
2015-08-31 21:11:42 +00:00
|
|
|
writeUint16(atUint16(wc));
|
2015-08-25 06:48:53 +00:00
|
|
|
}
|
|
|
|
writeUint16(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
utf8proc_int32_t wc = 0;
|
2015-08-25 06:48:53 +00:00
|
|
|
if (*buf)
|
2015-08-31 21:11:42 +00:00
|
|
|
{
|
|
|
|
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
atWarning("invalid UTF-8 character while decoding");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf += len;
|
|
|
|
}
|
2015-08-25 06:48:53 +00:00
|
|
|
|
|
|
|
if (wc == 0xFEFF)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-31 21:11:42 +00:00
|
|
|
writeUint16(atUint16(wc));
|
2015-08-25 06:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-08 02:53:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Converts a UTF8 string to a wide-char string in the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
|
|
|
*
|
|
|
|
* Endianness is little
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeStringAsWStringLittle(const std::string& str, atInt32 fixedLen = -1)
|
|
|
|
{
|
|
|
|
std::string tmpStr = "\xEF\xBB\xBF" + str;
|
2015-08-31 21:11:42 +00:00
|
|
|
const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(tmpStr.c_str());
|
2015-08-30 05:07:00 +00:00
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
while (*buf)
|
2015-08-30 05:07:00 +00:00
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
utf8proc_int32_t wc;
|
|
|
|
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
|
|
|
if (len < 0)
|
2015-08-30 05:07:00 +00:00
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
atWarning("invalid UTF-8 character while decoding");
|
|
|
|
return;
|
2015-08-30 05:07:00 +00:00
|
|
|
}
|
2015-08-31 21:11:42 +00:00
|
|
|
buf += len;
|
2015-08-25 06:48:53 +00:00
|
|
|
if (wc != 0xFEFF)
|
2015-08-31 21:11:42 +00:00
|
|
|
writeUint16Little(atUint16(wc));
|
2015-08-14 02:58:04 +00:00
|
|
|
}
|
|
|
|
writeUint16Little(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
utf8proc_int32_t wc = 0;
|
2015-08-25 06:48:53 +00:00
|
|
|
if (*buf)
|
2015-08-31 21:11:42 +00:00
|
|
|
{
|
|
|
|
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
atWarning("invalid UTF-8 character while decoding");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf += len;
|
|
|
|
}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-08-25 06:48:53 +00:00
|
|
|
if (wc == 0xFEFF)
|
2015-08-14 02:58:04 +00:00
|
|
|
{
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-31 21:11:42 +00:00
|
|
|
writeUint16Little(atUint16(wc));
|
2015-08-14 02:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Converts a UTF8 string to a wide-char string in the buffer and advances the buffer.
|
|
|
|
* It also swaps the bytes depending on the platform and Stream settings.
|
|
|
|
*
|
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
|
|
|
*
|
|
|
|
* Endianness is big
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeStringAsWStringBig(const std::string& str, atInt32 fixedLen = -1)
|
|
|
|
{
|
|
|
|
std::string tmpStr = "\xEF\xBB\xBF" + str;
|
2015-08-31 21:11:42 +00:00
|
|
|
const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(tmpStr.c_str());
|
2015-08-30 05:07:00 +00:00
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
while (*buf)
|
2015-08-30 05:07:00 +00:00
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
utf8proc_int32_t wc;
|
|
|
|
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
|
|
|
if (len < 0)
|
2015-08-30 05:07:00 +00:00
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
atWarning("invalid UTF-8 character while decoding");
|
|
|
|
return;
|
2015-08-30 05:07:00 +00:00
|
|
|
}
|
2015-08-31 21:11:42 +00:00
|
|
|
buf += len;
|
2015-08-25 06:48:53 +00:00
|
|
|
if (wc != 0xFEFF)
|
2015-08-31 21:11:42 +00:00
|
|
|
writeUint16Big(atUint16(wc));
|
2015-08-14 02:58:04 +00:00
|
|
|
}
|
|
|
|
writeUint16Big(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
2015-08-31 21:11:42 +00:00
|
|
|
utf8proc_int32_t wc = 0;
|
2015-08-25 06:48:53 +00:00
|
|
|
if (*buf)
|
2015-08-31 21:11:42 +00:00
|
|
|
{
|
|
|
|
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
atWarning("invalid UTF-8 character while decoding");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf += len;
|
|
|
|
}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-08-25 06:48:53 +00:00
|
|
|
if (wc == 0xFEFF)
|
2015-08-14 02:58:04 +00:00
|
|
|
{
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-31 21:11:42 +00:00
|
|
|
writeUint16Big(atUint16(wc));
|
2015-08-14 02:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an string to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeString(const std::string& str, atInt32 fixedLen = -1)
|
|
|
|
{
|
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
|
|
|
for (atUint8 c : str)
|
|
|
|
{
|
|
|
|
writeUByte(c);
|
|
|
|
|
|
|
|
if (c == '\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writeUByte(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto it = str.begin();
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
|
|
|
atUint8 chr;
|
|
|
|
if (it == str.end())
|
|
|
|
chr = 0;
|
|
|
|
else
|
|
|
|
chr = *it++;
|
|
|
|
writeUByte(chr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(const std::string& val) {writeString(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an wstring to the buffer and advances the buffer.
|
2015-07-08 02:53:39 +00:00
|
|
|
*
|
2015-09-08 03:02:58 +00:00
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
|
|
|
*
|
|
|
|
* Endianness is set with setEndian
|
2015-07-08 02:53:39 +00:00
|
|
|
*/
|
|
|
|
inline void writeWString(const std::wstring& str, atInt32 fixedLen = -1)
|
|
|
|
{
|
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
|
|
|
for (atUint16 c : str)
|
|
|
|
{
|
|
|
|
writeUint16(c);
|
|
|
|
|
|
|
|
if (c == L'\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writeUint16(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto it = str.begin();
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
|
|
|
atUint16 chr;
|
|
|
|
if (it == str.end())
|
|
|
|
chr = 0;
|
|
|
|
else
|
|
|
|
chr = *it++;
|
|
|
|
writeUint16(chr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeVal(const std::wstring& val) {writeWString(val);}
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an wstring to the buffer and advances the buffer.
|
|
|
|
*
|
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
|
|
|
*
|
|
|
|
* Endianness is little
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeWStringLittle(const std::wstring& str, atInt32 fixedLen = -1)
|
|
|
|
{
|
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
|
|
|
for (atUint16 c : str)
|
|
|
|
{
|
|
|
|
writeUint16Little(c);
|
|
|
|
|
|
|
|
if (c == L'\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writeUint16Little(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto it = str.begin();
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
|
|
|
atUint16 chr;
|
|
|
|
if (it == str.end())
|
|
|
|
chr = 0;
|
|
|
|
else
|
|
|
|
chr = *it++;
|
|
|
|
writeUint16Little(chr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValLittle(const std::wstring& val) {writeWStringLittle(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Writes an wstring to the buffer and advances the buffer.
|
|
|
|
*
|
|
|
|
* @param str The string to write to the buffer
|
|
|
|
* @param fixedLen If not -1, the number of characters to zero-fill string to
|
|
|
|
*
|
|
|
|
* Endianness is big
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
inline void writeWStringBig(const std::wstring& str, atInt32 fixedLen = -1)
|
|
|
|
{
|
|
|
|
if (fixedLen < 0)
|
|
|
|
{
|
|
|
|
for (atUint16 c : str)
|
|
|
|
{
|
|
|
|
writeUint16Big(c);
|
|
|
|
|
|
|
|
if (c == L'\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writeUint16Big(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto it = str.begin();
|
|
|
|
for (atInt32 i=0 ; i<fixedLen ; ++i)
|
|
|
|
{
|
|
|
|
atUint16 chr;
|
|
|
|
if (it == str.end())
|
|
|
|
chr = 0;
|
|
|
|
else
|
|
|
|
chr = *it++;
|
|
|
|
writeUint16Big(chr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 23:27:28 +00:00
|
|
|
inline void writeValBig(const std::wstring& val) {writeWStringBig(val);}
|
2015-08-14 02:58:04 +00:00
|
|
|
|
2015-07-08 02:53:39 +00:00
|
|
|
inline void fill(atUint8 val, atUint64 length)
|
|
|
|
{for (atUint64 l=0 ; l<length ; ++l) writeUBytes(&val, 1);}
|
|
|
|
inline void fill(atInt8 val, atUint64 length)
|
|
|
|
{fill((atUint8)val, length);}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Performs automatic std::vector enumeration writes using numeric type T
|
|
|
|
* @param vector The std::vector read from when writing data
|
|
|
|
*
|
|
|
|
* Endianness is set with setEndian
|
|
|
|
*/
|
2015-08-08 23:25:18 +00:00
|
|
|
template <class T>
|
|
|
|
void enumerate(const std::vector<T>& vector,
|
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value ||
|
|
|
|
std::is_same<T, atVec2f>::value ||
|
|
|
|
std::is_same<T, atVec3f>::value ||
|
|
|
|
std::is_same<T, atVec4f>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
for (const T& item : vector)
|
|
|
|
writeVal(item);
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Performs automatic std::vector enumeration writes using numeric type T
|
|
|
|
* @param vector The std::vector read from when writing data
|
|
|
|
*
|
|
|
|
* Endianness is little
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
template <class T>
|
|
|
|
void enumerateLittle(const std::vector<T>& vector,
|
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value ||
|
|
|
|
std::is_same<T, atVec2f>::value ||
|
|
|
|
std::is_same<T, atVec3f>::value ||
|
|
|
|
std::is_same<T, atVec4f>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
for (const T& item : vector)
|
|
|
|
writeValLittle(item);
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Performs automatic std::vector enumeration writes using numeric type T
|
|
|
|
* @param vector The std::vector read from when writing data
|
|
|
|
*
|
|
|
|
* Endianness is big
|
|
|
|
*/
|
2015-08-14 02:58:04 +00:00
|
|
|
template <class T>
|
|
|
|
void enumerateBig(const std::vector<T>& vector,
|
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value ||
|
|
|
|
std::is_same<T, atVec2f>::value ||
|
|
|
|
std::is_same<T, atVec3f>::value ||
|
|
|
|
std::is_same<T, atVec4f>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
for (const T& item : vector)
|
|
|
|
writeValBig(item);
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:02:58 +00:00
|
|
|
/** @brief Performs automatic std::vector enumeration writes using non-numeric type T
|
|
|
|
* @param vector The std::vector read from when writing data
|
|
|
|
*/
|
2015-08-08 23:25:18 +00:00
|
|
|
template <class T>
|
|
|
|
void enumerate(const std::vector<T>& vector,
|
|
|
|
typename std::enable_if<!std::is_arithmetic<T>::value &&
|
|
|
|
!std::is_same<T, atVec2f>::value &&
|
|
|
|
!std::is_same<T, atVec3f>::value &&
|
|
|
|
!std::is_same<T, atVec4f>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
for (const T& item : vector)
|
|
|
|
item.write(*this);
|
|
|
|
}
|
|
|
|
|
2015-07-08 02:53:39 +00:00
|
|
|
protected:
|
|
|
|
Endian m_endian;
|
2015-03-01 20:42:39 +00:00
|
|
|
};
|
2015-10-15 22:20:50 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
IStreamWriter& operator<<(IStreamWriter& lhs, const T& rhs)
|
|
|
|
{
|
2015-10-16 03:06:12 +00:00
|
|
|
lhs.writeVal(rhs);
|
2015-10-15 22:20:50 +00:00
|
|
|
return lhs;
|
|
|
|
}
|
2015-03-01 20:42:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // STREAMWRITER_HPP
|
|
|
|
|