PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXPath
Class for operating a file path and a directory path.
#include <SFXPath.h.hpp>
class SFXPath;
SFMTYPEDEFCLASS(SFXPath)

Collaboration diagram

 Collaboration diagram of SFXPathClass

Description

SFXPath is a class that gets a parent directory, converts a relative path into a absolute path, and set a file name or suffix.

The distinction between file and directory can be made by checking whether the last character of path is " / " or not.

Reference

SFXFile | SFXDirectory | File Path

Member

Constructor/Destructor
SFXPath( Void )
Constructor of SFXPath class.
SFXPath( SFXPathConstRef param )
Constructor of SFXPath class.
SFXPath( SFXAnsiStringConstRef param )
Constructor of SFXPath class.
Public Functions
SFXAnsiString AsDirectory( Void )
Convert a directory path into a string.
SFXPath AsDirectoryPath( Void )
Convert a path name into a directory path.
SFXAnsiString AsFile( Void )
Convert a file path into a string.
SFXPath AsFilePath( Void )
Convert a path name into a file path.
Void Clear( Void )
Clear the path.
static
SFXPathConstRef
EmptyInstance( Void )
Get the empty path.
Bool Equals( SFXPathConstRef param )
Check whether two paths equal or not.
SFXAnsiStringConstRef Get( Void )
Get the path in a string.
SFXAnsiString GetAbsolute( Void )
Get the absolute path in a string.
SFXPath GetAbsolutePath( Void )
Get the absolute path.
SFXAnsiString GetExtension( Void )
Get the file extention.
SFXAnsiString GetName( Bool extension = false )
Get the file or directory name.
SFXAnsiString GetParent( Void )
Get the parent directory path in a string.
SFXPath GetParentPath( Void )
Get the parent directory path.
static
SFXPath
HomeDirectoryPath( Void )
Get the home directory path.
Bool IsAbsolute( Void )
Check whether the path is an absolute path or not.
Bool IsDirectory( Void )
Check whether the path is a directory or not.
Bool IsHomeDirectory( Void )
Check whether the path is a home directory or not.
Bool IsRootDirectory( Void )
Check whether the path is a root directory or not.
SFXAnsiString Normalize( Void )
Normalize the path.
SFXPath NormalizePath( Void )
Get the normalized path.
static
SFXPath
RootDirectoryPath( Void )
Get the path of root directory.
SFCError Set( SFXPathConstRef param )
Set( SFXAnsiStringConstRef param )
Set the path.
SFCError SetExtension( SFXAnsiStringConstRef extension )
Set the file extention.
SFCError SetName( SFXAnsiStringConstRef name , Bool extension = false )
Set the file or directory name.
Void ToDirectory( Void )
Interpret the current path as directory.
Void ToFile( Void )
Interpret the current path as file.
Bool operator!=( SFXPathConstRef left , SFXPathConstRef right )
Check the relation of " != ".
SFXPathRef operator=( SFXPathConstRef param )
Substitute the path.
Bool operator==( SFXPathConstRef left , SFXPathConstRef right )
Check the relation of " == ".

SFXPath::SFXPath
Constructor of SFXPath class.
[ public, explicit ]
SFXPath(Void);
[ public ]
SFXPath(
    SFXPathConstRef param   // path to set
);
[ public, explicit ]
SFXPath(
    SFXAnsiStringConstRef param   // path to set
);

Description

Create a path by copying the object specified as an argument of the constructor.

Reference

SFXPath::Set | SFXPath::operator=


SFXPath::AsDirectory
Convert a directory path into a string.
[ public, const ]
SFXAnsiString AsDirectory(Void);

Description

If the path is of file, it will be converted into the path string with " / " appended at the end.

Example

SFXPath path("/user/admin/brew/a/b/c");
SFXAnsiString str;

// convert a directory path into a string
str = path.AsDirectory();  

// /user/admin/brew/a/b/c/
TRACE("%s", str.GetCString()); 

Reference

SFXPath::AsDirectoryPath | SFXPath::ToDirectory | SFXPath::AsFile


SFXPath::AsDirectoryPath
Convert a path name into a directory path.
[ public, const ]
SFXPath AsDirectoryPath(Void);

