nomlib
Loading...
Searching...
No Matches
nom::UnixFile Class Reference

Platform-specific interface for file based access in Unix. More...

#include <UnixFile.hpp>

Inheritance diagram for nom::UnixFile:
[legend]

Public Member Functions

const std::string extension (const std::string &file)
int32 size (const std::string &file_path)
bool is_dir (const std::string &file_path)
 Test for the existence of a directory.
bool is_file (const std::string &file_path)
bool exists (const std::string &file_path)
const std::string path (const std::string &dir_path)
 Extract the directory portion of a pathname.
std::string currentPath (void)
bool set_path (const std::string &path)
const std::string basename (const std::string &filename)
std::vector< std::string > read_dir (const std::string &dir_path)
 Get a list of file entries within 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_documents_path (void)
 Get the path to the logged in user's Documents folder.
const std::string user_app_support_path (void)
 Get the path to the logged in user's Application Support folder.
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.
bool mkdir (const std::string &path)
 Create a directory entry.
bool recursive_mkdir (const std::string &path)
 Create directories recursively.
bool rmdir (const std::string &path)
 Remove a directory entry.
bool mkfile (const std::string &path)
 Create a file (zero bytes).
std::string env (const std::string &path)
 Get the value of an environment variable.
nom::size_type num_files (const std::string &path)
 Get the total number of files in a directory.

Detailed Description

Platform-specific interface for file based access in Unix.

See also
http://www.gnu.org/software/libc/manual/html_node/File-System-Interface.html#File-System-Interface

Definition at line 47 of file UnixFile.hpp.

Member Function Documentation

◆ basename()

const std::string nom::UnixFile::basename ( const std::string & filename)
virtual

Implements nom::IFile::basename

Remarks
See nom::IFile::basename

Implements nom::IFile.

◆ currentPath()

std::string nom::UnixFile::currentPath ( void )
virtual

Implements nom::IFile::currentPath

Remarks
See nom::IFile::currentPath

Implements nom::IFile.

◆ env()

std::string nom::UnixFile::env ( const std::string & path)
virtual

Get the value of an environment variable.

Returns
A null-terminated string (zero length) upon err, such as an non-existent environment variable.

Implements nom::IFile.

◆ exists()

bool nom::UnixFile::exists ( const std::string & file_path)
virtual

Implements nom::IFile::exists

Remarks
See nom::IFile::exists

Implements nom::IFile.

◆ extension()

const std::string nom::UnixFile::extension ( const std::string & file)
virtual

Implements nom::IFile::extension

Remarks
See nom::IFile::extension

Implements nom::IFile.

◆ is_dir()

bool nom::UnixFile::is_dir ( const std::string & file_path)
virtual

◆ is_file()

bool nom::UnixFile::is_file ( const std::string & file_path)
virtual

Implements nom::IFile.

◆ mkdir()

bool nom::UnixFile::mkdir ( const std::string & path)
virtual

Create a directory entry.

Parameters
pathThe absolute path to create the directory file at.
Returns
Boolean TRUE if the directory path does not exist and is able to be created, and boolean FALSE if the directory path already exists.
Todo
Look into possibly revising our err handling; providing the actual reason for failure is helpful in determining the course of action to take in the application's program flow?

Implements nom::IFile.

◆ mkfile()

bool nom::UnixFile::mkfile ( const std::string & path)
virtual

Create a file (zero bytes).

See also
man 8 mkfile

Implements nom::IFile.

◆ num_files()

nom::size_type nom::UnixFile::num_files ( const std::string & path)
virtual

Get the total number of files in a directory.

\params An absolute directory path.

Implements nom::IFile.

◆ path()

const std::string nom::UnixFile::path ( const std::string & dir_path)
virtual

Extract the directory portion of a pathname.

Remarks
Emulates POSIX dirname() function; see man (3) dirname.
Todo
Rename method to dirname?
Note
dir_path is arbitrarily limited to 1024 characters.

Implements nom::IFile::path.

Implements nom::IFile.

◆ read_dir()

std::vector< std::string > nom::UnixFile::read_dir ( const std::string & dir_path)
virtual

Get a list of file entries within a directory.

