GL Studio API
|
#include <file_path_class.h>
Public Member Functions | |
FilePathClass () | |
FilePathClass (const std::string &stringPath) | |
bool | IsValid () const |
bool | FileExists () const |
std::string | PathRelativeTo (const FilePathClass &basePath) const |
const std::string & | Path () const |
std::string | Directory () const |
std::string | FileName () const |
std::string | FileExtension () const |
void | FileExtension (const std::string &ext) |
bool | operator== (const FilePathClass &path) const |
FilePathClass & | operator= (const FilePathClass &path) |
bool | SetToCWD () |
void | WriteAsAbsolutePath (bool value) |
bool | ReadPathString (const FilePathClass &basePath, const std::string &strPath) |
void | WritePathString (const FilePathClass &basePath, std::string *strPath) |
Static Public Member Functions | |
static const std::string & | InvalidPathChars () |
static bool | StringIsAbsolutePath (const std::string &strPath) |
static bool | StringIsRelativePath (const std::string &strPath) |
static bool | StringIsValidPath (const std::string &strPath) |
Protected Attributes | |
std::string | _path |
bool | _writeAsAbsolutePath |
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 | ( | ) |
Constructor. Path() is initially "" and invalid
FilePathClass | ( | const std::string & | stringPath | ) |
Implicit conversion - Path() is set to stringPath
std::string Directory | ( | ) | const |
Get the directory containing the referenced file (includes trailing slash) "" if the Path is not valid
bool FileExists | ( | ) | const |
Return true if this file path references a file that exists. Applies only to files; returns false for directories. Returns true for symbolic links that exist, regardless whether the link's target exists.
std::string FileExtension | ( | ) | const |
Get the file extension for the file (everything after the last ".") "" if the Path is not valid, doesn't reference a file, or the file has no extension
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.
ext | The new extension (e.g. "txt") |
std::string FileName | ( | ) | const |
Get the filename of the file (including the extension) "" if the Path is not valid or doesn't reference a file
|
static |
Return a string containing the characters that invalid to use in a path
bool IsValid | ( | ) | const |
Return 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.)
FilePathClass& operator= | ( | const FilePathClass & | path | ) |
Assignment operator (absolute path)
bool operator== | ( | const FilePathClass & | path | ) | const |
Equality operators If paths are equal they reference the same file If paths are not equal it doesn't guarantee that they reference different files
|
inline |
Return a string containing the complete path
std::string PathRelativeTo | ( | const FilePathClass & | basePath | ) | const |
Return true if the Directory() of this path DOES exist Create the Directory() for this path if it doesn't exist
bool ReadPathString | ( | const FilePathClass & | basePath, |
const std::string & | strPath | ||
) |
Read a relative or absolute path from a string
basePath | Used to build a complete path if strPath contains a relative path |
strPath | The string to read into |
bool SetToCWD | ( | ) |
Set this object to point to the current working directory
|
static |
return true if the given string contains an absolute path
|
static |
return true if the given string contains an relative path
|
static |
return true if the given string contains a valid or absolute path as close as we can verify it
|
inline |
Get and set the WriteAsAbsolutePath flag
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
basePath | Used to build a relative path if WriteAsAbsolutePath is false |
strPath | The string to write to |
|
protected |
The complete path: format is "<directory>/<filename>.<extension>" where / is last slash and . is the first dot after the last slash
|
protected |
Controls how the Path is written out when WritePathString is called Defaults to false