Core: Add OwnedMemoryStream class

This commit is contained in:
SirLynix 2023-03-03 13:16:33 +01:00
parent 2629d2052e
commit 3000345eab
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_OWNEDMEMORYSTREAM_HPP
#define NAZARA_CORE_OWNEDMEMORYSTREAM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/MemoryStream.hpp>
namespace Nz
{
class NAZARA_CORE_API OwnedMemoryStream : public MemoryStream
{
public:
inline OwnedMemoryStream(OpenModeFlags openMode = OpenMode_ReadWrite);
inline OwnedMemoryStream(ByteArray byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
OwnedMemoryStream(const OwnedMemoryStream&) = delete;
OwnedMemoryStream(OwnedMemoryStream&&) noexcept = default;
~OwnedMemoryStream() = default;
OwnedMemoryStream& operator=(const OwnedMemoryStream&) = delete;
OwnedMemoryStream& operator=(OwnedMemoryStream&&) noexcept = default;
private:
using MemoryStream::SetBuffer;
ByteArray m_ownedByteArray;
};
}
#include <Nazara/Core/OwnedMemoryStream.inl>
#endif // NAZARA_CORE_OWNEDMEMORYSTREAM_HPP

View File

@ -0,0 +1,33 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/OwnedMemoryStream.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \brief Constructs an OwnedMemoryStream object
*
* \param openMode Reading/writing mode for the stream
*/
inline OwnedMemoryStream::OwnedMemoryStream(OpenModeFlags openMode)
{
SetBuffer(&m_ownedByteArray, openMode);
}
/*!
* \brief Constructs an OwnedMemoryStream object
*
* \param byteArray Content
* \param openMode Reading/writing mode for the stream
*/
inline OwnedMemoryStream::OwnedMemoryStream(ByteArray byteArray, OpenModeFlags openMode) :
m_ownedByteArray(std::move(byteArray))
{
SetBuffer(&m_ownedByteArray, openMode);
}
}
#include <Nazara/Core/DebugOff.hpp>