YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
FileSystem.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2012 - 2013.
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_FileSystem_h_
29 #define YCL_INC_FileSystem_h_ 1
30 
31 #include "ycommon.h"
32 #if YCL_MINGW32
33 // NOTE: Make sure there are no uses of MinGW32 ::dirent, ::DIR, ::opendir, etc.
34 struct DIR;
35 struct dirent;
36 #else
37 # include <dirent.h>
38 #endif
39 
40 namespace platform
41 {
42 
43 //平台相关的全局常量。
44 
45 //最大路径长度。
46 #ifdef PATH_MAX
47 # define YCL_MAX_PATH_LENGTH PATH_MAX
48 #elif defined(MAXPATHLEN)
49 # define YCL_MAX_PATH_LENGTH MAXPATHLEN
50 #else
51 # define YCL_MAX_PATH_LENGTH 256
52 #endif
53 
54 //最大文件名长度。
55 #ifdef NAME_MAX
56 # define YCL_MAX_FILENAME_LENGTH NAME_MAX
57 #else
58 # define YCL_MAX_FILENAME_LENGTH YCL_MAX_PATH_LENGTH
59 #endif
60 
61 #ifdef YCL_API_FILESYSTEM_POSIX
62 
66 # define YCL_PATH_DELIMITER '/'
67 
70 # define YCL_PATH_SEPERATOR "/"
71 
74 # define YCL_PATH_ROOT YCL_PATH_SEPERATOR
75 
80 typedef char NativePathCharType;
81 #elif YCL_MINGW32
82 
86 # define YCL_PATH_DELIMITER '\\'
87 // #define YCL_PATH_DELIMITER L'\\'
92 # define YCL_PATH_SEPERATOR "\\"
93 // #define YCL_PATH_SEPERATOR L"\\"
98 # define YCL_PATH_ROOT YCL_PATH_SEPERATOR
99 
105 // typedef wchar_t NativePathCharType;
106 typedef char NativePathCharType;
107 #else
108 # error Unsupported platform found!
109 #endif
110 
111 //类型定义。
122 
123 // using ystdex;
125 using ystdex::path_t;
126 
127 
136 YF_API int
137 uopen(const char* filename, int oflag) ynothrow;
147 YF_API int
148 uopen(const char* filename, int oflag, int pmode) ynothrow;
156 YF_API int
157 uopen(const char16_t* filename, int oflag) ynothrow;
166 YF_API int
167 uopen(const char16_t* filename, int oflag, int pmode) ynothrow;
168 
177 YF_API std::FILE*
178 ufopen(const char* filename, const char* mode) ynothrow;
186 YF_API std::FILE*
187 ufopen(const char16_t* filename, const char16_t* mode) ynothrow;
188 
195 YF_API bool
196 ufexists(const char*) ynothrow;
203 YF_API bool
204 ufexists(const char16_t*) ynothrow;
210 template<class _tString>
211 inline bool
212 ufexists(const _tString& str) ynothrow
213 {
214  return ufexists(str.c_str());
215 }
216 
221 YF_API bool
223 
229 YF_API bool
230 udirexists(const_path_t) ynothrow;
236 template<class _tString>
237 inline bool
238 udirexists(const _tString& str) ynothrow
239 {
240  return udirexists(str.c_str());
241 }
242 
251 YF_API char*
252 getcwd_n(char* buf, std::size_t size) ynothrow;
253 
261 YF_API char16_t*
262 u16getcwd_n(char16_t* buf, std::size_t size) ynothrow;
263 
269 YF_API int
271 
276 YF_API bool
277 mkdirs(const_path_t) ynothrow;
278 
288 YF_API bool
289 truncate(std::FILE*, std::size_t) ynothrow;
290 
291 
296 class YF_API HFileNode final
297 {
298 public:
299  typedef ::DIR* IteratorType;
300 
306  static int LastError;
307 
308 private:
309  IteratorType dir;
314  ::dirent* p_dirent;
315 
316 public:
321  explicit
322  HFileNode(const_path_t path = {}) ynothrow
323  : dir(), p_dirent()
324  {
325  Open(path);
326  }
331  HFileNode(const HFileNode&) = default;
336  ~HFileNode() ynothrow
337  {
338  Close();
339  }
340 
346  HFileNode&
347  operator=(const HFileNode&) = default;
348 
353  HFileNode&
354  operator++() ynothrow;
359  HFileNode
360  operator++(int) ynothrow
361  {
362  return ++HFileNode(*this);
363  }
364 
369  explicit
370  operator bool() const ynothrow
371  {
372  return dir;
373  }
374 
379  bool
380  IsDirectory() const ynothrow;
381 
387  const char*
388  GetName() const ynothrow;
389 
394  void
395  Open(const_path_t) ynothrow;
396 
401  void
402  Close() ynothrow;
403 
408  void
409  Reset() ynothrow;
410 };
411 
412 
417 YF_API bool
419 
423 YF_API std::size_t
424 GetRootNameLength(const_path_t);
425 
426 } // namespace platform;
427 
428 namespace platform_ex
429 {
430 
431 } // namespace platform_ex;
432 
433 #endif
434