Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::IO::BasicPath< StringType > Class Template Reference

Public Types

using string_type = StringType
 
using value_type = typename StringType::value_type
 
using traits_type = typename StringType::traits_type
 
using string_view_type = AZStd::string_view
 
using const_iterator = PathIterator< const BasicPath >
 
using iterator = const_iterator
 

Public Member Functions

constexpr BasicPath (const BasicPath &other)=default
 
constexpr BasicPath (BasicPath &&other)=default
 
constexpr BasicPath (const PathView &other) noexcept
 
constexpr BasicPath (const string_type &pathString) noexcept
 
constexpr BasicPath (const string_type &pathString, const char preferredSeparator) noexcept
 
constexpr BasicPath (string_type &&pathString) noexcept
 
constexpr BasicPath (string_type &&pathString, const char preferredSeparator) noexcept
 
constexpr BasicPath (AZStd::string_view src) noexcept
 
constexpr BasicPath (AZStd::string_view src, const char preferredSeparator) noexcept
 
constexpr BasicPath (const value_type *pathString) noexcept
 
constexpr BasicPath (const value_type *pathString, const char preferredSeparator) noexcept
 
constexpr BasicPath (const char preferredSeparator) noexcept
 Constructs a empty Path with the preferred separator set to the parameter.
 
template<typename InputIt >
constexpr BasicPath (InputIt first, InputIt last)
 
template<typename InputIt >
constexpr BasicPath (InputIt first, InputIt last, const char preferredSeparator)
 
constexpr operator PathView () const noexcept
 
constexpr BasicPathoperator= (const BasicPath &other)=default
 
constexpr BasicPathoperator= (BasicPath &&other)=default
 
constexpr BasicPathoperator= (const PathView &pathView) noexcept
 
constexpr BasicPathoperator= (const string_type &str) noexcept
 
constexpr BasicPathoperator= (string_type &&str) noexcept
 
constexpr BasicPathoperator= (AZStd::string_view str) noexcept
 
constexpr BasicPathoperator= (const value_type *src) noexcept
 
constexpr BasicPathoperator= (value_type src) noexcept
 
constexpr BasicPathAssign (const PathView &pathView) noexcept
 
constexpr BasicPathAssign (const string_type &pathView) noexcept
 
constexpr BasicPathAssign (string_type &&pathView) noexcept
 
constexpr BasicPathAssign (AZStd::string_view pathView) noexcept
 
constexpr BasicPathAssign (const value_type *src) noexcept
 
constexpr BasicPathAssign (value_type src) noexcept
 
template<typename InputIt >
constexpr BasicPathAssign (InputIt first, InputIt last)
 
constexpr BasicPathoperator/= (const PathView &other)
 
constexpr BasicPathoperator/= (const string_type &src)
 
constexpr BasicPathoperator/= (AZStd::string_view src)
 
constexpr BasicPathoperator/= (const value_type *src)
 
constexpr BasicPathoperator/= (value_type src)
 
constexpr BasicPathAppend (const PathView &src)
 Sames as the operator/= functions above.
 
constexpr BasicPathAppend (const string_type &pathView)
 
constexpr BasicPathAppend (AZStd::string_view src)
 
constexpr BasicPathAppend (const value_type *src)
 
constexpr BasicPathAppend (value_type src)
 
template<typename InputIt >
constexpr BasicPathAppend (InputIt first, InputIt last)
 
constexpr void clear () noexcept
 Invokes clean on the underlying path string type.
 
constexpr BasicPathMakePreferred ()
 Replaces all path separators with the preferred separator value.
 
constexpr BasicPathRemoveFilename ()
 
constexpr BasicPathReplaceFilename (const PathView &replacementFilename)
 
constexpr BasicPathReplaceExtension (const PathView &replacementExtension={})
 
constexpr void swap (BasicPath &rhs) noexcept
 
constexpr const string_type & Native () const &noexcept
 
constexpr const string_type && Native () const &&noexcept
 
constexpr const value_type * c_str () const noexcept
 
constexpr operator string_type () const
 
constexpr string_type & Native () &noexcept
 
constexpr string_type && Native () &&noexcept
 
AZStd::string String () const
 
constexpr AZStd::fixed_string< MaxPathLengthFixedMaxPathString () const
 
constexpr string_type AsPosix () const
 
AZStd::string StringAsPosix () const
 
constexpr AZStd::fixed_string< MaxPathLengthFixedMaxPathStringAsPosix () const noexcept
 
string_type AsUri () const
 
AZStd::string StringAsUri () const
 
