YSTest: MemoryMapping.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

MemoryMapping.h
浏览该文件的文档.
1 /*
2 © 2012-2016, 2018 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YCL_INC_MemoryMapping_h_
29 #define YCL_INC_MemoryMapping_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YCLib_YCommon
33 #include YFM_YCLib_Reference // for ystdex::pseudo_output, unique_ptr,
34 // default_delete;
35 #include YFM_YCLib_FileIO
36 #include YFM_YBaseMacro
37
38 namespace platform
39 {
40
42
43 enum class FileMappingOption
45 {
46 ReadOnly,
47 ReadWrite,
48 CopyOnWrite
49 };
50
51
59 #if !YF_Hosted
60 using FileMappingKey = ystdex::pseudo_output;
61 #elif YCL_Win32
62 using FileMappingKey = const char16_t*;
63 #else
64 using FileMappingKey = bool;
65 #endif
66
67
68
69
71 class YF_API UnmapDelete
72 #if YCL_DS
73 : private default_delete<byte[]>
74 #endif
75 {
76 public:
77 using pointer = byte*;
78
79 private:
80 size_t size = 0;
81
82 public:
84 DefDeCtor(UnmapDelete)
85 UnmapDelete(size_t s)
86 : size(s)
87 {}
88
89 #if YCL_DS
90 using default_delete<byte[]>::operator();
92 #else
93
97 void
98 operator()(pointer) const ynothrowv;
99 #endif
100
102 DefGetter(const ynothrow, size_t, Size, size)
103 };
104
105
114 class YF_API MappedFile
115 {
116 private:
118 FileMappingOption option;
120 UniqueFile file{};
122 unique_ptr<byte[], UnmapDelete> mapped{};
123
124 public:
129 DefDeCtor(MappedFile)
147
149
151
156 explicit
157 MappedFile(std::uint64_t, size_t, UniqueFile,
158 FileMappingOption = FileMappingOption::ReadOnly, FileMappingKey = {});
160
161 private:
162 explicit
163 MappedFile(pair<size_t, UniqueFile> pr, FileMappingOption opt,
164 FileMappingKey key)
165 : MappedFile(pr.first, std::move(pr.second), opt, key)
166 {}
167
168 public:
169 explicit
170 MappedFile(size_t, UniqueFile,
171 FileMappingOption = FileMappingOption::ReadOnly, FileMappingKey = {});
173
174
176 explicit
178 MappedFile(UniqueFile,
179 FileMappingOption = FileMappingOption::ReadOnly, FileMappingKey = {});
181 explicit YB_NONNULL(2)
182 MappedFile(const char*, FileMappingOption = FileMappingOption::ReadOnly,
183 FileMappingKey = {});
184 template<class _tString, typename... _tParams>
185 explicit
186 MappedFile(const _tString& filename, _tParams&&... args)
187 : MappedFile(filename.c_str(), yforward(args)...)
188 {}
190
191
192 DefDeMoveCtor(MappedFile)
199 ~MappedFile();
200
202
203 DefDeMoveAssignment(MappedFile)
204
205 DefBoolNeg(explicit, bool(file))
206
208 DefGetter(const ynothrow, FileDescriptor, File, file.get())
209 DefGetter(const ynothrow, FileMappingOption, MappingOption, option)
211 DefGetter(const ynothrow, byte*, Ptr, mapped.get())
214 DefGetterMem(const ynothrow, size_t, Size, mapped.get_deleter())
216 DefGetter(const ynothrow, const UniqueFile&, UniqueFile, file)
217
219
220
224 PDefH(void, Flush, )
225 ImplExpr(FlushView(), FlushFile())
226
234 void
235 FlushView();
236
242 void
243 FlushFile();
245 };
246
247 } // namespace platform;
248
249 #endif
250
platform::MappedFile::MappedFile
MappedFile(pair< size_t, UniqueFile > pr, FileMappingOption opt, FileMappingKey key)
以指定的区域长度、文件、选项和键创建映射。
Definition: MemoryMapping.h:163
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
size
size_t size
Definition: memory_resource.cpp:295
platform::UnmapDelete::pointer
byte * pointer
Definition: MemoryMapping.h:77
platform::MappedFile::DefDeMoveAssignment
DefDeMoveAssignment(MappedFile) DefBoolNeg(explicit
YCL_DS
#define YCL_DS
Definition: Platform.h:332
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
platform::FileDescriptor
文件描述符包装类。
Definition: FileIO.h:149
platform::FileMappingOption::ReadWrite
@ ReadWrite
platform::if
if(!p) p
YF_API
#define YF_API
Definition: Platform.h:56
platform::MappedFile
只读内存映射文件。
Definition: MemoryMapping.h:115
platform::FileMappingOption
FileMappingOption
文件映射选项。
Definition: MemoryMapping.h:45
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
platform::MappedFile::YB_NONNULL
YB_NONNULL(2) MappedFile(const char *
platform::UniqueFile
unique_ptr_from< FileDescriptor::Deleter > UniqueFile
Definition: FileIO.h:486
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:228
platform::MappedFile::MappedFile
MappedFile(const _tString &filename, _tParams &&... args)
Definition: MemoryMapping.h:186
YSLib::IO::_tString
const string &path const String &path class class class _tString
Definition: YSLib/Service/FileSystem.h:612
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
platform::ynothrow
const _tString &path ynothrow
Definition: YCLib/FileSystem.h:453
platform::FileMappingOption::ReadOnly
@ ReadOnly
platform::MappedFile::option
FileMappingOption option
Definition: MemoryMapping.h:118
std
Definition: optional.h:982
platform::FileMappingOption::CopyOnWrite
@ CopyOnWrite
ystdex::pseudo_output
伪输出对象。
Definition: invoke.hpp:67
platform
默认平台命名空间。
Definition: Container.h:56
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
YModules.h
YSLib 用户界面模块配置文件。
platform::MappedFile::DefDeCtor
DefDeCtor(MappedFile) explicit MappedFile(std
无参数构造：具有大小等于 0 的空状态。
Definition: MemoryMapping.h:129
CHRLib::char16_t
YB_ATTR_nodiscard YB_PURE char16_t((*c_ptr<< CHAR_BIT)|c_ptr[1])) YB_ATTR_nodiscard YB_PURE inline PDefH(char16_t
取 c_ptr 指向的小端序双字节字符。
platform::UnmapDelete
Definition: MemoryMapping.h:75
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:140
ImplExpr
#define ImplExpr(...)
简单通用函数实现。
Definition: YBaseMacro.h:96
platform::PDefH
YB_ATTR_nodiscard PDefH(string, MakePathString, u16string_view sv) ImplRet(MakePathString(sv.data())) using FileNodeID
文件节点标识类型。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
mapped
MappedFile mapped
Definition: Initialization.cpp:316
platform::ynothrowv
YB_ATTR_nodiscard YF_API int amode ynothrowv
Definition: FileIO.h:550
platform::FileMappingKey
ystdex::pseudo_output FileMappingKey
文件映射键类型。
Definition: MemoryMapping.h:60
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
platform::bool
YB_ATTR_nodiscard std::FILE *fp bool
Definition: FileIO.h:1271
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
platform::UnmapDelete::DefDeCtor
DefDeCtor(UnmapDelete) UnmapDelete(size_t s)
Definition: MemoryMapping.h:84