Remarks
The directory entries '.' and '..' are removed from the file listing.
Todo
Implement optional directory recursion.
Note
Source reference: http://www.gnu.org/software/libc/manual/html_node/Simple-Directory-Lister.html#Simple-Directory-Lister.

Implements nom::IFile.

◆ recursive_mkdir()

bool nom::UnixFile::recursive_mkdir ( const std::string & path)
virtual

Create directories recursively.

Parameters
pathThe absolute path to create directory entries from.
Returns
Boolean TRUE if the directory path does not exist and is able to be created, and boolean FALSE if the directory path already exists.
Remarks
The directory must not be terminated with a path separator.
Todo
Look into possibly revising our err handling; providing the actual reason for failure is helpful in determining the course of action to take in the application's program flow?

Implements nom::IFile.

◆ resource_path()

const std::string nom::UnixFile::resource_path ( const std::string & identifier = "\0")
virtual

Get the path to the Resources folder within a bundle.

Remarks
If no identifier argument is passed, it is assumed you are looking for the main application bundle's Resources path, otherwise the identifier is used to locate a particular bundle from within another bundle.

The bundle's identifier can be found within the Info.plist file of said bundle, and typically is in reverse DNS notation. The string might look something like this:

org.dev.nomlib

or, as per the official API documentation,

com.apple.Finder.MyGetInfoPlugIn

The one restriction you have in using this function call is that the bundle whose identifier you have passed must already be loaded into the application bundle, or else this function call will fail.

Returns
A null-terminated string on err.

Implements nom::IFile.

◆ rmdir()

bool nom::UnixFile::rmdir ( const std::string & path)
virtual

Remove a directory entry.

Parameters
pathThe absolute path to remove the directory file from.
Returns
Boolean TRUE if the directory path does not exist and is able to be created, and boolean FALSE if the directory path already exists.
Todo
Look into possibly revising our err handling; providing the actual reason for failure is helpful in determining the course of action to take in the application's program flow?

Implements nom::IFile.

◆ set_path()

bool nom::UnixFile::set_path ( const std::string & path)
virtual

Implements nom::IFile::set_path

Remarks
See nom::IFile::set_path

Implements nom::IFile.

◆ size()

int32 nom::UnixFile::size ( const std::string & file_path)
virtual

Implements nom::IFile::size

Remarks
See nom::IFile::size

Implements nom::IFile.

◆ system_path()

const std::string nom::UnixFile::system_path ( void )
virtual

Get the platform-defined system path.

Returns
Under Mac OS X: a directory path in the format of: "/System". Under POSIX-compliant Unix (not verified): "/bin" (Linux/BSD).
See also
http://stackoverflow.com/questions/19404239/locating-mac-os-x-folders-using-urlfordirectory-instead-of-fsfindfolder

Implements nom::IFile.

◆ user_app_support_path()

const std::string nom::UnixFile::user_app_support_path ( void )
virtual

Get the path to the logged in user's Application Support folder.

$HOME/Library/Application\ Support/
Remarks
These are standard folders that may be used for saving user data under.
Todo
FSFindFolder and FSRefMakePath are deprecated in OS X v10.8+.
See also
http://stackoverflow.com/questions/19404239/locating-mac-os-x-folders-using-urlfordirectory-instead-of-fsfindfolder

Implements nom::IFile.

◆ user_documents_path()

const std::string nom::UnixFile::user_documents_path ( void )
virtual

Get the path to the logged in user's Documents folder.

$HOME/Documents/
Remarks
These are standard folders that may be used for saving user data under.
Todo
FSFindFolder and FSRefMakePath are deprecated in OS X v10.8+.
See also
http://stackoverflow.com/questions/19404239/locating-mac-os-x-folders-using-urlfordirectory-instead-of-fsfindfolder

Implements nom::IFile.

◆ user_home_path()

const std::string nom::UnixFile::user_home_path ( void )
virtual

Get the current user's home directory path.

Returns
Under Mac OS X: a directory path in the format of: "/Users/<user>". Under POSIX-compliant Unix: either "/home" (Linux) or "/usr/home" (BSD).
See also
http://stackoverflow.com/questions/19404239/locating-mac-os-x-folders-using-urlfordirectory-instead-of-fsfindfolder

Implements nom::IFile.


The documentation for this class was generated from the following file: