Jlm
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
jlm::util::FilePath Class Referencefinal

#include <file.hpp>

Public Member Functions

 FilePath (const std::string &path)
 
 FilePath (const FilePath &other)
 
 FilePath (FilePath &&other) noexcept
 
FilePathoperator= (const FilePath &other)
 
FilePathoperator= (FilePath &&other) noexcept
 
std::string base () const noexcept
 Returns the base name of the file without the path. More...
 
std::string name () const noexcept
 Returns the name of the file, excluding the path. More...
 
std::string complete_suffix () const noexcept
 Returns the complete suffix (extension) of the file. More...
 
std::string suffix () const noexcept
 Returns the suffix (extension) of the file. More...
 
FilePath Dirname () const noexcept
 Returns the path to the file or directory's parent directory. Emulates the behavior of the GNU coreutil "dirname". More...
 
FilePath Join (const std::string &other) const
 
FilePath Join (const FilePath &other) const
 
FilePath WithSuffix (const std::string &suffix) const
 
bool Exists () const noexcept
 Determines whether the file path exists. More...
 
bool IsDirectory () const noexcept
 Determines whether file path is a directory. More...
 
bool isFile () const noexcept
 Determines whether file path is a file. More...
 
void CreateDirectory () const
 
const std::string & to_str () const noexcept
 
bool operator== (const FilePath &other) const noexcept
 
bool operator== (const std::string &f) const noexcept
 

Static Public Member Functions

static FilePath createUniqueFileName (const FilePath &directory, const std::string &fileNamePrefix, const std::string &fileNameSuffix)
 Generates a unique file in a given directory with a prefix and suffix. More...
 
static FilePath TempDirectoryPath ()
 

Private Attributes

std::string path_
 

Detailed Description

Definition at line 18 of file file.hpp.

Constructor & Destructor Documentation

◆ FilePath() [1/3]

jlm::util::FilePath::FilePath ( const std::string &  path)
inlineexplicit

Definition at line 21 of file file.hpp.

◆ FilePath() [2/3]

jlm::util::FilePath::FilePath ( const FilePath other)
inline

Definition at line 25 of file file.hpp.

◆ FilePath() [3/3]

jlm::util::FilePath::FilePath ( FilePath &&  other)
inlinenoexcept

Definition at line 29 of file file.hpp.

Member Function Documentation

◆ base()

std::string jlm::util::FilePath::base ( ) const
inlinenoexcept

Returns the base name of the file without the path.

Example: jlm::file f("/tmp/archive.tar.gz"); auto base = f.base(); // base = "archive"

Definition at line 61 of file file.hpp.

◆ complete_suffix()

std::string jlm::util::FilePath::complete_suffix ( ) const
inlinenoexcept

Returns the complete suffix (extension) of the file.

Example: jlm::file f("/tmp/archive.tar.gz"); auto ext = f.complete_suffix(); // ext = "tar.gz"

Definition at line 98 of file file.hpp.

◆ CreateDirectory()

void jlm::util::FilePath::CreateDirectory ( ) const
inline

Creates the directory represented by this file path object. The parent directory must already exist. The directory can also exist already, in which case this is a no-op.

Exceptions
jlm::util::errorif an error occurs

Definition at line 258 of file file.hpp.

◆ createUniqueFileName()

static FilePath jlm::util::FilePath::createUniqueFileName ( const FilePath directory,
const std::string &  fileNamePrefix,
const std::string &  fileNameSuffix 
)
inlinestatic

Generates a unique file in a given directory with a prefix and suffix.

Parameters
directoryThe directory in which the file is created.
fileNamePrefixThe file name prefix.
fileNameSuffixThe file name suffix.
Returns
A unique file

Definition at line 301 of file file.hpp.

◆ Dirname()

FilePath jlm::util::FilePath::Dirname ( ) const
inlinenoexcept

Returns the path to the file or directory's parent directory. Emulates the behavior of the GNU coreutil "dirname".

If the current path does not contain a parent directory, either "/" or "." is returned, depending on whether this is an absolute or relative path.

