Files
OpenVulkano/openVulkanoCpp/IO/MemMappedFileInternal.hpp
2024-11-13 10:24:34 +02:00

50 lines
1.0 KiB
C++

/*
* 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 "MemMappedFile.hpp"
#ifdef _MSC_VER
#include <Windows.h>
#else
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif
namespace OpenVulkano
{
class MemMappedFileInternal
{
friend class MemMappedFileWriteHelper;
friend class MemMappedFile;
public:
MemMappedFileInternal(const char* file, MemMappedFile::FileMode fileMode);
~MemMappedFileInternal();
private:
#if defined(_MSC_VER)
bool InvalidHandle() const { return fileHandle == INVALID_HANDLE_VALUE || fileHandle == NULL; }
#else
[[nodiscard]] bool InvalidHandle() const { return fileHandle == -1; }
#endif
private:
void* address = nullptr;
size_t size = 0;
#ifdef _MSC_VER
HANDLE fileHandle;
HANDLE fileMappingHandle;
#else
int fileHandle;
struct stat fileStat;
#endif
};
}