Pyrogenesis  trunk
file_system.h
Go to the documentation of this file.
1 /* Copyright (c) 2016 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * higher-level interface on top of sysdep/filesystem.h
25  */
26 
27 #ifndef INCLUDED_FILE_SYSTEM
28 #define INCLUDED_FILE_SYSTEM
29 
30 #include "lib/os_path.h"
31 #include "lib/posix/posix_filesystem.h" // mode_t
32 
33 
34 LIB_API bool DirectoryExists(const OsPath& path);
35 LIB_API bool FileExists(const OsPath& pathname);
36 
37 LIB_API u64 FileSize(const OsPath& pathname);
38 
39 
40 // (bundling size and mtime avoids a second expensive call to stat())
41 class CFileInfo
42 {
43 public:
45  {
46  }
47 
48  CFileInfo(const OsPath& name, off_t size, time_t mtime)
49  : name(name), size(size), mtime(mtime)
50  {
51  }
52 
53  const OsPath& Name() const
54  {
55  return name;
56  }
57 
58  off_t Size() const
59  {
60  return size;
61  }
62 
63  time_t MTime() const
64  {
65  return mtime;
66  }
67 
68 private:
71  time_t mtime;
72 };
73 
74 LIB_API Status GetFileInfo(const OsPath& pathname, CFileInfo* fileInfo);
75 
76 typedef std::vector<CFileInfo> CFileInfos;
77 typedef std::vector<OsPath> DirectoryNames;
78 
79 LIB_API Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, DirectoryNames* subdirectoryNames);
80 
81 // same as boost::filesystem::create_directories, except that mkdir is invoked with
82 // <mode> instead of 0755.
83 // If the breakpoint is enabled, debug_break will be called if the directory didn't exist and couldn't be created.
84 LIB_API Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint = true);
85 
86 LIB_API Status DeleteDirectory(const OsPath& dirPath);
87 
88 #endif // #ifndef INCLUDED_FILE_SYSTEM
CFileInfo(const OsPath &name, off_t size, time_t mtime)
Definition: file_system.h:48
The MIT License free of to any person obtaining a copy of this software and associated documentation files(the"Software")
LIB_API bool DirectoryExists(const OsPath &path)
Definition: file_system.cpp:37
LIB_API u64 FileSize(const OsPath &pathname)
Definition: file_system.cpp:57
const OsPath & Name() const
Definition: file_system.h:53
LIB_API Status GetFileInfo(const OsPath &pathname, CFileInfo *fileInfo)
Definition: file_system.cpp:65
LIB_API bool FileExists(const OsPath &pathname)
Definition: file_system.cpp:49
LIB_API Status GetDirectoryEntries(const OsPath &path, CFileInfos *files, DirectoryNames *subdirectoryNames)
Definition: file_system.cpp:87
LIB_API Status CreateDirectories(const OsPath &path, mode_t mode, bool breakpoint=true)
Definition: file_system.cpp:133
OsPath name
Definition: file_system.h:69
uint64_t u64
Definition: types.h:40
LIB_API Status DeleteDirectory(const OsPath &dirPath)
Definition: file_system.cpp:167
__int64 off_t
Definition: wposix_types.h:91
Definition: path.h:77
off_t size
Definition: file_system.h:70
off_t Size() const
Definition: file_system.h:58
CFileInfo()
Definition: file_system.h:44
i64 Status
Error handling system.
Definition: status.h:171
time_t mtime
Definition: file_system.h:71
time_t MTime() const
Definition: file_system.h:63
std::vector< OsPath > DirectoryNames
Definition: file_system.h:77
std::vector< CFileInfo > CFileInfos
Definition: file_system.h:76
Definition: file_system.h:41