YSTest: FileSystem.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
YSLib/Service/FileSystem.h
浏览该文件的文档.
1 /*
2 © 2010-2014 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_FileSystem_h_
29 #define YSL_INC_Service_FileSystem_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YString
33 #include <ystdex/path.hpp>
34
35 namespace YSLib
36 {
37
38 namespace IO
39 {
40
45 class YF_API PathNorm : public ystdex::path_norm<YSLib::String>
46 {
47 public:
48 using value_type = YSLib::String;
49
50 PDefH(bool, is_delimiter, const value_type& str) override
51 ImplRet(YCL_FS_CharIsDelimiter(str[0], u))
52
53 PDefH(bool, is_parent, const value_type& str) ynothrow override
54 ImplRet(YCL_FS_StringIsParent(str, u))
55
56 PDefH(bool, is_root, const value_type& str) ynothrow override
57 ImplRet(YCL_FS_StringIsRoot(str, u))
58
59 PDefH(bool, is_self, const value_type& str) ynothrow override
60 ImplRet(YCL_FS_StringIsCurrent(str, u))
61
63 DefClone(const override, PathNorm)
64 };
65
66
68 using ypath = ystdex::path<vector<String>, PathNorm>;
69
70
75 class YF_API Path : private ypath
76 {
77 public:
78 using ypath::iterator;
79 using ypath::const_iterator;
81 using ypath::value_type;
82
83 public:
87 DefDeCtor(Path)
88 Path(const ucs2_t* str)
89 : ypath(Parse(str))
90 {}
92
93 Path(const ucs2string& str)
94 : ypath(Parse(str))
95 {}
96 Path(ucs2string&& str)
97 : ypath(Parse(str))
98 {}
100 template<typename _type,
101 yimpl(typename = ystdex::exclude_self_ctor_t<Path, _type>)>
102 Path(_type&& arg, Text::Encoding enc = CS_Path)
103 : ypath(Parse(String(yforward(arg), enc)))
104 {}
106
109 DefDeCopyCtor(Path)
113 DefDeMoveCtor(Path)
114 DefDeDtor(Path)
115
120 DefDeCopyAssignment(Path)
125 DefDeMoveAssignment(Path)
126
128
129 Path&
131 operator/=(const String&);
132 Path&
133 operator/=(const Path&);
135
136 friend bool
137 operator==(const Path&, const Path&);
138
139 friend bool
140 operator<(const Path&, const Path&);
141
147 operator String() const;
152 DefCvt(const, string, GetMBCS(CS_Path))
153
158 PDefH(string, GetMBCS, Text::Encoding enc = CS_Path) const
159 ImplRet(String(*this).GetMBCS(enc))
165 String
166 GetString() const;
167
172 PDefH(void, Normalize, )
173 ImplExpr(ystdex::normalize(*this))
174
176
177 static ypath
178 Parse(const ucs2string&);
179
180 using ypath::back;
181
182 using ypath::begin;
183
184 using ypath::cbegin;
185
186 using ypath::clear;
187
188 using ypath::cend;
189
190 using ypath::empty;
191
192 using ypath::end;
193
194 using ypath::erase;
195
197 using ypath::filter_self;
198
199 using ypath::front;
200
202 using ypath::get_norm;
203
204 using ypath::insert;
205
206 using ypath::is_absolute;
207
208 using ypath::is_relative;
209
211 using ypath::merge_parents;
212
214 using ypath::pop_back;
215
217 using ypath::push_back;
218
219 using ypath::swap;
220 PDefH(void, swap, Path& pth)
221 ImplExpr(static_cast<ypath&>(pth).swap(*this))
222
224 friend PDefH(String, to_string, const Path& pth)
225 ImplRet(to_string(static_cast<const ypath&>(pth),
226 ucs2string{YCL_PATH_DELIMITER}))
228 };
229
231
232 inline PDefHOp(bool, ==, const Path& x, const Path& y)
233 ImplRet(static_cast<const ypath&>(x) == static_cast<const ypath&>(y))
234 inline PDefHOp(bool, !=, const Path& x, const Path& y)
235 ImplRet(!(x == y))
236 inline PDefHOp(bool, <, const Path& x, const Path& y)
237 ImplRet(static_cast<const ypath&>(x) < static_cast<const ypath&>(y))
238 inline PDefHOp(bool, <=, const Path& x, const Path& y)
239 ImplRet(!(y < x))
240 inline PDefHOp(bool, >, const Path& x, const Path& y)
241 ImplRet(y < x)
242 inline PDefHOp(bool, >=, const Path& x, const Path& y)
243 ImplRet(!(x < y))
244
245 inline PDefHOp(Path, /, const Path& x, const Path& y)
246 ImplRet(std::move(Path(x) /= y))
247
251 inline DefSwap(ynothrow, Path)
253
254
261 YF_API String
262 GetExtensionOf(const String&);
264 inline PDefH(String, GetExtensionOf, const string& path)
265 ImplRet(String(path, CS_Path))
266 inline PDefH(String, GetExtensionOf, const Path& pth)
267 ImplRet(pth.empty() ? String() : GetExtensionOf(pth.back()))
269
270
277 YF_API String
278 FetchCurrentWorkingDirectory(size_t = 1 << 10);
279
280
282
283
285 inline PDefH(bool, IsAbsolute, const string& path)
286 ImplRet(IsAbsolute(path.c_str()))
287 inline PDefH(bool, IsAbsolute, const String& path)
288 ImplRet(IsAbsolute(path.GetMBCS(CS_Path)))
289 inline PDefH(bool, IsAbsolute, const Path& pth)
290 ImplRet(!pth.empty() && IsAbsolute(pth.GetString()))
292
294
295 inline PDefH(bool, IsRelative, const char* path)
296 ImplRet(!IsAbsolute(path))
297 inline PDefH(bool, IsRelative, const string& path)
298 ImplRet(!IsAbsolute(path))
299 inline PDefH(bool, IsRelative, const String& path)
300 ImplRet(!IsAbsolute(path))
301 inline PDefH(bool, IsRelative, const Path& pth)
302 ImplRet(!IsAbsolute(pth))
304
305
307
308 YF_API bool
309 VerifyDirectory(const char*);
310 inline PDefH(bool, VerifyDirectory, const string& path)
311 ImplRet(VerifyDirectory(path.c_str()))
312 inline PDefH(bool, VerifyDirectory, const String& path)
313 ImplRet(VerifyDirectory(path.GetMBCS(CS_Path)))
314 inline PDefH(bool, VerifyDirectory, const Path& pth)
315 ImplRet(!pth.empty() && VerifyDirectory(pth.GetString()))
317
318
327 YF_API void
328 EnsureDirectory(const Path&) ythrow(std::system_error);
329 inline PDefH(void, EnsureDirectory, const char* path)
330 ythrow(std::system_error)
331 ImplExpr(EnsureDirectory(Path(path)))
332 inline PDefH(void, EnsureDirectory, const string& path)
333 ythrow(std::system_error)
334 ImplExpr(EnsureDirectory(path.c_str()))
335 inline PDefH(void, EnsureDirectory, const String& path)
336 ythrow(std::system_error)
337 ImplExpr(EnsureDirectory(path.GetMBCS(CS_Path)))
339
340
345 void
346 ListFiles(const Path&, vector<String>&);
347
348
353 YF_API PathCategory
354 ClassifyPath(const String&, ypath::norm&& = PathNorm());
355
357 YF_API NodeCategory
358 ClassifyNode(const Path&);
360
361
362 // \brief 文件名过滤器。
363 // TODO: Definition & impl.
364
365 } // namespace IO;
366
367 } // namespace YSLib;
368
369 #endif
370
platform::PathCategory
PathCategory
路径类别。
Definition: YCLib/FileSystem.h:334
YSLib::IO::ClassifyPath
const String &path const Path &pth ImplRet(!pth.empty()&&VerifyDirectory(pth.GetString())) YF_API void EnsureDirectory(const Path &) ythrow(std PDefH(void, EnsureDirectory, const char *path) ythrow(std YF_API PathCategor ClassifyPath)(const String &, ypath::norm &&=PathNorm())
验证路径表示的目录是否存在，若不存在则逐级创建。
Definition: YSLib/Service/FileSystem.h:354
DefDeDtor
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
YCL_FS_StringIsParent
#define YCL_FS_StringIsParent(_s, _p)
Definition: YCLib/FileSystem.h:59
YSLib::IO::ListFiles
void ListFiles(const Path &pth, vector< String > &lst)
Definition: YSLib/Service/FileSystem.cpp:153
CHRLib::enc
enc
Definition: chrproc.h:76
YSLib::IO::Path::Path
Path(const ucs2string &str)
Definition: YSLib/Service/FileSystem.h:93
ystdex::path
一般路径模板。
Definition: path.hpp:149
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:136
path.hpp
抽象路径模板。
ystdex::path::value_type
typename _tSeqCon::value_type value_type
Definition: path.hpp:155
YF_API
#define YF_API
Definition: Platform.h:64
YSLib::IO::FetchCurrentWorkingDirectory
String FetchCurrentWorkingDirectory(size_t len)
Definition: YSLib/Service/FileSystem.cpp:113
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
YSLib::ucs2string
GSStringTemplate< CHRLib::ucs2_t >::basic_string ucs2string
Definition: ycont.h:167
YSLib::IO::IsRelative
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() const String &path const Path &pth IsRelative
Definition: YSLib/Service/FileSystem.h:295
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:177
YSLib::IO::GetExtensionOf
String GetExtensionOf(const String &fname)
Definition: YSLib/Service/FileSystem.cpp:99
ystdex::swap
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
YSLib::IO::Path::Path
Path(_type &&arg, Text::Encoding enc=CS_Path)
Definition: YSLib/Service/FileSystem.h:102
YSLib::IO::PDefH
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() PDefH(bool, IsAbsolute, const string &path) ImplRet(IsAbsolute(path.c_str())) inline PDefH(bool
取当前工作目录。
Definition: YSLib/Service/FileSystem.h:285
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: ystring.h:47
YSLib::IO::PathNorm
文件路径范式。
Definition: YSLib/Service/FileSystem.h:45
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:141
ImplExpr
#define ImplExpr(...)
Definition: YBaseMacro.h:93
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::IO::Path
路径。
Definition: YSLib/Service/FileSystem.h:75
ythrow
#define ythrow(...)
YSLib 动态异常规范：根据是否使用异常规范宏指定或忽略动态异常规范。
Definition: ydef.h:476
YSLib::IO::EnsureDirectory
void EnsureDirectory(const Path &pth)
Definition: YSLib/Service/FileSystem.cpp:138
ystdex::exclude_self_ctor_t
enable_if_t<!is_same< _tClass &, remove_rcv_t< _tParam > & >::value, _type > exclude_self_ctor_t
移除选择类类型的特定重载避免构造模板和复制/转移构造函数冲突。
Definition: type_op.hpp:766
ystdex::path::const_iterator
typename base::const_iterator const_iterator
Definition: path.hpp:165
DefClone
#define DefClone(_q, _t)
动态复制。
Definition: YBaseMacro.h:221
ystdex::to_string
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
CHRLib::ucs2_t
char16_t ucs2_t
UCS-2 字符类型。
Definition: chrdef.h:44
YSLib::IO::Path::DefDeCtor
DefDeCtor(Path) Path(const ucs2_t *str)
无参数构造：默认实现。
Definition: YSLib/Service/FileSystem.h:87
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:159
YSLib::IO::Path::Path
Path(ucs2string &&str)
Definition: YSLib/Service/FileSystem.h:96
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
YSLib::IO::ImplRet
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() const String &path ImplRet(IsAbsolute(path.GetMBCS(CS_Path))) inline PDefH(bool
判断路径表示相对路径（包括空路径）。
Definition: YSLib/Service/FileSystem.h:288
YSLib::IO::IsAbsolute
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() IsAbsolute
Definition: YSLib/Service/FileSystem.h:287
ystdex::path_norm
路径范式。
Definition: path.hpp:48
CHRLib::CharSet::Encoding
Encoding
Definition: encoding.h:53
YSLib::IO::VerifyDirectory
VerifyDirectory
Definition: YSLib/Service/FileSystem.h:312
YModules.h
platform::NodeCategory
NodeCategory
文件系统节点类别。
Definition: YCLib/FileSystem.h:343
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:154
ystdex::path::iterator
typename base::iterator iterator
Definition: path.hpp:164
YSLib::IO::ClassifyNode
YF_API NodeCategory ClassifyNode(const Path &)
按文件系统节点类别对路径分类。
Definition: YSLib/Service/FileSystem.cpp:186
YCL_FS_StringIsCurrent
#define YCL_FS_StringIsCurrent(_s, _p)
Definition: YCLib/FileSystem.h:52