nomlib
Loading...
Searching...
No Matches
UnixFile.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_UNIX_FILE_HEADERS
30#define NOMLIB_UNIX_FILE_HEADERS
31
32#include <iostream>
33#include <string>
34#include <sstream>
35#include <cstring>
36#include <vector>
37#include <fstream>
38
39#include "nomlib/config.hpp"
40#include "nomlib/system/IFile.hpp"
41
42namespace nom {
43
47class UnixFile: public IFile
48{
49 public:
50 UnixFile ( void );
51 ~UnixFile ( void );
52
56 const std::string extension ( const std::string& file );
57
61 int32 size ( const std::string& file_path );
62
66 bool is_dir( const std::string& file_path );
67
68 bool is_file( const std::string& file_path );
69
73 bool exists( const std::string& file_path );
74
84 const std::string path( const std::string& dir_path );
85
89 std::string currentPath( void );
90
94 bool set_path ( const std::string& path );
95
99 const std::string basename ( const std::string& filename );
100
109 std::vector<std::string> read_dir( const std::string& dir_path );
110
133 const std::string resource_path( const std::string& identifier = "\0" );
134
145 const std::string user_documents_path( void );
146
158 const std::string user_app_support_path( void );
159
167 const std::string user_home_path( void );
168
176 const std::string system_path( void );
177
178 // TODO: Implement getter method for platform's system temporary files path;
179 // (/tmp on POSIX and C:\Windows\Temp on Windows).
180 // const std::string system_temp_path( void );
181
182 // \brief Get the platform-defined system path.
183 //
184 // \returns Under Mac OS X: a directory path in the format of:
185 // "/System/Library". Under POSIX-compliant Unix (not verified):
186 // "/bin" (Linux/BSD). Under Windows: "<drive>:\Windows".
187 // const std::string system_library_path( void );
188
189 // \brief Get the platform-defined system fonts path.
190 //
191 // \returns Under Mac OS X: a directory path in the format of:
192 // "/System/Library/Fonts". Under POSIX-compliant Unix (not verified):
193 // "/usr/share/fonts" (Linux/BSD). Under Windows: "<drive>:\Windows\Fonts".
194 // const std::string system_fonts_path( void );
195
206 bool mkdir( const std::string& path );
207
220 bool recursive_mkdir( const std::string& path );
221
232 bool rmdir( const std::string& path );
233
237 bool mkfile( const std::string& path );
238
243 std::string env( const std::string& path );
244
245 nom::size_type num_files(const std::string& path);
246};
247
248
249} // namespace nom
250
251#endif // include guard
252
const std::string basename(const std::string &filename)
bool mkfile(const std::string &path)
Create a file (zero bytes).
bool recursive_mkdir(const std::string &path)
Create directories recursively.
bool is_dir(const std::string &file_path)
Test for the existence of a directory.
const std::string resource_path(const std::string &identifier="\0")
Get the path to the Resources folder within a bundle.
const std::string user_app_support_path(void)
Get the path to the logged in user's Application Support folder.
const std::string user_documents_path(void)
Get the path to the logged in user's Documents folder.
std::vector< std::string > read_dir(const std::string &dir_path)
Get a list of file entries within a directory.
const std::string extension(const std::string &file)
const std::string path(const std::string &dir_path)
Extract the directory portion of a pathname.
nom::size_type num_files(const std::string &path)
Get the total number of files in a directory.
bool set_path(const std::string &path)
const std::string user_home_path(void)
Get the current user's home directory path.
const std::string system_path(void)
Get the platform-defined system path.
int32 size(const std::string &file_path)
bool exists(const std::string &file_path)
bool mkdir(const std::string &path)
Create a directory entry.
std::string currentPath(void)
bool rmdir(const std::string &path)
Remove a directory entry.
std::string env(const std::string &path)
Get the value of an environment variable.