Description

If the path is of file, it will be converted into the path string with " / " appended at the end.

Example

SFXPath path1("/user/admin/brew/a/b/c");
SFXPath path2;

// convert path name into directory path
path2 = path.AsDirectoryPath();  

// /user/admin/brew/a/b/c/
TRACE("%s", path2.Get().GetCString()); 

Reference

SFXPath::AsFilePath | SFXPath::ToDirectory | SFXPath::AsDirectory


SFXPath::AsFile
Convert a file path into a string.
[ public, const ]
SFXAnsiString AsFile(Void);

Description

If the path is of directory, it will be converted into the path string without " / " at the end.

Example

SFXPath path("/user/admin/log/./../brew/log.txt");
SFXAnsiString str;

// convert file path into string
str = path.AsFile();

// /user/admin/log/./../brew/log.txt
TRACE("%s", str.GetCString());

Reference

SFXPath::AsFilePath | SFXPath::ToFile | SFXPath::AsDirectory


SFXPath::AsFilePath
Convert a path name into a file path.
[ public, const ]
SFXPath AsFilePath(Void);

Description

If the path is of directory, it will be converted into the path string without " / " at the end.

Example

SFXPath path1("dir1/dir2/data.txt");
SFXPath path2;

// convert path name into file path
path2 = path.AsFilePath();  

// dir1/dir2/data.txt
TRACE("%s", path2.Get().GetCString()); 

Reference

SFXPath::AsFile | SFXPath::ToFile | SFXPath::AsDirectoryPath


SFXPath::Clear
Clear the path.
[ public ]
Void Clear(Void);

Example

SFXPath path("/user/admin/brew/a/b/c");
    
...
// clear the path     
path.Clear();    

Reference

SFXPath::EmptyInstance


SFXPath::EmptyInstance
Get the empty path.
[ public, static ]
SFXPathConstRef EmptyInstance(Void);

Description

Get the instance that represents a empty path.

Reference

SFXPath::Clear


SFXPath::Equals
Check whether two paths equal or not.
[ public, const ]
Bool Equals(
    SFXPathConstRef param   // path to compare with
);

Return value

  • If equal : true
  • If not equal : false

Description

What two paths equal means that the object referenced by each path is the same file or directory.

Reference

SFXPath::Normalize | SFXPath::operator== | SFXPath::operator!=


SFXPath::Get
Get the path in a string.
[ public, const ]
SFXAnsiStringConstRef Get(Void);

Example

SFXPath path1("/dir1/data.txt");    
    
TRACE("path = %s", path.Get().GetCString());  // /dir1/data.txt

Reference

SFXPath::GetAbsolute | SFXPath::GetAbsolutePath | SFXPath::GetExtension | SFXPath::GetName | SFXPath::GetParent | SFXPath::GetParentPath | SFXPath::Set


SFXPath::GetAbsolute
Get the absolute path in a string.
[ public, const ]
SFXAnsiString GetAbsolute(Void);

Return value

Return the absolute path string.

Description

If the relative path is set, it will be converted into the absolute path.

Example

SFXPath path("/user/admin/log/./../brew/log.txt");

TRACE("absolute = %s", path.GetAbsolute().GetCString());  //  absolute = fs:/~/user/admin/log/./../brew/log.txt

Reference

SFXPath::IsAbsolute | SFXPath::Get | SFXPath::GetAbsolutePath


SFXPath::GetAbsolutePath
Get the absolute path.
[ public, const ]
SFXPath GetAbsolutePath(Void);

Return value

Return the instance of SFXPath class set with the absolute path.

Description

If the relative path is set, it will be converted into the absolute path.

Example

SFXPath path1("dir1/dir2/data.txt");
SFXPath path2;

// path2 = "/dir1/dir2/data.txt" 
// path1 is the same
path2 = path1.GetAbsolutePath();

Reference

SFXPath::IsAbsolute | SFXPath::Get | SFXPath::GetAbsolute


SFXPath::GetExtension
Get the file extention.
[ public, const ]
SFXAnsiString GetExtension(Void);

Return value

Return the file extention.

If it is a directory or does not have a extention, return the null string.

Example

