clan::PathHelp Class Reference - ClanLib SDK
Description: clan::PathHelp Class Reference

Public Types | Static Public Member Functions | List of all members
clan::PathHelp Class Reference
clanCore I/O Data

Path helper functions. More...

`#include <path_help.h>`

## Public Types
enum | PathType { path_type_file , path_type_virtual }
| Path types. More...

## Static Public Member Functions
static std::string | add_trailing_slash (const std::string &path, PathType path_type=path_type_file)
| Add trailing slash or backslash to path.
static std::string | combine (const std::string &part1, const std::string &part2, PathType path_type=path_type_file)
| Concatenates two strings into one adding a trailing slash to first string if missing.
static std::string | get_basename (const std::string &fullname, PathType path_type=path_type_file)
| Returns the basename part of a fullname.
static std::string | get_basepath (const std::string &fullname, PathType path_type=path_type_file)
| Returns the path excluding the location and filename.
static std::string | get_extension (const std::string &fullname, PathType path_type=path_type_file)
| Returns the extension part of a fullname.
static std::string | get_filename (const std::string &fullname, PathType path_type=path_type_file)
| Returns the filename part of a fullname.
static std::string | get_fullname (const std::string &fullpath, const std::string &filename, const std::string &extension, PathType path_type=path_type_file)
| Create a fullname from parts.
static std::string | get_fullname (const std::string &fullpath, const std::string &filename, PathType path_type=path_type_file)
| Create a fullname from parts.
static std::string | get_fullname (const std::string &location, const std::string &basepath, const std::string &filename, const std::string &extension, PathType path_type=path_type_file)
| Create a fullname from parts.
static std::string | get_fullpath (const std::string &fullname, PathType path_type=path_type_file)
| Returns the path including the location.
static std::string | get_location (const std::string &fullname, PathType path_type=path_type_file)
| Returns the drive (C:) or share name ( \ \ computer \ share)
static bool | is_absolute (const std::string &path, PathType path_type=path_type_file)
| Check if a path is absolute.
static bool | is_relative (const std::string &path, PathType path_type=path_type_file)
| Check if a path is relative.
static std::string | make_absolute (const std::string &base_path, const std::string &relative_path, PathType path_type=path_type_file)
| Convert a relative path to an absolute path.
static std::string | make_relative (const std::string &base_path, const std::string &absolute_path, PathType path_type=path_type_file)
| Converts an absolute path into a path relative to a base path.
static std::string | normalize (const std::string &path, PathType path_type=path_type_file)
| Normalize a path.
static std::string | remove_trailing_slash (const std::string &path)
| Remove trailing slash or backslash from path.
static std::vector< std::string > | split_basepath (const std::string &fullname, PathType path_type=path_type_file)
| Splits the path, excluding the location, into parts.

## Detailed Description

Path helper functions.

## Member Enumeration Documentation

## ◆ PathType

enum clan::PathHelp::PathType

Path types.

