STIR  6.2.0
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
stir::FilePath Class Reference

The FilePath class. More...

#include "stir/FilePath.h"

Public Member Functions

 FilePath (const std::string &__str, bool _run_checks=true)
 FilePath If the initial path exists in the disk _check should be left true. It will check that the path is writable If you want to initialize to an arbitary string then set _run_checks false.
 
bool is_directory () const
 Returns true if my_string points to a directory.
 
bool is_regular_file () const
 Returns true if my_string points to a regular file Returns true if the path is writable. More...
 
bool is_writable () const
 On Windows the attribute INVALID_FILE_ATTRIBUTES is used. Which is not quite the same.
 
FilePath append (const FilePath &p)
 Create a new folder,by FilePath, and return its path as FilePath.
 
FilePath append (const std::string &p)
 Create a new folder,by string, and return its path. More...
 
void prepend_directory_name (const std::string &p)
 If path is no absolute then prepend the p string.
 
void add_extension (const std::string &e)
 Append extension e if none is present.
 
void replace_extension (const std::string &e)
 Replace extension.
 
std::string get_path () const
 Get path from string.
 
std::string get_path_only () const
 Get the path from string. If no path in string returns empty string.
 
std::string get_filename () const
 Get only the filename An inherent functionality from utilities is that on Windows all separators will be checked.
 
std::string get_filename_no_extension () const
 Convinience function which returns the filename withouth the extension.
 
std::string get_extension () const
 Get the extension of the filename.
 
std::string get_as_string () const
 Return the current full string.
 
std::string get_string () const
 
bool operator== (const FilePath &other)
 
bool operator== (const std::string &other)
 
void operator= (const FilePath &other)
 
void operator= (const std::string &other)
 

Static Public Member Functions

static bool is_absolute (const std::string &_filename_with_directory)
 Returns true if the _filename_with_directory is an absolute path.
 
static bool exists (const std::string &s)
 Returns true if the path s already exists.
 
static std::string get_current_working_directory ()
 Returns the current / working directory.
 
static void append_separator (std::string &s)
 Append the separator.
 

Protected Attributes

std::string my_string
 This is the string holding the data.
 
std::string separator
 The separator for the current OS.
 
bool run_checks
 Run checks on the my_string on various occations. You want this when you operate on existing paths.
 

Detailed Description

The FilePath class.

Description
This class provides basic filesystem support for STIR. It is build in a similar manner to the functions in the utilities but extends with support to create folders, check if folder exists and is writable.

The old pathname operations are supported.

Member Function Documentation

◆ is_regular_file()

bool stir::FilePath::is_regular_file ( ) const

Returns true if my_string points to a regular file Returns true if the path is writable.

Warning
N.E: As far as I understand is only a *NIX feature. Write permissions do not exist in this level at Windows.

References stir::error(), and stir::info().

Referenced by stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< TargetT >::post_processing().

◆ append()

FilePath stir::FilePath::append ( const std::string &  p)

Create a new folder,by string, and return its path.

This functions creates appends path p to my_string. It supports multiple new folder levels.It will try to avoid errors as permissions and non existing root path.

References stir::error().

◆ operator=()

void stir::FilePath::operator= ( const std::string &  other)
inline
Warning
Possibly dangerous. When the object has been initialized with a existing path and then string in the assigment is an arbitary string this can lead to unexpented behaviour. Hopefully, we guard sufficiently by by performing checks again before crusial functions.
Possibly dangerous... when real paths are used.

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