GL Studio C++ Runtime API
FilePathClass Class Reference

#include <file_path_class.h>

Public Member Functions

 FilePathClass ()
 
 FilePathClass (const std::string &stringPath)
 
 FilePathClass (const char *stringPath)
 
 FilePathClass (const FilePathClass &other)
 
FilePathClassoperator= (const FilePathClass &other)
 
 FilePathClass (FilePathClass &&other)
 
FilePathClassoperator= (FilePathClass &&other)
 
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
 
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 FilePathClass GetCWD ()
 
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
 

Detailed Description

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.

Constructor & Destructor Documentation

Default construction. Path() is initially "" and invalid

FilePathClass ( const std::string &  stringPath)

Implicit conversion - Path() is set to stringPath

FilePathClass ( const char *  stringPath)

Implicit conversion - Path() is set to stringPath

FilePathClass ( const FilePathClass other)
inline

Copy construction

FilePathClass ( FilePathClass &&  other)
inline

Move construction

Member Function Documentation

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.

Parameters
extThe 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 FilePathClass GetCWD ( )
inlinestatic

Get a file path set to the Current Working Directory.

static const std::string& InvalidPathChars ( )
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 other)
inline

Copy assignment

FilePathClass& operator= ( FilePathClass &&  other)
inline

Move assignment

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

const std::string& Path ( ) const
inline

Return a string containing the complete path

Note
this method returns whatever is stored in the path whether it is valid or not
std::string PathRelativeTo ( const FilePathClass basePath) const

Return a string containing the relative path to this path from the given path's Directory Returns Path() if the relative path cannot be determined

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
basePathUsed to build a complete path if strPath contains a relative path
strPathThe string to read into
Returns
true on success or false if there was an error (basePath or strPath are invalid)
bool SetToCWD ( )

Set this object to point to the current working directory

Returns
true on success, false if there was an error
static bool StringIsAbsolutePath ( const std::string &  strPath)
static

return true if the given string contains an absolute path

static bool StringIsRelativePath ( const std::string &  strPath)
static

return true if the given string contains an relative path

static bool StringIsValidPath ( const std::string &  strPath)
static

return true if the given string contains a valid or absolute path as close as we can verify it

void WriteAsAbsolutePath ( bool  value)
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

Parameters
basePathUsed to build a relative path if WriteAsAbsolutePath is false
strPathThe string to write to

Member Data Documentation

std::string _path
protected

The complete path: format is "<directory>/<filename>.<extension>" where / is last slash and . is the first dot after the last slash

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: