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 "export.hpp"
40#include "nomlib/config.hpp"
41#include "nomlib/system/IFile.hpp"
42
43namespace nom {
44
48class NOM_EXPORT UnixFile: public IFile
49{
50 public:
51 UnixFile ( void );
52 ~UnixFile ( void );
53
57 const std::string extension ( const std::string& file );
58
62 int32 size ( const std::string& file_path );
63
67 bool is_dir( const std::string& file_path );
68
69 bool is_file( const std::string& file_path );
70
74 bool exists( const std::string& file_path );
75
85 const std::string path( const std::string& dir_path );
86
90 std::string currentPath( void );
91
95 bool set_path ( const std::string& path );
96
100 const std::string basename ( const std::string& filename );
101
110 std::vector<std::string> read_dir( const std::string& dir_path );
111
134 const std::string resource_path( const std::string& identifier = "\0" );
135
146 const std::string user_documents_path( void );
147
159 const std::string user_app_support_path( void );
160
168 const std::string user_home_path();
169
177 const std::string system_path();
178
179 // TODO: Implement getter method for platform's system temporary files path;
180 // (/tmp on POSIX and C:\Windows\Temp on Windows).
181 const std::string system_temp_path();
182
183 // \brief Get the platform-defined system path.
184 //
185 // \returns Under Mac OS X: a directory path in the format of:
186 // "/System/Library". Under POSIX-compliant Unix (not verified):
187 // "/bin" (Linux/BSD). Under Windows: "<drive>:\Windows".
188 const std::string system_library_path();
189
190 // \brief Get the platform-defined system fonts path.
191 //
192 // \returns Under Mac OS X: a directory path in the format of:
193 // "/System/Library/Fonts". Under POSIX-compliant Unix (not verified):
194 // "/usr/share/fonts" (Linux/BSD). Under Windows: "<drive>:\Windows\Fonts".
195 const std::string system_fonts_path();
196
207 bool mkdir( const std::string& path );
208
221 bool recursive_mkdir( const std::string& path );
222
233 bool rmdir( const std::string& path );
234
238 bool mkfile( const std::string& path );
239
244 std::string env( const std::string& path );
245
246 nom::size_type num_files(const std::string& path);
247};
248
249
250} // namespace nom
251
252#endif // include guard
253
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 system_path()
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)
const std::string user_home_path()
Get the current user's home directory path.
bool rmdir(const std::string &path)
Remove a directory entry.
std::string env(const std::string &path)
Get the value of an environment variable.