PrevNextUpHome SophiaFramework UNIVERSE 5.3
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

The SFXPath class is used to get a parent directory, convert a relative path into a absolute one, or set a file name or suffix.

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

Reference

SFXFile | SFXDirectory | File Path

Member

Constructor/Destructor
SFXPath( Void )
Constructor of the SFXPath class.
SFXPath( SFXPathConstRef param )
Constructor of the SFXPath class.
SFXPath( SFXAnsiStringConstRef param )
Constructor of the SFXPath class.
Public Functions
SFXAnsiString AsDirectory( Void )
Get this path as the directory path of the SFXAnsiString type.
SFXPath AsDirectoryPath( Void )
Get this path as the directory path of the SFXPath type.
SFXAnsiString AsFile( Void )
Get this path as the file path of the SFXAnsiString type.
SFXPath AsFilePath( Void )
Get this path as the file path of the SFXPath type.
Void Clear( Void )
Clear this path.
static
SFXPathConstRef
EmptyInstance( Void )
Get the empty path.
Bool Equals( SFXPathConstRef param )
Check whether or not this path equals the specified one.
SFXAnsiStringConstRef Get( Void )
Get this path of the SFXAnsiString type.
SFXAnsiString GetAbsolute( Void )
Get the absolute path of this path of the SFXAnsiString type.
SFXPath GetAbsolutePath( Void )
Get the absolute path of this path of the SFXPath type.
SFXAnsiString GetExtension( Void )
Get the file extention of this path.
SFXAnsiString GetName( Bool extension = false )
Get the file or directory name of this path.
SFXAnsiString GetParent( Void )
Get the parent directory path of this path of the SFXAnsiString type.
SFXPath GetParentPath( Void )
Get the parent directory path of this path of the SFXPath type.
static
SFXPath
HomeDirectoryPath( Void )
Get the home directory path.
Bool IsAbsolute( Void )
Check whether or not this path is an absolute one.
Bool IsDirectory( Void )
Check whether or not this path is a directory one.
Bool IsHomeDirectory( Void )
Check whether or not this path is a home directory one.
Bool IsRootDirectory( Void )
Check whether or not this path is a root directory one.
SFXAnsiString Normalize( Void )
Get the path of the SFXAnsiString type into which this path is normalized.
SFXPath NormalizePath( Void )
Get the path of the SFXPath type into which this path is normalized.
static
SFXPath
RootDirectoryPath( Void )
Get the root directory path.
SFCError Set( SFXPathConstRef param )
Set the path.
SFCError Set( SFXAnsiStringConstRef param )
Set the path.
SFCError SetExtension( SFXAnsiStringConstRef extension )
Set the file extention of this path.
SFCError SetName( SFXAnsiStringConstRef name , Bool extension = false )
Set the file or directory name of this path.
Void ToDirectory( Void )
Convert this path into the directory one.
Void ToFile( Void )
Convert this path into the file one.
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 the SFXPath class.
[ public, explicit ]
SFXPath(Void);
[ public ]
SFXPath(
    SFXPathConstRef param   // path to set
);
[ public, explicit ]
SFXPath(
    SFXAnsiStringConstRef param   // path to set
);

Description

In this constructor, this path can be set to the value specified in the path argument.

Reference

SFXPath::Set | SFXPath::operator=


SFXPath::AsDirectory
Get this path as the directory path of the SFXAnsiString type.
[ public, const ]
SFXAnsiString AsDirectory(Void);

Return value

Directory path of the SFXAnsiString type.

Description

This function gets this path as the directory path of the SFXAnsiString type.

The directory path of the SFXAnsiString type will be generated internally as follows:

  1. Convert this path into the string of the SFXAnsiString type.
  2. If the character at the end of the string is '/', this path is the directory one.
  3. Otherwise, append the '/' character to this path. And the result is the directory path.
[Note] Directory path

The directory path is the one that has the '/' character at the end.

Example

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

// get this path as the directory path of the SFXAnsiString type
str = path.AsDirectory();  
TRACE("%s", str.GetCString()); // /user/admin/brew/a/b/c/

Reference

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


SFXPath::AsDirectoryPath
Get this path as the directory path of the SFXPath type.
[ public, const ]
SFXPath AsDirectoryPath(Void);

Return value

Directory path of the SFXPath type.

Description

This function gets this path as the directory path of the SFXPath type.

The directory path of the SFXPath type will be generated internally as follows:

  1. If the character at the end of this path is '/', this path is the directory one.
  2. Otherwise, append the '/' character to this path. And the result is the directory path.