SFXPath path("/dir1/dir2/data.txt");
SFXAnsiString extension;

// get file extention
extension = path.GetExtension();
TRACE("extension = %s", extension.GetCString()); // extension = txt

Reference

SFXPath::Get | SFXPath::SetExtension


SFXPath::GetName
Get the file or directory name.
[ public, const ]
SFXAnsiString GetName(
    Bool extension = false   // whether to get the name including an extention
);

Example

SFXPath path("/user/admin/log/./../brew/log.txt");
    
TRACE("name = %s", path.GetName().GetCString());  // name = log

Reference

SFXPath::Get | SFXPath::SetName


SFXPath::GetParent
Get the parent directory path in a string.
[ public, const ]
SFXAnsiString GetParent(Void);

Description

If the current path is of file, return the directory path including the file. If the current path is of directory, return the one more upper directory path including the directory.

Example

In case the current path is of file:

SFXPath path("/user/admin/log/./../brew/log.txt");

TRACE("parent = %s", path.GetParent().GetCString()); // parent = /user/admin/log/./../brew/ 

In case the current path is of directory:

SFXPath path("/user/admin/log/./../brew");

TRACE("parent = %s", path.GetParent().GetCString()); // parent = /user/admin/log/./../ 

Reference

SFXPath::Get | SFXPath::GetParentPath


SFXPath::GetParentPath
Get the parent directory path.
[ public, const ]
SFXPath GetParentPath(Void);

Description

If the current path is of file, return the directory path including the file. If the current path is of directory, return the one more upper directory path including the directory.

Example

SFXPath path1("/dir1/dir2/data.txt");
SFXPath path2;
SFXAnsiString string;

// path2 is "/dir1/dir2/"
// path1 is the same
path2 = path1.GetParentPath();

Reference

SFXPath::Get | SFXPath::GetParent


SFXPath::HomeDirectoryPath
Get the home directory path.
[ public, static ]
SFXPath HomeDirectoryPath(Void);

Return value

In the BREW 3.0 / 3.1, return " fs:/~/ ". In the BREW earlier than 3.0, return " / ".

Reference

SFXPath::IsHomeDirectory


SFXPath::IsAbsolute
Check whether the path is an absolute path or not.
[ public, const ]
Bool IsAbsolute(Void);

Return value

  • If absolute path : true
  • If not : false

Reference

SFXPath::GetAbsolute SFXPath::GetAbsolutePath


SFXPath::IsDirectory
Check whether the path is a directory or not.
[ public, const ]
Bool IsDirectory(Void);

Return value

  • If directory : true
  • If file : false

SFXPath::IsHomeDirectory
Check whether the path is a home directory or not.
[ public, const ]
Bool IsHomeDirectory(Void);

Return value

  • If home directory : true
  • If not : false

Description

A home directory is " fs:/~/ " in the BREW 3.0 / 3.1, or " / " in the BREW earlier than 3.0.

The IsHomeDirectory function checks whether the path is " fs:/~/ " or " / " in the BREW 3.0 / 3.1, or is " / " in the BREW earlier than 3.0.

Reference

SFXPath::HomeDirectoryPath


SFXPath::IsRootDirectory
Check whether the path is a root directory or not.
[ public, const ]
Bool IsRootDirectory(Void);

Return value

  • If root directory : true
  • If not : false

Description

A root directory is " fs:/ " in the BREW 3.0 / 3.1, or " / " in the BREW earlier than 3.0.

The IsRootDirectory function checks whether the path is " fs:/ " or " / " in the BREW 3.0 / 3.1, or is " / " in the BREW earlier than 3.0.

Reference

SFXPath::RootDirectoryPath


SFXPath::Normalize
Normalize the path.
[ public, const ]
SFXAnsiString Normalize(Void);

Return value

Return the normalized path as a string.

Description

Normalization is to convert the relative path into the absolute path. For example, " .///a/b//c/./../a///../ " is normalized into " fs:/~/a/b/ " in the BREW 3.1.

Example

SFXPath path1(".///a/b//c/./../a///../ ");
SFXPath path2;

path2 = path1.NormalizePath(); // path2 = "fs:/~/a/b/" 

Reference

SFXPath::NormalizePath