AZStd::fixed_string< MaxPathLengthFixedMaxPathStringAsUri () const noexcept
 
constexpr int Compare (const PathView &other) const noexcept
 
constexpr int Compare (const string_type &pathString) const
 
constexpr int Compare (AZStd::string_view pathString) const noexcept
 
constexpr int Compare (const value_type *pathString) const noexcept
 
constexpr PathView RootName () const
 
constexpr PathView RootDirectory () const
 
constexpr PathView RootPath () const
 
constexpr PathView RelativePath () const
 
constexpr PathView ParentPath () const
 
constexpr PathView Filename () const
 
constexpr PathView Stem () const
 
constexpr PathView Extension () const
 
constexpr bool empty () const noexcept
 Checks if the contained string type element is empty.
 
constexpr bool HasRootName () const
 
constexpr bool HasRootDirectory () const
 Checks if the path has a root directory.
 
constexpr bool HasRootPath () const
 
constexpr bool HasRelativePath () const
 
constexpr bool HasParentPath () const
 checks whether the path has a parent path that empty
 
constexpr bool HasFilename () const
 Checks whether the filename is empty.
 
constexpr bool HasStem () const
 Checks whether the stem of the filename is empty <stem>[.<ext>].
 
constexpr bool HasExtension () const
 Checks whether the extension of the filename is empty <stem>[.<ext>].
 
constexpr bool IsAbsolute () const
 
constexpr bool IsRelative () const
 Check whether the path is not absolute.
 
constexpr bool IsRelativeTo (const PathView &base) const
 Check whether the path is relative to the base path.
 
constexpr const char PreferredSeparator () const noexcept
 Returns the preferred separator for this instance.
 
constexpr BasicPath LexicallyNormal () const
 
constexpr BasicPath LexicallyRelative (const PathView &base) const
 
constexpr BasicPath LexicallyProximate (const PathView &base) const
 Returns the lexically relative path if it is not an empty path, otherwise it returns the current *this path.
 
constexpr bool Match (AZStd::string_view pathPattern) const
 See PathView::Match for documentation on how to use.
 
constexpr const_iterator begin () const
 
constexpr const_iterator end () const
 
template<typename InputIt >
constexpr auto Assign (InputIt first, InputIt last) -> BasicPath &
 
template<typename InputIt >
constexpr auto Append (InputIt first, InputIt last) -> BasicPath &
 

Public Attributes

friend const_iterator
 

Friends

class PathView
 

Constructor & Destructor Documentation

◆ BasicPath() [1/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( const string_type &  pathString)
constexprnoexcept

Constructs a Path by copying the pathString to its internal string The preferred separator is to the OS default path separator

◆ BasicPath() [2/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( const string_type &  pathString,
const char  preferredSeparator 
)
constexprnoexcept

Constructs a Path by copying the pathString to its internal string The preferred separator is set to the parameter

◆ BasicPath() [3/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( string_type &&  pathString)
constexprnoexcept

Constructs a Path by moving the pathString to its internal string The preferred separator is to the OS default path separator

◆ BasicPath() [4/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( string_type &&  pathString,
const char  preferredSeparator 
)
constexprnoexcept

Constructs a Path by copying the pathString to its internal string The preferred separator is set to the parameter

◆ BasicPath() [5/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( AZStd::string_view  src)
constexprnoexcept

Constructs a Path by constructing it's internal out of a string_view The preferred separator is to the OS default path separator

◆ BasicPath() [6/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( AZStd::string_view  src,
const char  preferredSeparator 
)
constexprnoexcept

Constructs a Path by constructing it's internal out of a string_view The preferred separator is set to the parameter

◆ BasicPath() [7/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( const value_type *  pathString)
constexprnoexcept

Constructs a Path by constructing it's internal out of a value_type* The preferred separator is to the OS default path separator

◆ BasicPath() [8/8]

template<typename StringType >
constexpr AZ::IO::BasicPath< StringType >::BasicPath ( const value_type *  pathString,
const char  preferredSeparator 
)
constexprnoexcept

Constructs a Path by constructing it's internal out of a value_type* The preferred separator is set to the parameter

Member Function Documentation

◆ AsPosix()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::AsPosix
constexpr

Replicates the behavior of the Python pathlib as_posix method by replacing the Windows Path Separator with the Posix Path Separator

◆ Assign()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::Assign ( const PathView pathView)
constexprnoexcept

Replaces the contents of the path using the character sequence from the supplied parameters. No special conversions take place. It is either a string copy or move

◆ AsUri()

template<typename StringType >
string_type AZ::IO::BasicPath< StringType >::AsUri ( ) const

Models the Python pathlib as_uri method Percent encodes the path and appends file: to the front

◆ begin()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::begin
constexpr

Returns an iterator to the beginning of the path that can be used to traverse the path according to the following

  1. Root name - (0 or 1)
  2. Root directory - (0 or 1)
  3. Filename - (0 or more)

◆ Compare()

template<typename StringType >
constexpr int AZ::IO::BasicPath< StringType >::Compare ( const PathView other) const
constexprnoexcept

Performs a compare of each of the path parts for equivalence Each part of the path is compare using string comparison If both *this path and the input path uses the WindowsPathSeparator then a non-case sensitive compare is performed Ex: Comparing "test/foo" against "test/fop" returns -1; Path separators of the contained path string aren't compared Ex. Comparing "C:/test\foo" against C:

◆ end()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::end
constexpr

Returns an iterator to the end of the path element This iterator can be safely decremented to point to the last valid path element if it is not equal to the begin iterator

◆ Extension()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::Extension
constexpr

Returns the extension of the filename (or equivalently, the filename of the path with the stem stripped) windows = ".txt", posix = ".txt" NOTE: If the filename is the special "." or ".." path then their is no extension in that case

◆ Filename()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::Filename
constexpr

Returns the filename of the path windows = "name.txt", posix = "name.txt"

◆ FixedMaxPathString()

template<typename StringType >
constexpr AZStd::fixed_string< MaxPathLength > AZ::IO::BasicPath< StringType >::FixedMaxPathString
constexpr

extension: fixed string types with MaxPathLength capacity Returns a new instance of an AZStd::fixed_string with capacity of MaxPathLength made from the internal string

◆ HasRelativePath()

template<typename StringType >
constexpr bool AZ::IO::BasicPath< StringType >::HasRelativePath
constexpr

checks whether the relative part of path is empty (C:\ O3DE\dev) ^ ^ root part relative part

◆ HasRootName()

template<typename StringType >
constexpr bool AZ::IO::BasicPath< StringType >::HasRootName
constexpr

Checks if the path has a root name For posix paths this is always empty For windows paths this is the part of the path before the either the root directory or relative path part

◆ HasRootPath()

template<typename StringType >
constexpr bool AZ::IO::BasicPath< StringType >::HasRootPath
constexpr

Checks whether the entire root path portion of the path is empty The root portion of the path is made up of root_name() / root_directory()

◆ IsAbsolute()

template<typename StringType >
constexpr bool AZ::IO::BasicPath< StringType >::IsAbsolute
constexpr

Checks whether the contained path represents an absolute path If a path starts with a '/', "<drive letter>:\", "\<network_name>", "\\?\", "\??" or "\\.\"

◆ LexicallyNormal()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::LexicallyNormal
constexpr

Normalizes a path in a purely lexical manner.

Path separators are converted to their preferred path separator

Path parts of "." are collapsed to nothing empty

Paths parts of ".." are removed if there is a preceding directory

The preceding directory is also removed

Runs of Two or more path separators are collapsed into one path separator

unless the path begins with two path separators

Finally any trailing path separators are removed

◆ LexicallyRelative()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::LexicallyRelative ( const PathView base) const
constexpr

Make the path relative to the supplied base PathView, by using the following rules.

If root_name() != base.root_name() is true, return a default constructed path

(Path can't relative if the root_names are different i.e C: vs F:)

If is_absolute() != base.is_absolute() is true, return a default constructed path

(A relative path can't be formed out of when one path is absolute and the other isn't)

If !has_root_directory() && base.has_root_directory() is true return a default constructed path

(Again if one path contains a root directory and the other doesn't a relative path can't be formed

if any filename in the relative_path() or the base.relative_path() can be interpreted as a root-name

return a default constructed path (This is the occasion of having a "path" such as "foo/bar/C:/foo/bar". Such a path cannot be made relative

Otherwise determine the first mismatch of path parts between *this path and the base as if using

auto [a, b] = AZStd::mismatch(begin(), end(), base.begin(), base.end())

Then if a == end() and b == base.end(), then the paths are equal, return a relative path of "."(represents the same path)

Otherwise define N as the number of non-empty filename elements that are not "." or ".." in [b, base.end()] minus

the number of ".." elements. N is less than 0 then return a default constructed path (This is the case of all the parent directories of base being consumed by the "..". Such as a path of "foo/../bar/../..")

If N == 0 and a == end() or a->empty(), then the paths are equal and retruns a path of "."

(This is the case of a making "a/b/c" relative to a path such as "a/b/c/d/.."

Finally if all the above conditions fail then a path is composed of a default constructed path followed by

N applications of the Path append operator on "..", followed by an application of the path append operator for each element in the range of a[a, end()] (Example of this case is making "/a/d" relative to "/a/b/c". The mismatch happens on "d" for *this and b for base the number of path elements remaining from "b" to "base.end" is 2("b", "c"). Therefore two applications of ".." is formed So the path at this point is "../..", then the remaining elements in the mismatched range for *this is then append There is only 1 element in the range of [a, end()] and that is "d", so the final path becomes "../../d"

◆ operator/=()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::operator/= ( const PathView other)
constexpr

Joins a path together using the following rule set let p = other PathView

If p.is_absolute() || (p.has_root_name() && p.root.name() != root_name()

Then replaces the current *this path with p NOTE: This is the case of trying to append something such as "C:\Foo" / "F:\Foo" = "F:\Foo" IMPORTANT NOTE: this also applies for the root directory as well So appending "test/foo" "/bar" results in "/bar", not "test/foo/bar" If "test/foo/bar" is desired then either operator+=/concat can be used with "/bar" or leading path separator in bar is skipped over so that only "bar" is passed to operator+=

Otherwise If p.has_root_directory(), then removes any root directory and the entire relative path

from *this These address the the following cases:

  1. "C:foo" / "/bar" = "C:/bar"
  2. "C:/foo" / "/charlie" = "C:/charlie", not "C:/foo/charlie" If "C:/foo/charlie" is desired then the leading path separator in "/charlie" can be skipped over before being passed to operator/=

Else if for *this path has_filename() || (!has_root_directory() && is_absolute()), appends

the preferred path separator followed by the p using string operations This function absolute path behavior is consistent with the Python pathlib PurePath module https://docs.python.org/3/library/pathlib.html#pathlib.PurePath

◆ ParentPath()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::ParentPath
constexpr

Returns the parent directory of filename contained within the path windows = "C:\O3DE\foo\bar", posix = "/O3DE/foo/bar" NOTE: If the path ends with a trailing separator "test/foo/" it is treated as being a path of "test/foo" as if the filename of the path is "foo" and the parent directory is "test"

◆ RelativePath()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::RelativePath
constexpr

Returns the relative path portion of the path. This contains the path parts after the root path windows = "O3DE\foo\bar\name.txt", posix = "O3DE/foo/bar/name.txt"

◆ RemoveFilename()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::RemoveFilename
constexpr

Removes the filename portion of the Path NOTE: the filename portion of the path is the part of after last path separator What this means is that calling remove filename on "foo/bar" returns "foo/" and calling remove filename on "foo/" returns "foo/" (Treat the path of being made of two components "foo" and "") What this means is that remove filename does not change the number of path parts

◆ ReplaceExtension()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::ReplaceExtension ( const PathView replacementExtension = {})
constexpr

Replaces the extension of the filename with the supplied parameter. This is done as if by first removing the extension from the *this path appending a "." character to the filename if the replacement extension doesn't begin with one followed by concatenating the extension via operator+=

◆ ReplaceFilename()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::ReplaceFilename ( const PathView replacementFilename)
constexpr

Replaces the filename portion of the Path as if invoking remove filename on the path followed by invoking the append operator/= with the replacement filename

◆ RootDirectory()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::RootDirectory
constexpr

Returns the root directory part of the path if it has one. This is the root directory separator windows = "\", posix = "/"

◆ RootName()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::RootName
constexpr

Returns the root name part of the path. if it has one. This is the part of the path before the '/' root directory part windows = "C:", posix = ""

◆ RootPath()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::RootPath
constexpr

Returns the full root path portion of the path made as if it joined the root_name() and root_directory() windows = "C:\", posix = "/"

◆ Stem()

template<typename StringType >
constexpr auto AZ::IO::BasicPath< StringType >::Stem
constexpr

Returns the filename of the path stripped of it's extension windows = "name", posix = "name" NOTE: If the filename starts with a "." it is treated as part of the stem i.e "home/user/.vimrc"; The stem portion is ".vimrc" in this case

◆ String()

template<typename StringType >
AZStd::string AZ::IO::BasicPath< StringType >::String

The string and wstring functions cannot be constexpr until AZStd::basic_string is made constexpr. This cannot occur until C++20 as operator new/delete cannot be used within constexpr functions Returns a new instance of an AZStd::string made from the internal string


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