YSTest: MemoryMapping.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

MemoryMapping.h
浏览该文件的文档.
1 /*
2 © 2012-2016 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 void
95 operator()(pointer) const ynothrow;
96 #endif
97
99 DefGetter(const ynothrow, size_t, Size, size)
100 };
101
102
111 class YF_API MappedFile
112 {
113 private:
115 FileMappingOption option;
117 UniqueFile file{};
119 unique_ptr<byte[], UnmapDelete> mapped{};
120
121 public:
126 DefDeCtor(MappedFile)
142
144
146
151 explicit
152 MappedFile(std::uint64_t, size_t, UniqueFile,
153 FileMappingOption = FileMappingOption::ReadOnly, FileMappingKey = {});
155
156 private:
157 explicit
158 MappedFile(pair<size_t, UniqueFile> pr, FileMappingOption opt,
159 FileMappingKey key)
160 : MappedFile(pr.first, std::move(pr.second), opt, key)
161 {}
162
163 public:
164 explicit
165 MappedFile(size_t, UniqueFile,
166 FileMappingOption = FileMappingOption::ReadOnly, FileMappingKey = {});
168
169
171 explicit
173 MappedFile(UniqueFile,
174 FileMappingOption = FileMappingOption::ReadOnly, FileMappingKey = {});
176 explicit YB_NONNULL(2)
177 MappedFile(const char*, FileMappingOption = FileMappingOption::ReadOnly,
178 FileMappingKey = {});
179 template<class _tString, typename... _tParams>
180 explicit
181 MappedFile(const _tString& filename, _tParams&&... args)
182 : MappedFile(filename.c_str(), yforward(args)...)
183 {}
185
186
187 DefDeMoveCtor(MappedFile)
194 ~MappedFile();
195
197
198 DefDeMoveAssignment(MappedFile)
199
200 DefBoolNeg(explicit, bool(file))
201
203 DefGetter(const ynothrow, FileDescriptor, File, file.get())
204 DefGetter(const ynothrow, FileMappingOption, MappingOption, option)
206 DefGetter(const ynothrow, byte*, Ptr, mapped.get())
209 DefGetterMem(const ynothrow, size_t, Size, mapped.get_deleter())
211 DefGetter(const ynothrow, const UniqueFile&, UniqueFile, file)
212
214
215
219 PDefH(void, Flush, )
220 ImplExpr(FlushView(), FlushFile())
221
229 void
230 FlushView();
231
237 void
238 FlushFile();
240 };
241
242 } // namespace platform;
243
244 #endif
245
platform::FileDescriptor
文件描述符包装类。
Definition: FileIO.h:146
platform::UnmapDelete::pointer
byte * pointer
Definition: MemoryMapping.h:77
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:228
platform
默认平台命名空间。
Definition: Container.h:47
platform::FileMappingOption::ReadOnly
platform::MappedFile::option
FileMappingOption option
Definition: MemoryMapping.h:115
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1280
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
YCL_DS
#define YCL_DS
Definition: Platform.h:332
platform::PDefH
const string const char *sig PDefH(string, ComposeMessageWithSignature, const char *msg, const char *sig) ImplRet(string(Nonnull(msg))+" @ "+Nonnull(sig)) template< class _type > inline YB_NONNULL(2) string ComposeMessageWithSignature(const _type &msg
platform::UnmapDelete::DefDeCtor
DefDeCtor(UnmapDelete) UnmapDelete(size_t s)
Definition: MemoryMapping.h:84
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:131
platform::UniqueFile
unique_ptr_from< FileDescriptor::Deleter > UniqueFile
Definition: FileIO.h:464
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
platform::MappedFile::MappedFile
MappedFile(pair< size_t, UniqueFile > pr, FileMappingOption opt, FileMappingKey key)
以指定的区域长度、文件、选项和键创建映射。
Definition: MemoryMapping.h:158
mapped
MappedFile mapped
Definition: Initialization.cpp:224
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
platform::FileMappingOption
FileMappingOption
文件映射选项。
Definition: MemoryMapping.h:44
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
platform::if
if(!p) p
platform::MappedFile::DefDeCtor
DefDeCtor(MappedFile) explicit MappedFile(std
无参数构造：空状态。
Definition: MemoryMapping.h:126
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YF_API
#define YF_API
Definition: Platform.h:56
platform::FileMappingOption::ReadWrite
platform::YB_NONNULL
YB_NONNULL(2) PDefH(string
组合消息和函数签名字符串。
YModules.h
platform::MappedFile::MappedFile
MappedFile(const _tString &filename, _tParams &&...args)
Definition: MemoryMapping.h:181
ystdex::pseudo_output
伪输出对象。
Definition: ref.hpp:307
std
Definition: memory.hpp:1183
platform::FileMappingKey
ystdex::pseudo_output FileMappingKey
文件映射键类型。
Definition: MemoryMapping.h:60
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
ystdex::byte
unsigned char byte
字节类型。
Definition: ydef.h:834
platform::UnmapDelete
Definition: MemoryMapping.h:71
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
CHRLib::char16_t
char16_t((*c_ptr<< CHAR_BIT)|c_ptr[1])) inline PDefH(char16_t
取 c_ptr 指向的小端序双字节字符。
platform::MappedFile
只读内存映射文件。
Definition: MemoryMapping.h:111
platform::FileMappingOption::CopyOnWrite
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
platform::ynothrow
const _tString &path ynothrow
Definition: YCLib/FileSystem.h:274
ystdex::details::get
get())
Definition: cast.hpp:102