YSTest: File.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

File.h
浏览该文件的文档.
1 /*
2 © 2009-2017 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 YSL_INC_Service_File_h_
29 #define YSL_INC_Service_File_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YCoreUtilities // for MappedFile, std::istream,
33 // ofstream;
34 #include <ystdex/streambuf.hpp> // for ystdex::membuf;
35
36 namespace YSLib
37 {
38
39 namespace IO
40 {
41
50 YF_API YB_NONNULL(1) UniqueFile
51 OpenFile(const char*, int, mode_t = 0);
52
53
61 template<typename _tChar>
62 YB_NONNULL(1) void
63 Remove(const _tChar* path)
64 {
65 if(YB_UNLIKELY(!uremove(path)))
66 {
67 const int err(errno);
68
69 if(err != ENOENT)
70 ystdex::throw_error(err, "Failed removing destination file '"
71 + IO::MakePathString(path) + '\'');
72 }
73 }
74
75 template<typename _tChar>
76 YB_NONNULL(1) void
77 Unlink(const _tChar* path)
78 {
79 if(YB_UNLIKELY(!uunlink(path)))
80 {
81 const int err(errno);
82
83 if(err != ENOENT)
84 ystdex::throw_error(err, "Failed unlinking destination file '"
85 + IO::MakePathString(path) + '\'');
86 }
87 }
89
90
92
93 class YF_API SharedInputMappedFileStream : private MappedFile,
95 private SharedIndirectLockGuard<const UniqueFile>, private ystdex::membuf,
96 public std::istream
97 {
98 public:
99 YB_NONNULL(1)
100 SharedInputMappedFileStream(const char*);
101
102 explicit DefCvt(const ynothrow, bool, !fail())
103
105 ~SharedInputMappedFileStream() override;
106 };
107
108
110 class YF_API UniqueLockedOutputFileStream : public ofstream
111 {
112 private:
113 FileDescriptor desc;
114 unique_lock<FileDescriptor> lock;
115
116 UniqueLockedOutputFileStream(int);
117
118 public:
119 UniqueLockedOutputFileStream(UniqueFile);
121
122 template<typename _tChar>
123 YB_NONNULL(1)
124 UniqueLockedOutputFileStream(const _tChar* filename, int omode,
125 mode_t pmode = DefaultPMode())
126 : UniqueLockedOutputFileStream(uopen(filename, omode, pmode))
127 {}
132 template<typename _tChar>
133 YB_NONNULL(1)
134 UniqueLockedOutputFileStream(std::ios_base::openmode mode,
135 const _tChar* filename, mode_t pmode = DefaultPMode())
136 : UniqueLockedOutputFileStream(filename, omode_conv(mode), pmode)
137 {}
139
141 ~UniqueLockedOutputFileStream() override;
142 };
144
145 } // namespace IO;
146
147 } // namespace YSLib;
148
149 #endif
150
platform::FileDescriptor
文件描述符包装类。
Definition: FileIO.h:146
YSLib::IO::UniqueLockedOutputFileStream::desc
FileDescriptor desc
Definition: File.h:113
YModules.h
YSLib::IO::mode_t
YF_API mode_t
Definition: File.h:51
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
platform::omode_conv
int omode_conv(std::ios_base::openmode mode) ynothrow
Definition: FileIO.cpp:796
platform::uunlink
bool uunlink(const char *path) ynothrowv
Definition: FileIO.cpp:1073
platform::MakePathString
MakePathString
Definition: FileIO.h:62
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:464
platform::UniqueFile
unique_ptr_from< FileDescriptor::Deleter > UniqueFile
Definition: FileIO.h:464
platform::uopen
int uopen(const char *filename, int oflag, mode_t pmode) ynothrowv
Definition: FileIO.cpp:873
ystdex::throw_error
void throw_error(std::error_code ec, _tParams &&...args)
抛出错误： std::system_error 或允许相同构造函数参数的异常。
Definition: ystdex/exception.h:206
YSLib::IO::UniqueLockedOutputFileStream
独占锁定的文件输出流。
Definition: File.h:110
IO
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
platform::uremove
bool uremove(const char *path) ynothrowv
Definition: FileIO.cpp:1083
std
Definition: memory.hpp:1183
platform::pmode
YF_API int mode_t pmode
Definition: FileIO.h:542
platform::Concurrency::SharedIndirectLockGuard
SharedAdaptedLockGuard< _type, ystdex::indirect_ref_adaptor< _type >> SharedIndirectLockGuard
Definition: Mutex.h:133
YSLib::IO::UniqueLockedOutputFileStream::lock
unique_lock< FileDescriptor > lock
Definition: File.h:114
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:206
streambuf.hpp
ISO C++ 标准库标准流缓冲扩展。
ystdex::basic_membuf
内存中储存不具有所有权的只读流缓冲。
Definition: streambuf.hpp:62
YSLib::IO::YB_NONNULL
YF_API YB_NONNULL(1) UniqueFile OpenFile(const char *
打开文件。
Definition: File.h:62
YSLib::path
YF_API const char * path
Definition: Initialization.h:77
platform::DefaultPMode
YF_API YB_STATELESS mode_t DefaultPMode() ynothrow
取默认权限。
Definition: FileIO.cpp:772
YSLib::IO::OpenFile
UniqueFile OpenFile(const char *filename, int omode, mode_t pmode)
Definition: File.cpp:38