diff --git a/include/Nazara/Core/OwnedMemoryStream.hpp b/include/Nazara/Core/OwnedMemoryStream.hpp new file mode 100644 index 000000000..c2fb6f1ca --- /dev/null +++ b/include/Nazara/Core/OwnedMemoryStream.hpp @@ -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 +#include +#include + +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 + +#endif // NAZARA_CORE_OWNEDMEMORYSTREAM_HPP diff --git a/include/Nazara/Core/OwnedMemoryStream.inl b/include/Nazara/Core/OwnedMemoryStream.inl new file mode 100644 index 000000000..e65abc996 --- /dev/null +++ b/include/Nazara/Core/OwnedMemoryStream.inl @@ -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 +#include + +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