memmappedfile-fix (#115)
Co-authored-by: Metehan Tuncbilek <mtuncbilek95@gmail.com> Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com> Co-authored-by: mtuncbilek <metehan.tuncbilek@madvoxel.com> Co-committed-by: mtuncbilek <metehan.tuncbilek@madvoxel.com>
This commit is contained in:
48
openVulkanoCpp/IO/MemMappedFileWriteHelper.hpp
Normal file
48
openVulkanoCpp/IO/MemMappedFileWriteHelper.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IO/MemMappedFile.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
class MemMappedFileWriteHelper
|
||||
{
|
||||
public:
|
||||
MemMappedFileWriteHelper(const std::filesystem::path& path, size_t maxFileSize);
|
||||
~MemMappedFileWriteHelper();
|
||||
|
||||
[[nodiscard]] void* Data() const { return m_file->Data(); }
|
||||
[[nodiscard]] size_t Size() const { return m_file->Size(); }
|
||||
|
||||
bool Resize(size_t newSize);
|
||||
void Close();
|
||||
bool Trim(size_t finalFileSize);
|
||||
|
||||
static constexpr size_t USE_CURRENT_FILE_SIZE = 0;
|
||||
|
||||
private:
|
||||
MemMappedFile* m_file;
|
||||
std::filesystem::path m_path;
|
||||
};
|
||||
|
||||
class MemMappedFileWriter final
|
||||
{
|
||||
public:
|
||||
MemMappedFileWriter(const std::filesystem::path& path, size_t maxFileSize);
|
||||
~MemMappedFileWriter();
|
||||
|
||||
void Write(const char* data, size_t size);
|
||||
void SetOffset(size_t offset) { m_writtenSize = offset; }
|
||||
[[nodiscard]] size_t GetOffset() const { return m_writtenSize; }
|
||||
|
||||
private:
|
||||
MemMappedFileWriteHelper m_helper;
|
||||
size_t m_writtenSize = 0;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user