Documentation for ByteArray and ByteStream

Former-commit-id: 4d2d0de93562077e030b4304b57f6c95b32185b5
This commit is contained in:
Gawaboumga
2016-02-21 14:32:59 +01:00
parent f540029825
commit d340553023
4 changed files with 594 additions and 0 deletions

View File

@@ -7,11 +7,25 @@
namespace Nz
{
/*!
* \brief Constructs a ByteStream object with a stream
*
* \remark Produces a NazaraAssert if stream is invalid
*/
inline ByteStream::ByteStream(Stream* stream)
{
NazaraAssert(stream, "Invalid stream");
m_context.stream = stream;
}
/*!
* \brief Constructs a ByteStream object by move semantic
*
* \param stream ByteStream to move into this
*/
inline ByteStream::ByteStream(ByteStream&& stream) :
m_ownedStream(std::move(stream.m_ownedStream)),
m_context(stream.m_context)
@@ -19,17 +33,35 @@ namespace Nz
stream.m_context.stream = nullptr;
}
/*!
* \brief Destructs the object and calls FlushBits
*
* \remark Produces a NazaraWarning if flush did not work
*
* \see FlushBits
*/
inline ByteStream::~ByteStream()
{
if (!FlushBits())
NazaraWarning("Failed to flush bits at serializer destruction");
}
/*!
* \brief Gets the stream endianness
* \return Type of the endianness
*/
inline Endianness ByteStream::GetDataEndianness() const
{
return m_context.endianness;
}
/*!
* \brief Gets the size of the byte stream
* \return Size of the stream
*/
inline Nz::UInt64 ByteStream::GetSize() const
{
if (m_context.stream)
@@ -38,11 +70,21 @@ namespace Nz
return 0;
}
/*!
* \brief Gets the internal stream
* \return Internal stream
*/
inline Stream* ByteStream::GetStream() const
{
return m_context.stream;
}
/*!
* \brief Flushes the stream
* \return true if flushing is successful
*/
inline bool ByteStream::FlushBits()
{
if (!m_context.stream)
@@ -59,6 +101,14 @@ namespace Nz
return true;
}
/*!
* \brief Reads data
* \return Number of data read
*
* \param buffer Preallocated buffer to contain information read
* \param size Size of the read and thus of the buffer
*/
inline std::size_t ByteStream::Read(void* ptr, std::size_t size)
{
if (!m_context.stream)
@@ -68,13 +118,29 @@ namespace Nz
return m_context.stream->Read(ptr, size);
}
/*!
* \brief Sets the stream endianness
*
* \param Type of the endianness
*/
inline void ByteStream::SetDataEndianness(Endianness endiannes)
{
m_context.endianness = endiannes;
}
/*!
* \brief Sets this with a stream
*
* \param stream Stream existing
*
* \remark Produces a NazaraAssert if stream is invalid
*/
inline void ByteStream::SetStream(Stream* stream)
{
NazaraAssert(stream, "Invalid stream");
// We don't want to lose some bits..
FlushBits();
@@ -82,6 +148,16 @@ namespace Nz
m_ownedStream.reset();
}
/*!
* \brief Writes data
* \return Number of data written
*
* \param buffer Preallocated buffer containing information to write
* \param size Size of the writting and thus of the buffer
*
* \remark Produces a NazaraAssert if buffer is nullptr
*/
inline void ByteStream::Write(const void* data, std::size_t size)
{
if (!m_context.stream)
@@ -91,6 +167,15 @@ namespace Nz
m_context.stream->Write(data, size);
}
/*!
* \brief Outputs a data from the stream
* \return A reference to this
*
* \param value Value to unserialize
*
* \remark Produces a NazaraError if unserialization failed
*/
template<typename T>
ByteStream& ByteStream::operator>>(T& value)
{
@@ -103,6 +188,15 @@ namespace Nz
return *this;
}
/*!
* \brief Adds the data to the stream
* \return A reference to this
*
* \param value Value to serialize
*
* \remark Produces a NazaraError if serialization failed
*/
template<typename T>
ByteStream& ByteStream::operator<<(const T& value)
{
@@ -115,6 +209,13 @@ namespace Nz
return *this;
}
/*!
* \brief Moves the other byte stream into this
* \return A reference to this
*
* \param stream ByteStream to move in this
*/
inline ByteStream& ByteStream::operator=(ByteStream&& stream)
{
m_context = stream.m_context;