#include <file_path_class.h>
The FilePathClass represents a single absolute path. There are methods for getting the directory, filename, file extension, and checking the validity of the path. You can get a relative path string by comparing two FilePathClass objects. FilePathClass also has methods for reading/writing absolute or relative path strings, the class remembers which was last read and writes out the same way. You can change this behavior by modifying the WriteAsAbsolutePath() flag.
◆ FilePathClass() [1/5]
Default construction. Path() is initially "" and invalid
◆ FilePathClass() [2/5]
Implicit conversion
- Parameters
-
stringPath | The path to set. |
◆ FilePathClass() [3/5]
Implicit conversion
- Parameters
-
stringPath | The path to set. |
◆ FilePathClass() [4/5]
Copy construction
- Parameters
-
other | The object to copy from. |
◆ FilePathClass() [5/5]
Move construction
- Parameters
-
other | The object to move from. |
◆ Directory()
std::string Directory |
( |
| ) |
const |
- Returns
- The directory containing the referenced file (includes trailing slash) or "" if the path is not valid.
◆ FileExists()
bool FileExists |
( |
| ) |
const |
- Returns
- True if this file path references a file that exists.
- Note
- Applies only to files; returns false for directories. Returns true for symbolic links that exist, regardless whether the link's target exists.
◆ FileExtension() [1/2]
std::string FileExtension |
( |
| ) |
const |
- Returns
- The file extension for the file (everything after the last ".") or "" if the path is not valid, doesn't reference a file, or the file has no extension.
◆ FileExtension() [2/2]
void FileExtension |
( |
const std::string & |
ext | ) |
|
Replace the current file extension with the specified string. This will also insert a '.' into the filename if needed.
- Parameters
-
ext | The new extension (e.g. "txt") |
◆ FileName()
std::string FileName |
( |
| ) |
const |
- Returns
- The filename of the file (including the extension) or "" if the path is not valid or doesn't reference a file.
◆ GetCWD()
- Returns
- A file path set to the current working directory.
◆ InvalidPathChars()
static const std::string & InvalidPathChars |
( |
| ) |
|
|
static |
- Returns
- A string containing the characters that invalid to use in a path.
◆ IsValid()
- Returns
- True if the path points to a directory or file that COULD exist. (i.e. Path() will return a valid path as close as we can verify it.)
◆ operator!=()
Inequality operator If paths are not equal it doesn't guarantee that they reference different files.
- Parameters
-
- Returns
- Whether or not the paths are not equal.
◆ operator=() [1/2]
Copy assignment
- Parameters
-
other | The object to copy from. |
- Returns
- The resulting object (this).
◆ operator=() [2/2]
Move assignment
- Parameters
-
other | The object to move from. |
- Returns
- The resulting object (this).
◆ operator==()
Equality operator If paths are equal they reference the same file.
- Parameters
-
- Returns
- Whether or not the paths are equal.
◆ Path()
const std::string & Path |
( |
| ) |
const |
|
inline |
- Returns
- A string containing the complete path.
- Note
- This method returns whatever is stored in the path whether it is valid or not.
◆ PathRelativeTo()
std::string PathRelativeTo |
( |
const FilePathClass & |
basePath | ) |
const |
- Parameters
-
basePath | The path to calculate the relative path from. |
- Returns
- A string containing the relative path to this path from the given path's directory.
- Note
- Returns Path() if the relative path cannot be determined.
◆ ReadPathString()
bool ReadPathString |
( |
const FilePathClass & |
basePath, |
|
|
const std::string & |
strPath |
|
) |
| |
Read a relative or absolute path from a string
- Precondition
- None
- Postcondition
- If strPath was an absolute path or invalid then this path will be set to strPath and WriteAsAbsolutePath() will be true If strPath was relative, this path will be set to basePath + strPath and WriteAsAbsolutePath() will be false
- Parameters
-
basePath | Used to build a complete path if strPath contains a relative path |
strPath | The string to read into |
- Returns
- true on success or false if there was an error (basePath or strPath are invalid)
◆ SetToCWD()
Set this object to point to the current working directory
- Returns
- true on success, false if there was an error
◆ StringIsAbsolutePath()
static bool StringIsAbsolutePath |
( |
const std::string & |
strPath | ) |
|
|
static |
- Parameters
-
strPath | The string to check. |
- Returns
- true If the given string contains an absolute path.
◆ StringIsRelativePath()
static bool StringIsRelativePath |
( |
const std::string & |
strPath | ) |
|
|
static |
- Parameters
-
strPath | The string to check. |
- Returns
- True if the given string contains an relative path.
◆ StringIsValidPath()
static bool StringIsValidPath |
( |
const std::string & |
strPath | ) |
|
|
static |
- Parameters
-
strPath | The string to check. |
- Returns
- true If the given string contains a valid or absolute path as close as we can verify it.
◆ WriteAsAbsolutePath() [1/2]
bool WriteAsAbsolutePath |
( |
| ) |
|
|
inline |
- Returns
- Whether or not paths will be written as absolute.
◆ WriteAsAbsolutePath() [2/2]
void WriteAsAbsolutePath |
( |
bool |
value | ) |
|
|
inline |
Set whether or not paths will be written as absolute paths.
- Parameters
-
value | The new path write value to set. |
◆ WritePathString()
void WritePathString |
( |
const FilePathClass & |
basePath, |
|
|
std::string * |
strPath |
|
) |
| |
Get the path string to write to a file This strPath will be either the absolute or relative path depending on the current setting of the WriteAsAbsolutePath() flag
- Parameters
-
basePath | Used to build a relative path if WriteAsAbsolutePath is false |
strPath | The string to write to
|
◆ operator<<
std::ostream & operator<< |
( |
std::ostream & |
outstr, |
|
|
const FilePathClass & |
path |
|
) |
| |
|
friend |
Stream out operator
- Parameters
-
outstr | Stream to write path to. |
path | Path to write to the stream. |
- Returns
- The stream in its current state.
◆ operator>>
std::istream & operator>> |
( |
std::istream & |
instr, |
|
|
FilePathClass & |
path |
|
) |
| |
|
friend |
Stream in operator
- Parameters
-
instr | The stream to read path from. |
path | Returned path read from the stream. |
- Returns
- The stream in its current state.
◆ _path
The complete path: format is "<directory>/<filename>.<extension>" where / is last slash and . is the first dot after the last slash
◆ _writeAsAbsolutePath
bool _writeAsAbsolutePath |
|
protected |
Controls how the Path is written out when WritePathString is called Defaults to false
The documentation for this class was generated from the following file: