2023-02-25 17:39:39 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "VTUtils.hpp"
|
|
|
|
#if defined(LIBCMO_OS_WIN32)
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
2023-02-25 22:58:28 +08:00
|
|
|
#include <filesystem>
|
2023-02-25 17:39:39 +08:00
|
|
|
|
2023-02-26 21:48:03 +08:00
|
|
|
namespace LibCmo::VxMath {
|
2023-02-25 17:39:39 +08:00
|
|
|
|
|
|
|
class VxMemoryMappedFile {
|
|
|
|
private:
|
|
|
|
|
2023-02-25 22:58:28 +08:00
|
|
|
|
2023-02-25 17:39:39 +08:00
|
|
|
#if defined(LIBCMO_OS_WIN32)
|
|
|
|
HANDLE m_hFile;
|
|
|
|
DWORD m_dwFileSizeLow, m_dwFileSizeHigh;
|
|
|
|
HANDLE m_hFileMapping;
|
|
|
|
LPVOID m_hFileMapView;
|
|
|
|
#else
|
2023-02-25 22:58:28 +08:00
|
|
|
|
2023-02-25 17:39:39 +08:00
|
|
|
#error NO IMPLEMENTATION FOR LINUX MMAP!
|
|
|
|
#endif
|
|
|
|
|
2023-02-25 22:58:28 +08:00
|
|
|
std::filesystem::path m_szFilePath;
|
2023-02-25 17:39:39 +08:00
|
|
|
void* m_pMemoryMappedFileBase;
|
|
|
|
size_t m_cbFile;
|
|
|
|
bool m_bIsValid;
|
|
|
|
public:
|
|
|
|
VxMemoryMappedFile(const char* u8_filepath);
|
|
|
|
VxMemoryMappedFile(const VxMemoryMappedFile&) = delete;
|
|
|
|
VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete;
|
|
|
|
~VxMemoryMappedFile(void);
|
|
|
|
|
|
|
|
inline void* GetBase(void) { return this->m_pMemoryMappedFileBase; }
|
|
|
|
inline size_t GetFileSize(void) { return this->m_cbFile; }
|
|
|
|
inline bool IsValid(void) { return this->m_bIsValid; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|