Path_t Class Reference

Class to encapsulate a path to a file or directory and facilitate path operations. More...

#include <UTPath.h>

Inheritance diagram for Path_t:
String_t Buffer_t PathB_t

List of all members.

Public Member Functions

 Path_t ()
 Path_t (byte *buffer, int buffer_size)
 Path_t (stringliteral *path)
 Path_t (const utf8 *path)
 Path_t (const Path_t &path)
 Path_t (const String_t &path)
Status_t Set (stringliteral *path)
Status_t Set (const utf8 *path)
Status_t Set (const Path_t &path)
Status_t Set (const String_t &path)
const Path_toperator= (stringliteral *path)
const Path_toperator= (const utf8 *path)
const Path_toperator= (const Path_t &path)
const Path_toperator= (const String_t &path)
bool IsPathValid () const
Status_t Append (stringliteral *leaf)
Status_t Append (const utf8 *leaf)
Status_t Append (const Path_t &leaf)
Status_t Append (const String_t &leaf)
Status_t AppendToLeaf (stringliteral *add_to_leaf)
Status_t AppendToLeaf (const utf8 *add_to_leaf)
Status_t AppendToLeaf (const String_t &add_to_leaf)
const Path_toperator+= (stringliteral *path)
const Path_toperator+= (const utf8 *path)
const Path_toperator+= (const Path_t &leaf)
const Path_toperator+= (const String_t &leaf)
Path_t operator+ (stringliteral *append) const
Path_t operator+ (const utf8 *append) const
Path_t operator+ (const Path_t &append) const
Path_t operator+ (const String_t &append) const
Status_t GetLeafName (Path_t *leaf) const
Status_t ToRelative (const Path_t &relative_to, bool canonical=true)
Status_t ToParent ()
Status_t GetParent (Path_t *parent) const
Status_t IsDirectory () const
Status_t GetDirectory (Path_t *dir) const
Status_t IsAbsolute () const
Status_t MakeAbsolute ()
Status_t IsRootDirectory () const
Status_t IsRegularFile () const
Status_t RegularFileSize (fileoff_t *size) const
Status_t IsSymLink () const
Status_t MakeDir (bool recursive=true, mode_t permissions=(S_IRUSR|S_IWUSR)|S_IXUSR) const
Status_t Delete (bool recursive=false) const
Status_t StripCurrAndParentDirs ()

Static Public Member Functions

static Status_t GetAppPath (Path_t *app_path)
static Status_t GetAppDir (Path_t *app_dir)
static Status_t GetCurrentWorkingDir (Path_t *cwd)
static Status_t SetCurrentWorkingDir (const Path_t &cwd)
static Status_t GetHomeDir (Path_t *home)
static bool IsDelimiter (utf8 c)

Detailed Description

Class to encapsulate a relative or absolute path to a file or directory and facilitate path operations without the developer having to be concerned with platforms like Windows which use a nonstandard path delimiter. '/' is treated as being the canonical path delimiter, and the path object will accept it and treat it as such. On platforms which use a nonstandard path delimiter, the UT library will convert any slashes to the nonstandard delimiter when it needs to use a such a path in a system call.

Definition at line 49 of file UTPath.h.


Constructor & Destructor Documentation

Path_t::Path_t (  )  [inline]

Constructor for an empty path.

Definition at line 567 of file UTPath.h.

Path_t::Path_t ( byte buffer,
int  buffer_size 
) [inline]

Constructor for a path which initially uses a stack-allocated buffer of the specified size. If the required size grows beyond that size, the buffer will be reallocated from the heap. Unless it is guaranteed that the needed size is going to be less than PATH_MAX, if a stack buffer is to be used, PathB_t would be a more straightforward way to accomplish the same thing since it has a built-in buffer of size PATH_MAX. A file does not need to exist at the path to be valid.

Definition at line 572 of file UTPath.h.

Path_t::Path_t ( stringliteral path  )  [inline]

Path which persistently references a string literal; the pointer is borrowed. Therefore the path object is dependent on the pointer with which it was constructed. The contents of that pointer must remain valid for the life of the path object. Any manipulation of the path will cause the contents to be copied to a dynamically allocated buffer. At that point, the path object will no longer be dependent on the contents of the string literal constant. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Definition at line 578 of file UTPath.h.

Path_t::Path_t ( const utf8 path  )  [inline]

Constructor which initializes itself using the specified string. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Definition at line 584 of file UTPath.h.

Path_t::Path_t ( const Path_t path  )  [inline]

Copy constructor. A file does not need to exist at the path to be valid.

Definition at line 590 of file UTPath.h.

Path_t::Path_t ( const String_t path  )  [inline]

Constructor which initializes itself using the specified string. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Definition at line 596 of file UTPath.h.


Member Function Documentation

Status_t Path_t::Set ( stringliteral path  )  [inline]

Copies the specified path string into this and checks the path's validity. If the path is invalid, an error status is returned. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 602 of file UTPath.h.