[Note] Directory path

The directory path is the one that has the '/' character at the end.

Example

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

// get this path as the directory path
path2 = path.AsDirectoryPath();  
TRACE("%s", path2.Get().GetCString()); // /user/admin/brew/a/b/c/

Reference

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


SFXPath::AsFile
Get this path as the file path of the SFXAnsiString type.
[ public, const ]
SFXAnsiString AsFile(Void);

Return value

File path of the SFXAnsiString type.

Description

This function gets this path as the file path of the SFXAnsiString type.

The file path of the SFXAnsiString type will be generated internally as follows:

  1. Convert this path into the string of the SFXAnsiString type.
  2. If the character at the end of the string is not '/', it is the file path.
  3. Otherwise, the '/' character at the end will be removed. And the result is the file path.
[Note] File path

The file path is the one that has any character except '/' at the end.

Example

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

// get this path as the file path of the SFXAnsiString type
str = path.AsFile();
TRACE("%s", str.GetCString()); // /user/admin/log/./../brew/log.txt

Reference

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


SFXPath::AsFilePath
Get this path as the file path of the SFXPath type.
[ public, const ]
SFXPath AsFilePath(Void);

Return value

File path of the SFXPath type.

Description

This function gets this path as the file path of the SFXPath type.

The file path of the SFXPath type will be generated internally as follows:

  1. If the character at the end of the string is not '/', it is the file path.
  2. Otherwise, the '/' character at the end will be removed. And the result is the file path.
[Note] File path

The file path is the one that has any character except '/' at the end.

Example

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

// get this path as the file path of the SFXPath type
path2 = path.AsFilePath();  
TRACE("%s", path2.Get().GetCString()); // dir1/dir2/data.txt

Reference

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


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

Description

This function clears this path.

[Note] Note

After cleared, this path is same as the return value of the SFXPath::EmptyInstance function.

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

This function gets the instance that represents an empty path.

Reference

SFXPath::Clear


SFXPath::Equals
Check whether or not this path equals the specified one.
[ public, const ]
Bool Equals(
    SFXPathConstRef param   // path to compare with
);

Return value

  • If yes: true
  • Otherwise: false

Description

This function checks whether or not this path equals the specified one, i.e., this path refers to the same object as the specified one.

[Note] Note

This function internally executes the SFXPath::Normalize function to compare both of the result strings.

Reference

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


SFXPath::Get
Get this path of the SFXAnsiString type.
[ public, const ]
SFXAnsiStringConstRef Get(Void);

Return value

This path of the SFXAnsiString type.

Description

This function gets this path of the SFXAnsiString type.

Example

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

Reference

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


SFXPath::GetAbsolute
Get the absolute path of this path of the SFXAnsiString type.
[ public, const ]
SFXAnsiString GetAbsolute(Void);

Return value

Absolute path of this path of the SFXAnsiString type.

Description

This function gets the absolute path of this path of the SFXAnsiString type.

[Note] Note

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 | SFXAnsiString


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

Return value

Absolute path of this path of the SFXPath type.

Description

This function gets the absolute path of this path of the SFXPath type.

[Note] Note

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


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

Return value

File extention of this path

If this path is a directory or does not have any extention, the null string will be returned.

Description

This function gets the file extention of this path.

[Note] Note

If this path is a directory or does not have any extention, the null string will be returned.

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 of this path.
[ public, const ]
SFXAnsiString GetName(
    Bool extension = false   // whether or not to get the name including its extention
);

Return value

File or directory name of this path.

Description

This function gets the file or directory name of this path.

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 of this path of the SFXAnsiString type.
[ public, const ]
SFXAnsiString GetParent(Void);

Return value

Parent directory path of this path of the SFXAnsiString type.

Description

This function gets the parent directory path of this path of the SFXAnsiString type.

If the current path is of a file, the directory path including the file will be returned. Otherwise, i.e., it is of a directory, the one more upper directory path including the directory will be returned.

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 | SFXAnsiString


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

Return value

Parent directory path of this path of the SFXPath type.

Description

This function gets the parent directory path of this path of the SFXPath type.

If the current path is of a file, the directory path including the file will be returned. Otherwise, i.e., it is of a directory, the one more upper directory path including the directory will be returned.

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


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

Return value

  • BREW 3.1 or above: "fs:/~/"
  • BREW 2.1 or below: "/"

Description

This function gets the home directory path.

[Note] Home directory path

