nomlib
Loading...
Searching...
No Matches
File.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_FILE_HEADERS
30#define NOMLIB_FILE_HEADERS
31
32#include <string>
33#include <vector>
34
35#include "nomlib/config.hpp"
36#include "nomlib/system/IFile.hpp"
37
38#if defined ( NOM_PLATFORM_OSX ) || defined ( NOM_PLATFORM_POSIX )
39
40 #include "nomlib/system/unix/UnixFile.hpp"
41
42#elif defined ( NOM_PLATFORM_WINDOWS )
43
44 #include "nomlib/system/windows/WinFile.hpp"
45
46#endif
47
48namespace nom {
49
50// Forward declarations
51class IFile;
52
54class File
55{
56 public:
57 File();
58 ~File();
59
61 std::string extension(const std::string& file) const;
62
64 int32 size(const std::string& file_path) const;
65
67 bool is_dir(const std::string& file_path) const;
68
69 bool is_file(const std::string& file_path) const;
70
72 bool exists(const std::string& file_path) const;
73
77 std::string path(const std::string& dir_path) const;
78
80 std::string currentPath() const;
81
83 bool set_path(const std::string& path) const;
84
86 std::string basename(const std::string& filename) const;
87
88 std::vector<std::string> read_dir(const std::string& dir_path) const;
89
90 std::string resource_path(const std::string& identifier = "\0") const;
91
92 std::string user_documents_path() const;
93
94 std::string user_app_support_path() const;
95
96 std::string user_home_path() const;
97
98 std::string system_path() const;
99
101 bool mkdir(const std::string& path) const;
102
104 bool recursive_mkdir(const std::string& path) const;
105
107 bool rmdir(const std::string& path) const;
108
110 bool mkfile(const std::string& path) const;
111
113 std::string env(const std::string& path) const;
114
116 nom::size_type num_files(const std::string& path) const;
117
118 private:
119 std::unique_ptr<IFile> file;
120};
121
122namespace priv {
123
125extern std::string file_root_;
126
127} // namespace priv
128
134std::string file_root();
135
144void set_file_root(const std::string& root);
145
146} // namespace nom
147
148#endif // include guard
149
bool is_dir(const std::string &file_path) const
Test for the existence of a directory.
int32 size(const std::string &file_path) const
Re-implements nom::IFile::size.
bool mkdir(const std::string &path) const
std::string env(const std::string &path) const
bool exists(const std::string &file_path) const
Re-implements nom::IFile::exists.
bool mkfile(const std::string &path) const
bool recursive_mkdir(const std::string &path) const
std::string path(const std::string &dir_path) const
Platform-specific implementation of IFile::path.
std::string currentPath() const
Re-implements nom::IFile::currentPath.
nom::size_type num_files(const std::string &path) const
std::string basename(const std::string &filename) const
Re-implements nom::IFile::basename.
std::string extension(const std::string &file) const
Re-implements nom::IFile::extension.
bool set_path(const std::string &path) const
Re-implements nom::IFile::set_path.
bool rmdir(const std::string &path) const
Abstract interface class for Platform-agnostic file access.
Definition IFile.hpp:43