Status_t Path_t::Set ( const utf8 path  )  [inline]

Copies the specified path string into this and checks the path's validity. If the path is invalid, an error status is returned. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 612 of file UTPath.h.

Status_t Path_t::Set ( const Path_t path  )  [inline]

Copies the specified path into this and checks the path's validity. If the path is invalid, an error status is returned. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 622 of file UTPath.h.

Status_t Path_t::Set ( const String_t path  )  [inline]

Copies the specified path string into this and checks the path's validity. If the path is invalid, an error status is returned. A file does not need to exist at the path to be valid.

Definition at line 632 of file UTPath.h.

const Path_t & Path_t::operator= ( stringliteral path  )  [inline]

Copies the specified path string into this. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Reimplemented in PathB_t.

Definition at line 642 of file UTPath.h.

const Path_t & Path_t::operator= ( const utf8 path  )  [inline]

Copies the specified path string into this. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Reimplemented in PathB_t.

Definition at line 650 of file UTPath.h.

const Path_t & Path_t::operator= ( const Path_t path  )  [inline]

Copies the specified path into this. The path is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 658 of file UTPath.h.

const Path_t & Path_t::operator= ( const String_t path  )  [inline]

Copies the specified path string into this. The path string is assumed to be valid. If it is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented in PathB_t.

Definition at line 666 of file UTPath.h.

bool Path_t::IsPathValid (  )  const

Checks the path's validity. Returns true if the path is valid, false if it is not. A file does not need to exist at the path to be valid.

Status_t Path_t::Append ( stringliteral leaf  )  [inline]

Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 674 of file UTPath.h.

Status_t Path_t::Append ( const utf8 leaf  ) 

Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Status_t Path_t::Append ( const Path_t leaf  )  [inline]

Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 681 of file UTPath.h.

Status_t Path_t::Append ( const String_t leaf  )  [inline]

Appends a leaf name or relative path. The Append function will automatically add a path delimiter before the appended path if necessary. If the existing path or the appended leaf name or relative path is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Definition at line 688 of file UTPath.h.

Status_t Path_t::AppendToLeaf ( stringliteral add_to_leaf  )  [inline]

Appends more text to the leaf name. If the existing path or the appended text is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Definition at line 695 of file UTPath.h.

Status_t Path_t::AppendToLeaf ( const utf8 add_to_leaf  )  [inline]

Appends more text to the leaf name. If the existing path or the appended text is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Definition at line 707 of file UTPath.h.

Status_t Path_t::AppendToLeaf ( const String_t add_to_leaf  )  [inline]

Appends more text to the leaf name. If the existing path or the appended text is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Definition at line 719 of file UTPath.h.

const Path_t & Path_t::operator+= ( stringliteral path  )  [inline]

Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 729 of file UTPath.h.

const Path_t & Path_t::operator+= ( const utf8 path  )  [inline]

Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 737 of file UTPath.h.

const Path_t & Path_t::operator+= ( const Path_t leaf  )  [inline]

Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Reimplemented from String_t.

Definition at line 745 of file UTPath.h.

const Path_t & Path_t::operator+= ( const String_t leaf  )  [inline]

Appends a leaf name or relative path. operator += will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid.

Definition at line 753 of file UTPath.h.

Path_t Path_t::operator+ ( stringliteral append  )  const [inline]

Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.

Reimplemented from String_t.

Definition at line 761 of file UTPath.h.

Path_t Path_t::operator+ ( const utf8 append  )  const [inline]

Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.

Reimplemented from String_t.

Definition at line 770 of file UTPath.h.

Path_t Path_t::operator+ ( const Path_t append  )  const [inline]

Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.

Reimplemented from String_t.

Definition at line 779 of file UTPath.h.

Path_t Path_t::operator+ ( const String_t append  )  const [inline]

Returns a concatenation of this and the append parameter, appended as a separate leaf name or relative path as with operator +=. operator + will automatically add a path delimiter before the appended path if necessary. The existing and appended paths are assumed to be valid. If either is not, subsequent operations will fail. A file does not need to exist at the path to be valid. This operator is provided for convenience and should not be used when efficiency is needed due to the copy constructors invoked by return-by-value conventions.

Definition at line 788 of file UTPath.h.

Status_t Path_t::GetLeafName ( Path_t leaf  )  const

Obtains the name of the last path element. That could be the name of the specified file with all path information removed, or the name of the specified directory with all parent path components removed. If the path is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Status_t Path_t::ToRelative ( const Path_t relative_to,
bool  canonical = true 
)