In BREW 3.1 or above, the home directory path is "fs:/~/".

In BREW 2.1 or below, it is "/".

Reference

SFXPath::IsHomeDirectory


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

Return value

  • If this path is an absolute one: true
  • Otherwise: false

Description

This function checks whether or not this path is an absolute one.

Reference

SFXPath::GetAbsolute SFXPath::GetAbsolutePath


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

Return value

  • If this path is a directory one: true
  • Otherwise: false

Description

This function checks whether or not this path is a directory one.

[Note] Directory path

The directory path is the one that has the '/' character at the end.

Reference

SFXPath::ToDirectory | SFXPath::AsDirectory


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

Return value

  • If this path is a home directory one: true
  • Otherwise: false

Description

This function checks whether or not this path is a home directory one.

[Note] Home directory path

In BREW 3.1 or above, the home directory path is "fs:/~/".

In BREW 2.1 or below, it is "/".

Reference

SFXPath::HomeDirectoryPath


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

Return value

  • If this path is a root directory one: true
  • Otherwise: false

Description

This function checks whether or not this path is a root directory one.

[Note] Root directory path

In BREW 3.1 or above, the root directory path is "fs:/".

In BREW 2.1 or below, it is "/".

Reference

SFXPath::RootDirectoryPath


SFXPath::Normalize
Get the path of the SFXAnsiString type into which this path is normalized.
[ public, const ]
SFXAnsiString Normalize(Void);

Return value

Path of the SFXAnsiString type into which this path is normalized.

Description

This function gets the path of the SFXAnsiString type into which this path is normalized.

[Note] Normalization

Normalization is to convert the relative path into the absolute one.

For instance, ".///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::NormalizePath | SFXAnsiString


SFXPath::NormalizePath
Get the path of the SFXPath type into which this path is normalized.
[ public, const ]
SFXPath NormalizePath(Void);

Return value

Path of the SFXPath type into which this path is normalized.

Description

This function gets the path of the SFXPath type into which this path is normalized.

[Note] Normalization

Normalization is to convert the relative path into the absolute one.

For instance, ".///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::Normalize | SFXPath


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

Return value

  • In BREW 3.1 or above: "fs:/"
  • In BREW 2.1 or below: "/"

Description

This function gets the root directory path.

[Note] Root directory path

In BREW 3.1 or above, the root directory path is "fs:/".

In BREW 2.1 or below, it is "/".

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

  • If succeeds: SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function sets the path.

Reference

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


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

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the extention argument is null: SFERR_INVALID_PARAM
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function sets the file extention of this path.

[Note] Note

This function cannot change the directory or file name of this path nor remove the extention from this path.

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 of this path.
[ public ]
SFCError SetName(
    SFXAnsiStringConstRef name   // name to set
    Bool extension = false       // whether or not to set the name including an extention
);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If the name argument is null: SFERR_INVALID_PARAM
  • If insufficient memory: SFERR_NO_MEMORY

Description

This function sets the file or directory name of this path.

[Note] Note

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

Example

SFXPath path("dir1/dir2/");

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

Reference

SFXPath::Set | SFXPath::GetName


SFXPath::ToDirectory
Convert this path into the directory one.
[ public ]
Void ToDirectory(Void);

Description

This function converts this path into the directory one.

This path will be converted into the directory one as follows:

  1. If the character at the end of this path is '/', this path is the directory one. Therefore, nothing will happen.
  2. Otherwise, the '/' character will be appended to this path. Then this path will become the directory one.
[Note] Directory path

The directory path is the one that has the '/' character at the end.

Reference

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


SFXPath::ToFile
Convert this path into the file one.
[ public ]
Void ToFile(Void);

Description

This function converts this path into the file one.

This path will be converted into the file one as follows:

  1. If the character at the end of this path is not '/', this path is the file one. Therefore, nothing will happen.
  2. Otherwise, the '/' character at the end will be removed from this path. Then this path will become the file one.
[Note] File path

The file path is the one that has any character except '/' 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
  • Otherwise: false

Description

This operator checks whether or not the path of the left side equals that of the right side, i.e., both refer to the same file or directory.

For the paths of the both sides, if the return values of the SFXPath::Normalize function are the same, true will be returned. Otherwise, false will be returned.

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
  • Otherwise false

Description

This operator checks whether or not the path of the left side equals that of the right side, i.e., both refer to the differnt file or directory.

For the paths of the both sides, if the return values of the SFXPath::Normalize function are not the same, true will be returned. Otherwise, false will be returned.

Reference

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