Luna::Path
A container that contains a sequence of names that describe one path.
class Luna::Path
Path is one kind of string that describes the location of one node in a hierarchical-based node tree, given that each node in the tree can be identified by a name string. For example, a file path is used to identify a file or folder in the given file system.
Path is designed to be platform-independent and efficient to handle file path related operations. In implementation, the path object does not store the path string directly, but breaks it down to several parts, and stores each part independently. This makes path-related operations very fast and consumes less memory if you need to store lots of paths.
One path is composed by the following components:1. The root name, which usually determines the domain of the path. For example, then volume symbol on Windows (like C:) is one kind of root name.
-
The directory nodes that composes the path. For example, "C:\Games\MyGame\" has root name "C:" and two directory nodes "Games" and "MyGame". In file object, every directory node as well as the root name is stored independently as one Name object, and they are grouped into one array to form the path sequence.
-
The path flags, see
EPathFlag
for details. Basically, path object uses flags to determine if one path is absolute (if begins with one separator), and if one path represents a directory (if it ends with one separator). This flags are properly set when the path string gets parsed, but it may not be correct. For example, if you parse one path string that represents a directory but does not ends with a separator, theEPathFlag::directory
will not be set for that path. The path object will not use runtime system calls likefile_attribute
to determine if one path is valid or represents a directory, it is the user's responsibility to check it before using it.
Member functions
-
Constructs one empty path.
-
Constructs one path by parsing the specified path string.
-
Path(const String &str, usize pos)
Constructs one path by parsing the specified path string with custom starting position.
-
Path(const String &str, usize pos, usize count)
Constructs one path by parsing the specified path string with custom starting position and string size.
-
Constructs one path by parsing the specified path string.
-
Path(const c8 *s, usize count)
Constructs one path by parsing the specified path string.
-
Constructs one path by moving coping content from another path.
-
Constructs one path by moving moving content from another path.
-
Path & operator=(const String &str)
Replaces content of the path by parsing the specified path string.
-
Replaces content of the path by parsing the specified path string.
-
Path & operator=(const Path &rhs)
Replaces content of the path by coping content from another path.
-
Replaces content of the path by coping content from another path.
-
Gets the path flags.
-
Gets the path flags.
-
Normalizes the path.
-
String encode(PathSeparator separator=PathSeparator::slash, bool has_root=true) const
Encodes the current path to a string.
-
Replaces content of the path by coping content from another path.
-
Replaces content of the path by coping content from another path.
-
void assign(const String &str)
Replaces content of the path by parsing the specified path string.
-
void assign(const String &str, usize pos)
Replaces content of the path by parsing the specified path string with custom starting position.
-
void assign(const String &str, usize pos, usize count)
CReplaces content of the path by parsing the specified path string with custom starting position and string size.
-
Replaces content of the path by parsing the specified path string.
-
void assign(const c8 *s, usize count)
Replaces content of the path by parsing the specified path string.
-
void assign_relative(const Path &base, const Path &target)
Assigns the content of this path with a new path that if appended to
base
path, creates a path equal totarget
path. -
Gets the path root name.
-
Gets the path root name.
-
Gets the extension name of the path, that is, the name string after the last dot(.) character.
-
Gets the filename of the path, which is the last node in the path excluding extension and the separating dot(
.
). -
void replace_extension(const c8 *new_extension)
Replaces the extension.
-
void replace_extension(const c8 *new_extension, usize count)
Replaces the extension.
-
void append_extension(const c8 *new_extension)
Appends the extension.
-
void append_extension(const c8 *new_extension, usize count)
Appends the extension.
-
Removes the extension.
-
const_reference at(usize index) const
Gets the name node at the specified index.
-
Gets the name node at the specified index.
-
const_reference operator[](usize index) const
Gets the name node at the specified index.
-
reference operator[](usize index)
Gets the name node at the specified index.
-
Gets one iterator to the first name node of the path.
-
Gets one constant iterator to the first name node of the path.
-
Gets one constant iterator to the first name node of the path.
-
Gets one iterator to the one past last name node of the path.
-
Gets one constant iterator to the one past last name node of the path.
-
Gets one constant iterator to the one past last name node of the path.
-
Gets one reverse iterator to the last name node of the path.
-
const_reverse_iterator rbegin() const
Gets one constant reverse iterator to the last name node of the path.
-
const_reverse_iterator crbegin() const
Gets one constant reverse iterator to the last name node of the path.
-
Gets one reverse iterator to the one-before-first name node of the path.
-
const_reverse_iterator rend() const
Gets one constant reverse iterator to the one-before-first name node of the path.
-
const_reverse_iterator crend() const
Gets one constant reverse iterator to the one-before-first name node of the path.
-
Gets the size of the path, that is, the number of name nodes in the path.
-
Checks whether this path is empty, that is, the size of this path is
0
. -
Gets the first name node in the path.
-
Gets the first name node in the path.
-
Gets the last name node in the path.
-
Gets the last name node in the path.
-
void push_back(const Name &path_node)
Inserts one name node at the back of the path.
-
void push_back(Name &&path_node)
Inserts one name node at the back of the path.
-
Removes the last name node of the path.
-
void append(const Path &appended_path)
Appends another path to the end of this path.
-
void append(const Path &appended_path, usize pos)
Appends another path to the end of this path.
-
void append(const Path &appended_path, usize pos, usize count)
Appends another path to the end of this path.
-
Clears all nodes in the path.
-
Resets the path object. This operation clears all nodes in the path, then clears the root name and flags of the path.
-
iterator erase(const_iterator pos)
Removes one name node from the path.
-
iterator erase(const_iterator first, const_iterator last)
Removes one range of name nodes from the path.
-
Computes the hash code of this path.
-
bool is_subpath_of(const Path &base) const
Checks whether the current path is one subsequent path of the specified base path.
-
bool equal_to(const Path &rhs, PathComponent compared_components=PathComponent::all) const
Compares two paths for equality.
-
bool operator==(const Path &rhs) const
Compares all components of two paths for equality.
-
bool operator!=(const Path &rhs) const
Compares all components of two paths for non-equality.