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:
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
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
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;
81  using ypath::value_type;
82 
83 public:
88  Path(const ucs2_t* str)
89  : ypath(Parse(str))
90  {}
92 
93  Path(const ucs2string& str)
94  : ypath(Parse(str))
95  {}
97  : ypath(Parse(str))
98  {}
100  template<typename _type,
102  Path(_type&& arg, Text::Encoding enc = CS_Path)
103  : ypath(Parse(String(yforward(arg), enc)))
104  {}
106 
114  DefDeDtor(Path)
115 
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 
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 
354 ClassifyPath(const String&, ypath::norm&& = PathNorm());
355 
358 ClassifyNode(const Path&);
360 
361 
362 // \brief 文件名过滤器。
363 // TODO: Definition & impl.
364 
365 } // namespace IO;
366 
367 } // namespace YSLib;
368 
369 #endif
370 
PathCategory
路径类别。
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())
验证路径表示的目录是否存在,若不存在则逐级创建。
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
#define YCL_FS_StringIsParent(_s, _p)
void ListFiles(const Path &pth, vector< String > &lst)
Path(const ucs2string &str)
一般路径模板。
Definition: path.hpp:149
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:136
抽象路径模板。
typename _tSeqCon::value_type value_type
Definition: path.hpp:155
#define YF_API
Definition: Platform.h:64
String FetchCurrentWorkingDirectory(size_t len)
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
GSStringTemplate< CHRLib::ucs2_t >::basic_string ucs2string
Definition: ycont.h:167
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() const String &path const Path &pth IsRelative
#define yimpl(...)
实现标签。
Definition: ydef.h:177
String GetExtensionOf(const String &fname)
void swap(any &x, any &y)
交换对象。
Definition: any.h:729
Path(_type &&arg, Text::Encoding enc=CS_Path)
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
取当前工作目录。
YSLib 标准字符串(使用 UCS-2 作为内部编码)。
Definition: ystring.h:47
文件路径范式。
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:141
#define ImplExpr(...)
Definition: YBaseMacro.h:93
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。
Definition: ydef.h:476
void EnsureDirectory(const Path &pth)
enable_if_t<!is_same< _tClass &, remove_rcv_t< _tParam > & >::value, _type > exclude_self_ctor_t
移除选择类类型的特定重载避免构造模板和复制/转移构造函数冲突。
Definition: type_op.hpp:766
typename base::const_iterator const_iterator
Definition: path.hpp:165
#define DefClone(_q, _t)
动态复制。
Definition: YBaseMacro.h:221
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
char16_t ucs2_t
UCS-2 字符类型。
Definition: chrdef.h:44
DefDeCtor(Path) Path(const ucs2_t *str)
无参数构造:默认实现。
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:159
Path(ucs2string &&str)
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() const String &path ImplRet(IsAbsolute(path.GetMBCS(CS_Path))) inline PDefH(bool
判断路径表示相对路径(包括空路径)。
CS_Path PDefH(String, GetExtensionOf, const Path &pth) ImplRet(pth.empty()?String() IsAbsolute
路径范式。
Definition: path.hpp:48
NodeCategory
文件系统节点类别。
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:154
typename base::iterator iterator
Definition: path.hpp:164
YF_API NodeCategory ClassifyNode(const Path &)
按文件系统节点类别对路径分类。
#define YCL_FS_StringIsCurrent(_s, _p)