YSTest: File.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

File.cpp
浏览该文件的文档.
1 /*
2 © 2009-2019 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 #include "YSLib/Service/YModules.h"
29 #include YFM_YSLib_Service_File
30
31 namespace YSLib
32 {
33
34 namespace IO
35 {
36
37 UniqueFile
38 OpenFile(const char* filename, int omode, mode_t pmode)
39 {
40 if(UniqueFile p_ifile{uopen(filename, omode, pmode)})
41 return p_ifile;
42 else
43 ystdex::throw_error(errno, "Failed opening file '"
44 + std::string(filename) + '\'');
45 }
46
47
48 SharedInputMappedFileStream::SharedInputMappedFileStream(const char* path)
49 : MappedFile(path), SharedIndirectLockGuard<const UniqueFile>(
50 GetUniqueFile()), ystdex::membuf(ystdex::replace_cast<const char*>(
51 GetPtr()), GetSize()), std::istream(this)
52 {}
53
54 ImplDeDtor(SharedInputMappedFileStream)
55
56
57 UniqueLockedOutputFileStream::UniqueLockedOutputFileStream(int fd,
58 std::ios_base::openmode mode)
59 : ofstream(UniqueFile(fd), mode), desc(fd), lock()
60 {
61 if(*this)
62 lock = unique_lock<FileDescriptor>(desc);
63 }
64 UniqueLockedOutputFileStream::UniqueLockedOutputFileStream(UniqueFile ufile,
65 std::ios_base::openmode mode)
66 : UniqueLockedOutputFileStream(*ufile.get(), mode)
67 {
68 ufile.release();
69 }
70
71 ImplDeDtor(UniqueLockedOutputFileStream)
72
73 } // namespace IO;
74
75 } // namespace YSLib;
76
platform::pmode
YB_ATTR_nodiscard YF_API int mode_t pmode
Definition: FileIO.h:564
YSLib::IO::OpenFile
UniqueFile OpenFile(const char *filename, int omode, mode_t pmode)
Definition: File.cpp:38
platform::MappedFile
只读内存映射文件。
Definition: MemoryMapping.h:115
YSLib::ImplDeDtor
ImplDeDtor(LoggedEvent) FatalError
Definition: YException.cpp:49
YModules.h
YSLib 服务模块配置文件。
YSLib::IO::SharedInputMappedFileStream
共享锁定的文件映射输入流。
Definition: File.h:97
platform::UniqueFile
unique_ptr_from< FileDescriptor::Deleter > UniqueFile
Definition: FileIO.h:486
ystdex::replace_cast
enable_if_t< and_< is_object_pointer< _pDst >, is_trivially_replaceable< _tSrc, remove_pointer_t< _pDst > > >::value, _pDst > replace_cast(_tSrc *v)
保证平凡替换存储的显式转换。
Definition: type_pun.hpp:204
platform::uopen
int uopen(const char *filename, int oflag, mode_t pmode) ynothrowv
Definition: FileIO.cpp:872
ystdex::threading::lock_guard
Definition: pseudo_mutex.h:223
std
Definition: optional.h:982
ystdex::throw_error
void throw_error(std::error_code ec, _tParams &&... args)
抛出错误： std::system_error 或允许相同构造函数参数的异常。
Definition: ystdex/exception.h:241
YSLib::Drawing::GetSize
dst GetSize()
YSLib::IO::ImplDeDtor
ImplDeDtor(SharedInputMappedFileStream) UniqueLockedOutputFileStream
Definition: File.cpp:54
YSLib::path
YB_ATTR_nodiscard YF_API const char * path
Definition: Initialization.h:116
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::IO::UniqueLockedOutputFileStream::UniqueLockedOutputFileStream
UniqueLockedOutputFileStream(int, std::ios_base::openmode)
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::IO::mode_t
YF_API mode_t
Definition: File.h:51
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ystdex::single_thread::lock
void lock(_tLock1 &&, _tLock2 &&, _tLocks &&...)
Definition: pseudo_mutex.h:990
ystdex::cpp2017::string
basic_string< char > string
Definition: string.hpp:772
ystdex::membuf
basic_membuf< char > membuf
Definition: streambuf.hpp:136
YSLib::IO::UniqueLockedOutputFileStream
独占锁定的文件输出流。
Definition: File.h:120
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
ystdex::threading::unique_lock
Definition: pseudo_mutex.h:566