Enumerator
path_type_file | Native file system path. (On windows, '/' are turned into '\'. On linux, '\' are turned into '/')
path_type_virtual | Path using slashes ('/').

## Member Function Documentation

## ◆ add_trailing_slash()

std::string clan::PathHelp::add_trailing_slash | ( | const std::string & | path,
|  | PathType | path_type = path_type_file )
| static

Add trailing slash or backslash to path.

This function checks if a path already has a trailing slash/backslash and adds it if its missing.

Parameters

  path | The path to use
  path_type | The path type (of path)

Returns
  The converted path

References clan::path, and path_type_file.

## ◆ combine()

std::string clan::PathHelp::combine | ( | const std::string & | part1,
|  | const std::string & | part2,
|  | PathType | path_type = path_type_file )
| static

Concatenates two strings into one adding a trailing slash to first string if missing.

Parameters

  part1 | First part of path
  part2 | Second part of path
  path_type | The path type (of path)

References path_type_file.

## ◆ get_basename()

std::string clan::PathHelp::get_basename | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Returns the basename part of a fullname.

param: fullname = The full path to use param: path_type = The path type

Returns
  The filename (excluding the extension)

References path_type_file.

## ◆ get_basepath()

std::string clan::PathHelp::get_basepath | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Returns the path excluding the location and filename.

Parameters

  fullname | The full path name to use
  path_type | The path type

Returns
  The base path

If (path_type == path_type_virtual) or not using windows, then this function returns the path (excluding filename)

References path_type_file.

## ◆ get_extension()

std::string clan::PathHelp::get_extension | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Returns the extension part of a fullname.

If no extension was found, an empty string is returned.

param: fullname = The full path to use param: path_type = The path type

Returns
  The extension

References path_type_file.

## ◆ get_filename()

std::string clan::PathHelp::get_filename | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Returns the filename part of a fullname.

param: fullname = The full path to use param: path_type = The path type

Returns
  The filename

References path_type_file.

## ◆ get_fullname() [1/3]

std::string clan::PathHelp::get_fullname | ( | const std::string & | fullpath,
|  | const std::string & | filename,
|  | const std::string & | extension,
|  | PathType | path_type = path_type_file )
| static

Create a fullname from parts.

param: fullpath = The full path to use param: filename = The filename to use param: extension = The filename extension to use param: path_type = The path type

Returns
  The full name

References path_type_file.

## ◆ get_fullname() [2/3]

std::string clan::PathHelp::get_fullname | ( | const std::string & | fullpath,
|  | const std::string & | filename,
|  | PathType | path_type = path_type_file )
| static

Create a fullname from parts.

param: fullpath = The full path to use param: filename = The filename to use param: path_type = The path type

Returns
  The full name

References path_type_file.

## ◆ get_fullname() [3/3]

std::string clan::PathHelp::get_fullname | ( | const std::string & | location,
|  | const std::string & | basepath,
|  | const std::string & | filename,
|  | const std::string & | extension,
|  | PathType | path_type = path_type_file )
| static

Create a fullname from parts.

param: location = The location to use param: fullpath = The full path to use param: filename = The filename to use param: extension = The filename extension to use param: path_type = The path type

Returns
  The full name

References path_type_file.

## ◆ get_fullpath()

std::string clan::PathHelp::get_fullpath | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Returns the path including the location.

param: fullname = The full path to use (including filename) param: path_type = The path type

Returns
  The full path including the location (excluding filename)

References path_type_file.

## ◆ get_location()

std::string clan::PathHelp::get_location | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Returns the drive (C:) or share name ( \ \ computer \ share)

If (path_type == path_type_virtual) or not using windows, then this function always returns an empty string.

Parameters

  fullname | The full path name to use
  path_type | The path type

Returns
  The drive or share name*‍/

References path_type_file.

## ◆ is_absolute()

bool clan::PathHelp::is_absolute | ( | const std::string & | path,
|  | PathType | path_type = path_type_file )
| static

Check if a path is absolute.

Parameters

  path | The path to check
  path_type | The path type (of path)

Returns
  true if path is absolute

References clan::path, and path_type_file.

## ◆ is_relative()

bool clan::PathHelp::is_relative | ( | const std::string & | path,
|  | PathType | path_type = path_type_file )
| static

Check if a path is relative.

Parameters

  path | The path to check
  path_type | The path type (of path)

Returns
  true if path is relative

References clan::path, and path_type_file.

## ◆ make_absolute()

std::string clan::PathHelp::make_absolute | ( | const std::string & | base_path,
|  | const std::string & | relative_path,
|  | PathType | path_type = path_type_file )
| static

Convert a relative path to an absolute path.

Parameters

  base_path | The base path (Does not require a trailing slash)
  relative_path | The relative path
  path_type | The path type

Returns
  The converted path

This function behaves differently depending on OS and path_type. In Windows, if the relative_path begins with a drive letter, and the driver letter differs from the base path, the path is converted to an absolute path using the current directory for that drive. Likewise, if the specified base path does not include a drive or its path is not absolute, the current drive and directory is added. The function converts all slashes to backslashes.

If the OS is unix based, there is no location (drive or share name) and the function also converts all backslashes to slashes.

If the type is path_type_virtual, the base path is required to be absolute. If it does not start in a slash, the function prefixes a slash to the path. The current drive or directory is never taken into account and all backslashes are converted to slashes.

This function calls normalise() on base_path and relative_path.

Example #1:

std::string str = PathHelp::make_absolute("ABD/DEF/", "GFX/Filename.txt", PathHelp::path_type_file);
On Linux: str = "/home/user/ABD/DEF/GFX/Filename.txt"
On Windows: str = "c:\user\ABD\DEF\GFX\Filename.txt"
clan::PathHelp::make_absolute
static std::string make_absolute(const std::string &base_path, const std::string &relative_path, PathType path_type=path_type_file)
Convert a relative path to an absolute path.
clan::PathHelp::path_type_file
@ path_type_file
Native file system path. (On windows, '/' are turned into '\'. On linux, '\' are turned into '/')
Definition path_help.h:46

Example #2:

std::string str = PathHelp::make_absolute("/ABD/DEF/", "../Filename.txt", PathHelp::path_type_file);
On Linux: str = "/ABD/Filename.txt"
On Windows: str = "c:\ABD\Filename.txt"

Example #3:

std::string str = PathHelp::make_absolute("/ABD/DEF/", "../Filename.txt", PathHelp::path_type_virtual);
On Linux: str = "/ABD/Filename.txt"
On Windows: str = "/ABD/Filename.txt"
clan::PathHelp::path_type_virtual
@ path_type_virtual
Path using slashes ('/').
Definition path_help.h:49

References path_type_file.

## ◆ make_relative()

std::string clan::PathHelp::make_relative | ( | const std::string & | base_path,
|  | const std::string & | absolute_path,
|  | PathType | path_type = path_type_file )
| static

Converts an absolute path into a path relative to a base path.

Parameters

  base_path | The base path (Does not require a trailing slash)
  absolute_path | The absolute path
  path_type | The path type

Returns
  The converted path

This function is the inverse of FileHelp::make_absolute. Please see the detailed information for make_absolute for more information about behavior.

This function calls normalise() on the base_path and absolute_path-

Example #1 (Windows):

std::string str = PathHelp::make_relative("ABD/DEF/", "c:\user\ABD\Filename.txt", PathHelp::path_type_file);
On Windows: str = "..\Filename.txt"
clan::PathHelp::make_relative
static std::string make_relative(const std::string &base_path, const std::string &absolute_path, PathType path_type=path_type_file)
Converts an absolute path into a path relative to a base path.

References path_type_file.

## ◆ normalize()

std::string clan::PathHelp::normalize | ( | const std::string & | path,
|  | PathType | path_type = path_type_file )
| static

Normalize a path.

Parameters

  path | The path to use
  path_type | The path type (of the normalized path)

Returns
  The converted path

Converts all slashes and backslashes into their right type. Simplifies or removes all . and .., converting the path into its most readable form.

References clan::path, and path_type_file.

## ◆ remove_trailing_slash()

std::string clan::PathHelp::remove_trailing_slash | ( | const std::string & | path | ) |
| static

Remove trailing slash or backslash from path.

This function checks if a path has a trailing slash/backslash and removes it if needed.

Parameters

  path | The path to use

Returns
  The converted path

References clan::path.

## ◆ split_basepath()

std::vector< std::string > clan::PathHelp::split_basepath | ( | const std::string & | fullname,
|  | PathType | path_type = path_type_file )
| static

Splits the path, excluding the location, into parts.

param: fullname = The full path name to use param: path_type = The path type

Returns
  The split path

References path_type_file.

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

- path_help.h