doc: add documentation

- add documentation for CKDefines, CKGlobals and VxMemoryMappedFile.
- fix build issue in VxMemoryMappedFile.
- add file size limitation in VxMemoryMappedFile. File whose size exceed the maximum value can not be opened.
This commit is contained in:
2024-08-22 10:57:53 +08:00
parent a7c1028926
commit 1028aad155
6 changed files with 174 additions and 75 deletions

View File

@ -2,12 +2,9 @@
#include "../VTInternal.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include <WinImportPrefix.hpp>
#include <Windows.h>
// disable annoy macro at the same time
#undef GetObject
#undef GetClassName
#undef LoadImage
#undef GetTempPath
#include <WinImportSuffix.hpp>
#else
#include <sys/mman.h>
#include <sys/stat.h>
@ -17,16 +14,19 @@
#endif
#include <string>
#include <filesystem>
namespace LibCmo::VxMath {
/**
* @brief Utility class for memory mapped file reading.
* @details The VxMemoryMappedFile can be used have a mapping of a file into a memory buffer for reading purposes.
* @remarks Due to Virtools limitation, we disallow opening any file whose size exceed the maximum value of CKDWORD.
*/
class VxMemoryMappedFile {
private:
#if YYCC_OS == YYCC_OS_WINDOWS
HANDLE m_hFile;
DWORD m_dwFileSizeLow, m_dwFileSizeHigh;
LARGE_INTEGER m_dwFileSize;
HANDLE m_hFileMapping;
LPVOID m_hFileMapView;
#else
@ -35,19 +35,41 @@ namespace LibCmo::VxMath {
void* m_pFileAddr;
#endif
std::filesystem::path m_szFilePath;
std::u8string m_szFilePath;
void* m_pMemoryMappedFileBase;
size_t m_cbFile;
CKDWORD m_cbFile;
bool m_bIsValid;
public:
VxMemoryMappedFile(CKSTRING u8_filepath);
VxMemoryMappedFile(const VxMemoryMappedFile&) = delete;
VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete;
~VxMemoryMappedFile(void);
void* GetBase(void) { return this->m_pMemoryMappedFileBase; }
CKDWORD GetFileSize(void) { return static_cast<CKDWORD>(this->m_cbFile); }
bool IsValid(void) { return this->m_bIsValid; }
public:
/**
* @brief Create a new VxMemoryMappedFile
* @param[in] u8_filepath The path to file to be opened. nullptr is allowed but not suggested.
* Because it must create an invalid VxMemoryMappedFile.
*/
VxMemoryMappedFile(CKSTRING u8_filepath);
~VxMemoryMappedFile();
YYCC_DEL_CLS_COPY_MOVE(VxMemoryMappedFile);
/**
* @brief Returns a pointer to the mapped memory buffer.
* @return The pointer to the mapped memory buffer for reading.
* @remarks
* The returned pointer should not be deleted nor should it be used for writing purpose.
* If you did, it will cause undefined behavior.
* @exception RuntimeException Raised when calling this on an invalid file mapping.
*/
const void* GetBase() const;
/**
* @brief Returns the file size in bytes.
* @return The file size in bytes.
* @exception RuntimeException Raised when calling this on an invalid file mapping.
*/
CKDWORD GetFileSize() const;
/**
* @brief Check whether this file mapping is valid to use.
* @return True if it is, otherwise false.
*/
bool IsValid() const;
};
}