SFXPath::NormalizePath
Get the normalized path.
[ public, const ]
SFXPath NormalizePath(Void);

Return value

Return the normalized path.

Description

Normalization is to convert the relative path into the absolute path. For example, " .///a/b//c/./../a///../ " is normalized into " fs:/~/a/b/ " in the BREW 3.1.

Example

SFXPath path("/user/admin/log/./../brew");

TRACE("normalize = %s", path.Normalize().GetCString());  // normalize = fs:/user/admin/brew

Reference

SFXPath::Normalize


SFXPath::RootDirectoryPath
Get the path of root directory.
[ public, static ]
SFXPath RootDirectoryPath(Void);

Return value

Return the path of root directory.

A root directory is " fs:/ " in the BREW 3.0 / 3.1, or " / " in the BREW earlier than 3.0.

Reference

SFXPath::IsRootDirectory


SFXPath::Set
Set the path.
[ public ]
SFCError Set(
    SFXPathConstRef param   // path to set
);
[ public ]
SFCError Set(
    SFXAnsiStringConstRef param   // path to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMORY

Reference

SFXPath::Get | SFXPath::SetExtension | SFXPath::SetName | SFXPath::operator=


SFXPath::SetExtension
Set the file extention.
[ public ]
SFCError SetExtension(
    SFXAnsiStringConstRef extension   // file extention to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If extention is null : SFERR_INVALID_PARAM
  • If insufficient memory : SFERR_NO_MEMORY

Description

The SetExtension function cannot change the directory name, and remove the extention.

Example

SFXPath path("/dir1/dir2/data.txt");

path.SetExtension("dat");
TRACE("path = %s", path.Get().GetCString());  // path = /dir1/dir2/data.dat

Reference

SFXPath::Set | SFXPath::GetExtension


SFXPath::SetName
Set the file or directory name.
[ public ]
SFCError SetName(
    SFXAnsiStringConstRef name   // name to set
    Bool extension = false       // whether to set the name including an extention or not
);

Return value

  • Success : SFERR_NO_ERROR
  • If name is null : SFERR_INVALID_PARAM
  • If insufficient memory : SFERR_NO_MEMORY

Description

Since the directory has no extention, the extension augument is invalid in case of directory.

Example

SFXPath path("dir1/dir2/");

path.SetName("user");
TRACE("%s", path.Get().GetCString());  // dir1/user/

Reference

SFXPath::Set | SFXPath::GetName


SFXPath::ToDirectory
Interpret the current path as directory.
[ public ]
Void ToDirectory(Void);

Description

If the path is of file, it can be precessed as directory by appending " / " at the end.

Reference

SFXPath::ToFile | SFXPath::AsDirectory | SFXPath::AsDirectoryPath


SFXPath::ToFile
Interpret the current path as file.
[ public ]
Void ToFile(Void);

Description

If the path is of directory, it can be precessed as file by removing " / " at the end.

Reference

SFXPath::ToDirectory | SFXPath::AsFile | SFXPath::AsFilePath


SFXPath::operator=
Substitute the path.
[ public ]
SFXPathRef operator=(
    SFXPathConstRef param   // path to copy
);

Reference

SFXPath::SFXPath | SFXPath::Set


SFXPath::operator==
Check the relation of " == ".
[ public, friend ]
Bool operator==(
    SFXPathConstRef left    // path to compare
    SFXPathConstRef right   // path to compare
);

Return value

  • If equal : true
  • If not : false

Description

What two paths equal means that the object referenced by each path is the same file or directory. Inside this function, the path strings normalized by using the SFXPath::Normalize function are compared.

Reference

SFXPath::Equals | SFXPath::Normalize | SFXPath::operator!=


SFXPath::operator!=
Check the relation of " != ".
[ public, friend ]
Bool operator!=(
    SFXPathConstRef left    // path to compare
    SFXPathConstRef right   // path to compare
);

Return value

  • If not equal : true
  • If equal : false

Description

What two paths equal means that the object referenced by each path is the same file or directory. Inside this function, the path strings normalized by using the SFXPath::Normalize function are compared.

Reference

SFXPath::Equals | SFXPath::Normalize | SFXPath::operator==