Converts the path to be relative to the path sepecified by relative to. If canonical is true, any nonstandard path delimiters (like '\' under Windows) will be converted to the canonical '/' delimiter.

Status_t Path_t::ToParent (  ) 

Removes the last path element. If the path is a relative path, the ToParent function will resolve the parent path to an absolute path if necessary. If the path is not valid, or has no parent directory, an error status is returned. A file does not need to exist at the path to be valid.

Status_t Path_t::GetParent ( Path_t parent  )  const [inline]

Obtains the parent directory of the path specified by this. If this specifies a relative path, the GetParent function will resolve the parent path to an absolute path if necessary. If the path specified by this is not valid, or has no parent directory, an error status is returned. A file does not need to exist at the path to be valid.

Definition at line 797 of file UTPath.h.

Status_t Path_t::IsDirectory (  )  const

Checks whether this is a directory (not a regular file, pipe, etc). If this is not a valid path, or the specified path does not exist, IsDirectory returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult(). If the path is a symbolic link, it will be dereferenced.

Status_t Path_t::GetDirectory ( Path_t dir  )  const

If this is a directory, dir will be set to the same path specified by this. If this is a file, dir will be set to the parent directory of the file.

Status_t Path_t::IsAbsolute (  )  const

Checks whether this is an absolute path. If this is not a valid path, IsAbsolute returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult(). A file does not need to exist at the path to be valid.

Status_t Path_t::MakeAbsolute (  ) 

If this specifies a relative path, it will be converted to an absolute path. If the path specified by this is not valid, an error status is returned. A file does not need to exist at the path to be valid.

Status_t Path_t::IsRootDirectory (  )  const

Checks whether this is a root path (one with no parent). If this is not a valid path, IsRootDirectory returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult().

Status_t Path_t::IsRegularFile (  )  const

Checks whether this is a regular file (not a directory, pipe, etc). If this is not a valid path, or the specified path does not exist, IsRegularFile returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult(). If the path is a symbolic link, it will be dereferenced.

Status_t Path_t::RegularFileSize ( fileoff_t size  )  const

Checks whether this is a regular file. If it is, returns a success status and sets *size to indicate the size of the file. If the path is a symbolic link, it will be dereferenced.

Status_t Path_t::IsSymLink (  )  const

Checks whether this is a symbolic link. If this is not a valid path, or the specified path does not exist, IsSymLink returns an error status, otherwise a Status_t with a non-error status of true or false will be returned. A non-error status can be checked using Status_t::BoolResult().

Status_t Path_t::MakeDir ( bool  recursive = true,
mode_t  permissions = (S_IRUSR|S_IWUSR)|S_IXUSR 
) const

Creates a directory at the specified path. If it already exists and is a regular directory, returns the POSIX error EEXIST. If it already exists but is not a directory, returns the POSIX error ENOTDIR. The following symbolic constants are provided for permissions:

S_IRWUSR user (file owner) has read, write permission
S_IRWXU user (file owner) has read, write and execute permission
S_IRUSR (S_IREAD) user has read permission
S_IWUSR (S_IWRITE) user has write permission
S_IXUSR (S_IEXEC) user has execute permission

S_IRWGRP group has read, write permission
S_IRWXG group has read, write and execute permission
S_IRGRP group has read permission
S_IWGRP group has write permission
S_IXGRP group has execute permission

S_IRWOTH others have read, write permission
S_IRWXO others have read, write and execute permission
S_IROTH others have read permission
S_IWOTH others have write permisson
S_IXOTH others have execute permission

Status_t Path_t::Delete ( bool  recursive = false  )  const

Deletes the file or directory at the specified path. If no such file or directory existed, returns the POSIX error ENOENT. If the path to be deleted is a directory and it is not empty, it can only be deleted if the recursive parameter is true.

static Status_t Path_t::GetAppPath ( Path_t app_path  )  [static]

Obtains the path of the application executable. If an error occurs, an error status will be returned.

static Status_t Path_t::GetAppDir ( Path_t app_dir  )  [static]

Obtains the path of the directory containing the application executable. If an error occurs, an error status will be returned.

static Status_t Path_t::GetCurrentWorkingDir ( Path_t cwd  )  [static]

Obtains the current working directory. If an error occurs, an error status will be returned.

static Status_t Path_t::SetCurrentWorkingDir ( const Path_t cwd  )  [static]

Sets the current working directory. If an error occurs, an error status will be returned.

static Status_t Path_t::GetHomeDir ( Path_t home  )  [static]

Obtains the path of the user's home directory.

bool Path_t::IsDelimiter ( utf8  c  )  [inline, static]

Returns true if the character c is a path delimiter. If c is '/' (the canonical delimiter), it will always return true. On platforms which use a nonstandard delimiter (like Windows' '\'), it will also return true if c matches the nonstandard delimiter. This function will not return true for the character used to delimit separate complete paths as in "C:\a;C:\b" or "/usr/bin:/sbin").

Definition at line 805 of file UTPath.h.

Status_t Path_t::StripCurrAndParentDirs (  )  [inline]

Strips current (".") and parent ("Parent/..") elements from the path.

Definition at line 818 of file UTPath.h.


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

Generated on Tue Dec 14 22:35:07 2010 for UT library by  doxygen 1.6.1