This function does not respect ".." and instead treats it like any other folder.

Examples: "/tmp/archive.tar.gz" => "/tmp" "/tmp/jlm/" => "/tmp" "/a" => "/" "a/.." => "a" "dir/file.txt" => "dir" "test.txt" => "." Special cases: "/" => "/" "." => "." "" => "."

Definition at line 148 of file file.hpp.

◆ Exists()

bool jlm::util::FilePath::Exists ( ) const
inlinenoexcept

Determines whether the file path exists.

Returns
True if the file path exists, otherwise false.

Definition at line 222 of file file.hpp.

◆ IsDirectory()

bool jlm::util::FilePath::IsDirectory ( ) const
inlinenoexcept

Determines whether file path is a directory.

Returns
True if the file path is a directory, otherwise false.

Definition at line 233 of file file.hpp.

◆ isFile()

bool jlm::util::FilePath::isFile ( ) const
inlinenoexcept

Determines whether file path is a file.

Returns
True if the file path is a file, otherwise false.

Definition at line 244 of file file.hpp.

◆ Join() [1/2]

FilePath jlm::util::FilePath::Join ( const FilePath other) const
inline

Definition at line 201 of file file.hpp.

◆ Join() [2/2]

FilePath jlm::util::FilePath::Join ( const std::string &  other) const
inline

Creates a new file path this / other.

If other is an absolute path, the this-part is completely ignored. What constitutes an absolute path is platform specific.

Any "." or ".." in paths are kept as is. Except if the this-part is equal to ".", in which case other is returned directly.

Examples: "/tmp/" join "a.txt" => "/tmp/a.txt" "a/b" join "c/d" => "a/b/c/d" "a/b" join "/tmp/x" => "/tmp/x" "." join "e.txt" => "e.txt" "" join "e.txt" => "e.txt" "a/." join "../e.txt" => "a/./../e.txt"

Parameters
otherthe second part of the path
Returns
the joined file path

Definition at line 193 of file file.hpp.

◆ name()

std::string jlm::util::FilePath::name ( ) const
inlinenoexcept

Returns the name of the file, excluding the path.

Example: jlm::file f("/tmp/archive.tar.gz"); auto name = f.name(); // name = "archive.tar.gz"

Returns
The name of the file

Definition at line 81 of file file.hpp.

◆ operator=() [1/2]

FilePath& jlm::util::FilePath::operator= ( const FilePath other)
inline

Definition at line 34 of file file.hpp.

◆ operator=() [2/2]

FilePath& jlm::util::FilePath::operator= ( FilePath &&  other)
inlinenoexcept

Definition at line 44 of file file.hpp.

◆ operator==() [1/2]

bool jlm::util::FilePath::operator== ( const FilePath other) const
inlinenoexcept

Definition at line 281 of file file.hpp.

◆ operator==() [2/2]

bool jlm::util::FilePath::operator== ( const std::string &  f) const
inlinenoexcept

Definition at line 287 of file file.hpp.

◆ suffix()

std::string jlm::util::FilePath::suffix ( ) const
inlinenoexcept

Returns the suffix (extension) of the file.

Example: jlm::file f("/tmp/archive.tar.gz"); auto ext = f.suffix(); // ext = "gz"

Definition at line 116 of file file.hpp.

◆ TempDirectoryPath()

static FilePath jlm::util::FilePath::TempDirectoryPath ( )
inlinestatic
Returns
a directory suitable for temporary files

Definition at line 317 of file file.hpp.

◆ to_str()

const std::string& jlm::util::FilePath::to_str ( ) const
inlinenoexcept

Definition at line 275 of file file.hpp.

◆ WithSuffix()

FilePath jlm::util::FilePath::WithSuffix ( const std::string &  suffix) const
inline

Creates a new file path by adding the given suffix

Returns
the new file path

Definition at line 211 of file file.hpp.

Member Data Documentation

◆ path_

std::string jlm::util::FilePath::path_
private

Definition at line 323 of file file.hpp.


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