iash  v0.5
Library to provide a bash-like shell in an application
Directory Class Reference

Represents a directory on the filesystem. More...

#include <Directory.h>

Public Member Functions

 Directory ()
 Creates a Directory instance pointed at the application's current working directory. More...
 
 Directory (const std::string &dir)
 Creates a Directory instance pointed at the directory dir. More...
 
bool isValid () const
 Checks if the Directory object points to an existing directory. More...
 
const std::string & getAbsPath () const
 Gets the absolute path to this Directory from the root of the filesystem. More...
 
bool changeDirRel (const std::string &relPath)
 Changes this Directory instance to point at the directory with path relPath relative to the directory currently pointed to by this Directory. More...
 
bool changeDirAbs (const std::string &absPath)
 Changes this Directory instance to point at the directory with the absolute path absPath. More...
 
std::string resolvePath (const std::string &relpath) const
 Converts a path relative to the current Directory to an absolute path. More...
 
int mkSubdir (const std::string &dirName) const
 Creates a directory inside of the current Directory instance. More...
 
bool dirExists (const std::string &dirName) const
 Checks if the given dirname represents an existing directory inside of the current Directory. More...
 
bool fileExists (const std::string &filename) const
 Checks if the given filename represents an existing file inside of the current Directory. More...
 

Static Public Member Functions

static int mkdir (const char *pathname)
 Creates a directory with the absolute path pathname. More...
 
static bool isDir (const char *pathname)
 Checks if pathname refers to an existing directory. More...
 
static bool isFile (const char *pathname)
 Checks if pathname refers to an existing file. More...
 
static std::string toIash (const std::string &pathname)
 Converts pathname from system path representation to iash path representation. More...
 
static std::string toPlatform (const std::string &pathname)
 Converts pathname from iash path representation to the platform's path representation. More...
 
static Directory getHomeDir ()
 Gets the user's home directory as a Directory instance. More...
 
static Directory getConfigDir ()
 Gets the user's root application configuration directory ad a Directory instance. More...
 
static Directory getWorkingDir ()
 Gets the working directory for this process. More...
 

Detailed Description

Represents a directory on the filesystem.

Intended to help with managing filesystem resources in a cross-platform manner.

On Windows platforms, Directory will convert all directory separators to forward slashes (/) from backslashes (\), and expects all arguments to use forward slashes. Since fstream will accept either, there is usually no need to change this.

Since
0.5

Constructor & Destructor Documentation

◆ Directory() [1/2]

Directory::Directory ( )

Creates a Directory instance pointed at the application's current working directory.

Note that this is NOT the same as the iash current working directory; this is actually held as a Directory instance internal to iash.

◆ Directory() [2/2]

Directory::Directory ( const std::string &  dir)

Creates a Directory instance pointed at the directory dir.

Parameters
dirthe directory path to create this Directory at

Member Function Documentation

◆ changeDirAbs()

bool Directory::changeDirAbs ( const std::string &  absPath)

Changes this Directory instance to point at the directory with the absolute path absPath.

Returns
if the change operationb was successful (the new directory exists)

◆ changeDirRel()

bool Directory::changeDirRel ( const std::string &  relPath)

Changes this Directory instance to point at the directory with path relPath relative to the directory currently pointed to by this Directory.

Returns
if the change operation was successful (the new directory exists)

◆ dirExists()

bool Directory::dirExists ( const std::string &  dirName) const

Checks if the given dirname represents an existing directory inside of the current Directory.

Parameters
dirNamethe name of the directory to check for existence
Returns
true if the directory exists, false otherwise
See also
Directory::isDir

◆ fileExists()

bool Directory::fileExists ( const std::string &  filename) const

Checks if the given filename represents an existing file inside of the current Directory.

Parameters
filenamethe name of the file to check for existence
Returns
true if the file exists, false otherwise
See also
Directory::isFile

◆ getAbsPath()

const string & Directory::getAbsPath ( ) const

Gets the absolute path to this Directory from the root of the filesystem.

Returns
the absolute path

◆ getConfigDir()

Directory Directory::getConfigDir ( )
static

Gets the user's root application configuration directory ad a Directory instance.

This does not refer to the application's specific configuration directory.

Returns
the user's configuration directory

◆ getHomeDir()

Directory Directory::getHomeDir ( )
static

Gets the user's home directory as a Directory instance.

Returns
the user's home directory as a Directory

◆ getWorkingDir()

Directory Directory::getWorkingDir ( )
static

Gets the working directory for this process.

Note that this is not the same as the iash working directory; iash stores that internally as a Directory instance.

Returns
the process' current working directory

◆ isDir()

bool Directory::isDir ( const char *  pathname)
static

Checks if pathname refers to an existing directory.

Parameters
pathnamethe path of the directory to check for existence
Returns
true if the path represents an existing directory, false otherwise

◆ isFile()

bool Directory::isFile ( const char *  pathname)
static

Checks if pathname refers to an existing file.

Parameters
pathnamethe path of the file to check for existence
Returns
true if the path represents an existing file, false otherwise

◆ isValid()

bool Directory::isValid ( ) const

Checks if the Directory object points to an existing directory.

Returns
true if the Directory exists, false otherwise

◆ mkdir()

int Directory::mkdir ( const char *  pathname)
static

Creates a directory with the absolute path pathname.

Parameters
pathnamethe absolute path of the new directory
Returns
0 if successful, -1 otherwise
See also
https://linux.die.net/man/2/mkdir

◆ mkSubdir()

int Directory::mkSubdir ( const std::string &  dirName) const

Creates a directory inside of the current Directory instance.

Parameters
dirNamethe name for the new directory
Returns
the return value of Directory::mkdir for this operation
See also
Directory::mkdir

◆ resolvePath()

string Directory::resolvePath ( const std::string &  relpath) const

Converts a path relative to the current Directory to an absolute path.

Parameters
relpatha path relative to the current Directory
Returns
the absolute path to the item referred to by relpath

◆ toIash()

string Directory::toIash ( const std::string &  pathname)
static

Converts pathname from system path representation to iash path representation.

On Unix/Linux/macOS, this does nothing.

Parameters
pathnamethe path to convert to iash representation
Returns
the path in iash representation

◆ toPlatform()

string Directory::toPlatform ( const std::string &  pathname)
static

Converts pathname from iash path representation to the platform's path representation.

On Unix/Linux/macOS, this does nothing.

Parameters
pathnamethe path to convert to platform representation
Returns
the path in platform representation

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