fully remove boost dependency

This commit is contained in:
yyc12345 2023-02-12 21:03:36 +08:00
parent 3de9e3d996
commit 1fb1b81253
7 changed files with 108 additions and 48 deletions

View File

@ -100,7 +100,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -118,7 +118,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -136,7 +136,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -156,7 +156,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>

View File

@ -5,6 +5,7 @@
#if defined(LIBCMO_OS_WIN32)
#include <Windows.h>
#include <fileapi.h>
#else
#include <iconv.h>
#endif

View File

@ -28,43 +28,100 @@ namespace LibCmo {
#pragma region VxMemoryMappedFile
VxMemoryMappedFile::VxMemoryMappedFile(const char* u8_filepath) :
// init members
#if defined(LIBCMO_OS_WIN32)
m_hFile(NULL), m_hFileMapping(NULL), m_hFileMapView(NULL),
m_dwFileSizeLow(0), m_dwFileSizeHigh(0),
#else
#error NO IMPLEMENTATION FOR LINUX MMAP!
#endif
m_szFilePath(),
m_hFile(nullptr), m_hFileMapping(nullptr),
m_bIsValid(false) {
m_bIsValid(false), m_pMemoryMappedFileBase(nullptr), m_cbFile(0u) {
// save file path and set region option
boost::interprocess::map_options_t region_option;
// save file path
#if defined(LIBCMO_OS_WIN32)
Encoding::CharToWchar(u8_filepath, this->m_szFilePath, CP_UTF8);
region_option = FILE_MAP_READ;
#else
this->m_szFilePath = u8_filepath;
region_option = boost::interprocess::default_map_options;
#endif
// real mapping work
#if defined(LIBCMO_OS_WIN32)
// open file
this->m_hFile = new boost::interprocess::file_mapping(
this->m_szFilePath.c_str(), boost::interprocess::read_only
this->m_hFile = CreateFileW(
this->m_szFilePath.c_str(),
GENERIC_READ,
0, // do not share
NULL, // no security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, // no attr
NULL // no template
);
if (this->m_hFile == INVALID_HANDLE_VALUE) {
return;
}
// open region
this->m_hFileMapping = new boost::interprocess::mapped_region(
*(this->m_hFile), boost::interprocess::read_only,
0, 0, nullptr,
region_option
// get size
m_dwFileSizeLow = ::GetFileSize(this->m_hFile, &this->m_dwFileSizeHigh);
if (m_dwFileSizeLow == INVALID_FILE_SIZE) {
CloseHandle(this->m_hFile);
return;
}
// open mapping
this->m_hFileMapping = CreateFileMappingW(
this->m_hFile,
NULL, // default security
PAGE_READONLY,
0, 0, // expand to file size
NULL // no name
);
if (this->m_hFileMapping == NULL) {
CloseHandle(this->m_hFile);
return;
}
// open map view
this->m_hFileMapView = MapViewOfFile(
this->m_hFileMapping,
FILE_MAP_READ,
0, 0, //no offset
0 // expand to full file size
);
if (this->m_hFileMapView == NULL) {
CloseHandle(m_hFileMapping);
CloseHandle(m_hFile);
}
// write member data
m_pMemoryMappedFileBase = m_hFileMapView;
m_cbFile = static_cast<size_t>(m_dwFileSizeLow) | (static_cast<size_t>(m_dwFileSizeHigh) << 32);
#else
#error NO IMPLEMENTATION FOR LINUX MMAP!
#endif
// set valid
this->m_bIsValid = true;
}
VxMemoryMappedFile::~VxMemoryMappedFile(void) {
this->m_bIsValid = false;
if (this->m_bIsValid) {
// only success mapping need free
this->m_bIsValid = false;
m_cbFile = 0;
m_pMemoryMappedFileBase = nullptr;
delete this->m_hFileMapping;
boost::interprocess::file_mapping::remove(this->m_szFilePath.c_str());
delete this->m_hFile;
#if defined(LIBCMO_OS_WIN32)
UnmapViewOfFile(this->m_hFileMapView);
CloseHandle(m_hFileMapping);
CloseHandle(m_hFile);
#else
#error NO IMPLEMENTATION FOR LINUX MMAP!
#endif
}
}
#pragma endregion

View File

@ -5,8 +5,11 @@
#include "VTEncoding.hpp"
#include <vector>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
#if defined(LIBCMO_OS_WIN32)
#include <Windows.h>
#else
#include <sys/mman.h>
#endif
namespace LibCmo {
@ -27,12 +30,17 @@ namespace LibCmo {
#if defined(LIBCMO_OS_WIN32)
std::wstring m_szFilePath;
HANDLE m_hFile;
DWORD m_dwFileSizeLow, m_dwFileSizeHigh;
HANDLE m_hFileMapping;
LPVOID m_hFileMapView;
#else
std::string m_szFilePath;
#error NO IMPLEMENTATION FOR LINUX MMAP!
#endif
boost::interprocess::file_mapping* m_hFile;
boost::interprocess::mapped_region* m_hFileMapping;
void* m_pMemoryMappedFileBase;
size_t m_cbFile;
bool m_bIsValid;
public:
VxMemoryMappedFile(const char* u8_filepath);
@ -40,8 +48,8 @@ namespace LibCmo {
VxMemoryMappedFile& operator=(const VxMemoryMappedFile&) = delete;
~VxMemoryMappedFile(void);
inline void* GetBase(void) { return this->m_hFileMapping->get_address(); }
inline size_t GetFileSize(void) { return this->m_hFileMapping->get_size(); }
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; }
};

View File

@ -2,8 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<BOOST_INCLUDE_PATH>D:\CppLib\boost_1_81_0</BOOST_INCLUDE_PATH>
<SQLITE_HEADER_PATH>D:\CppLib\SQLite\sqlite-amalgamation-3400100</SQLITE_HEADER_PATH>
<SQLITE_WIN32_LIB_PATH>D:\CppLib\SQLite\sqlite-dll-win32-x86-3400100</SQLITE_WIN32_LIB_PATH>
<SQLITE_WIN64_LIB_PATH>D:\CppLib\SQLite\sqlite-dll-win64-x64-3400100</SQLITE_WIN64_LIB_PATH>
@ -13,10 +11,6 @@
<PropertyGroup />
<ItemDefinitionGroup />
<ItemGroup>
<BuildMacro Include="BOOST_INCLUDE_PATH">
<Value>$(BOOST_INCLUDE_PATH)</Value>
</BuildMacro>
<BuildMacro Include="SQLITE_HEADER_PATH">
<Value>$(SQLITE_HEADER_PATH)</Value>
</BuildMacro>

View File

@ -3,18 +3,18 @@
#include <unordered_map>
#include <string>
#include <functional>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
//#include <boost/program_options/options_description.hpp>
//#include <boost/program_options/positional_options.hpp>
//#include <boost/program_options/parsers.hpp>
//#include <boost/program_options/variables_map.hpp>
namespace Unvirt {
struct CmdRegisteryEntry {
boost::program_options::options_description mOptDesc;
boost::program_options::positional_options_description mPosOptDesc;
std::function<void(boost::program_options::options_description&, boost::program_options::variables_map&)> mBindProc;
};
//struct CmdRegisteryEntry {
// boost::program_options::options_description mOptDesc;
// boost::program_options::positional_options_description mPosOptDesc;
// std::function<void(boost::program_options::options_description&, boost::program_options::variables_map&)> mBindProc;
//};
class InteractiveCmd {
public:
@ -24,7 +24,7 @@ namespace Unvirt {
void Run(void) { ; }
private:
std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
//std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
};

View File

@ -100,7 +100,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -119,7 +119,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -138,7 +138,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -157,7 +157,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>