Flow123d
JS_before_hm-1804-gf2ad740aa
|
Dedicated class for storing path to input and output files. More...
#include <file_path.hh>
Public Types | |
enum | FileType { input_file, output_file } |
Possible types of file. More... | |
Public Member Functions | |
TYPEDEF_ERR_INFO (EI_Path, string) | |
TYPEDEF_ERR_INFO (EI_Address_String, string) | |
DECLARE_EXCEPTION (ExcFileOpen,<< "Can not open file: "<< EI_Path::qval<< "\nAt input address: "<< EI_Address_String::qval) | |
DECLARE_EXCEPTION (ExcAbsOutputPath,<< "Can not set absolute path "<< EI_Path::qval<< " for an output file.") | |
DECLARE_EXCEPTION (ExcMkdirFail,<< "Can not create directory: "<< EI_Path::qval) | |
FilePath () | |
FilePath (string file_path, const FileType ft) | |
FilePath (vector< string > sub_paths, const FileType ft) | |
Same as previous, but create path from vector of strings. More... | |
FilePath (string file_path) | |
Same as previous but implicitly use FileType::output_file. More... | |
operator string () const | |
bool | operator== (const FilePath &other) const |
Equality comparison operators for FilePaths. More... | |
void | create_output_dir () |
string | parent_path () const |
string | filename () const |
string | stem () const |
string | extension () const |
string | cut_extension () const |
template<class Stream > | |
void | open_stream (Stream &stream) const |
bool | exists () const |
Static Public Member Functions | |
static void | set_io_dirs (const string working_dir, const string root, const string input, const string output) |
Obsolete method for set input and output directories. More... | |
static void | set_dirs (const string root, const string input, const string output) |
Method for set input and output directories. More... | |
static string | set_dirs_from_input (const string main_yaml, const string input, const string output) |
Method for set input and output directories. More... | |
static void | add_placeholder (string key, string value) |
Add new item to place holder. More... | |
static const string | get_absolute_working_dir () |
Private Member Functions | |
void | substitute_value (string &path) |
Static Private Member Functions | |
static void | create_dir (const boost::filesystem::path &dir) |
static string | convert_for_check_absolute (string path) |
Prepare path string for check absolute path. More... | |
Private Attributes | |
std::shared_ptr< boost::filesystem::path > | abs_file_path_ |
Final absolute path to the file. More... | |
FileType | file_type_ |
File type. More... | |
Static Private Attributes | |
static std::map< string, string > | placeholder |
dictionary of placeholders More... | |
static std::shared_ptr< boost::filesystem::path > | output_dir =std::make_shared<boost::filesystem::path>(".") |
Prefix path for output files. More... | |
static std::shared_ptr< boost::filesystem::path > | root_dir =std::make_shared<boost::filesystem::path>(".") |
Prefix path for input files (directory of the main input file). More... | |
Dedicated class for storing path to input and output files.
FilePath objects are constructed from given absolute or relative path to the file and its type (input or output). Before you create any instance of the class you have to call static method set_io_dirs
to set:
Definition at line 54 of file file_path.hh.
enum FilePath::FileType |
Possible types of file.
Enumerator | |
---|---|
input_file | |
output_file |
Definition at line 67 of file file_path.hh.
FilePath::FilePath | ( | ) |
Default constructor, necessary when using Input::Record::opt_val() to initialize a FilePath.
Definition at line 89 of file file_path.cc.
FilePath::FilePath | ( | string | file_path, |
const FileType | ft | ||
) |
Translates the given absolute or relative path to a file file_path
depending on the file type ft
.
For input files:
For output files:
Definition at line 50 of file file_path.cc.
Same as previous, but create path from vector of strings.
Definition at line 81 of file file_path.cc.
FilePath::FilePath | ( | string | file_path | ) |
Same as previous but implicitly use FileType::output_file.
Definition at line 85 of file file_path.cc.
|
static |
Add new item to place holder.
Placeholder is extended by adding a single new item. The item can be used in the name of the input or output file name. Currently, the only supported placeholder is $INPUT_DIR$.
[in] | key | Key of new item. |
[in] | value | Value of new item. |
Definition at line 155 of file file_path.cc.
|
staticprivate |
Prepare path string for check absolute path.
Check first char of path string. If it is slash '/', add second slash char. Two slashes at begin is necessary for correct output of boost::filesystem::path.is_absolute() method for detection absolute path in unix format ("/home/x/y/z") under cygwin.
Definition at line 239 of file file_path.cc.
|
staticprivate |
Create a directory, and check for exceptions.
Definition at line 256 of file file_path.cc.
void FilePath::create_output_dir | ( | ) |
For an output filepath, the directory part (up to last separator) is extracted and all subdirectories are created if doesn't exist yet.
Definition at line 176 of file file_path.cc.
string FilePath::cut_extension | ( | ) | const |
Return path to file with filename without extension.
Definition at line 203 of file file_path.cc.
FilePath::DECLARE_EXCEPTION | ( | ExcAbsOutputPath | , |
<< "Can not set absolute path "<< EI_Path::qval<< " for an output file." | |||
) |
FilePath::DECLARE_EXCEPTION | ( | ExcFileOpen | , |
<< "Can not open file: "<< EI_Path::qval<< "\nAt input address: "<< EI_Address_String::qval | |||
) |
FilePath::DECLARE_EXCEPTION | ( | ExcMkdirFail | , |
<< "Can not create directory: "<< EI_Path::qval | |||
) |
bool FilePath::exists | ( | ) | const |
Return true if the FilePath is a file.
Definition at line 228 of file file_path.cc.
string FilePath::extension | ( | ) | const |
Return extension of file.
Definition at line 198 of file file_path.cc.
string FilePath::filename | ( | ) | const |
Return name of file with extension.
Definition at line 188 of file file_path.cc.
|
static |
Return absolute path of actual working directory.
Definition at line 171 of file file_path.cc.
template void FilePath::open_stream | ( | Stream & | stream | ) | const |
Open stream for this FilePath. Open mode is determined from the FilePath type.
Definition at line 211 of file file_path.cc.
FilePath::operator string | ( | ) | const |
This class is implicitly convertible to string.
Definition at line 251 of file file_path.cc.
bool FilePath::operator== | ( | const FilePath & | other | ) | const |
Equality comparison operators for FilePaths.
Definition at line 266 of file file_path.cc.
string FilePath::parent_path | ( | ) | const |
Return path to file.
Definition at line 183 of file file_path.cc.
|
static |
Method for set input and output directories.
Set:
Definition at line 102 of file file_path.cc.
|
static |
Method for set input and output directories.
Same as previous, but in first argument accepts full path of yaml file and returns filename of this yaml file.
Set:
Definition at line 137 of file file_path.cc.
|
static |
Obsolete method for set input and output directories.
Ensures consistency of unit tests.
Set:
Definition at line 96 of file file_path.cc.
string FilePath::stem | ( | ) | const |
Return name of file without extension.
Definition at line 193 of file file_path.cc.
|
private |
Substitutes placeholders in path
.
Definition at line 160 of file file_path.cc.
FilePath::TYPEDEF_ERR_INFO | ( | EI_Address_String | , |
string | |||
) |
FilePath::TYPEDEF_ERR_INFO | ( | EI_Path | , |
string | |||
) |
Reporting failure when openning a file.
|
private |
Final absolute path to the file.
Definition at line 227 of file file_path.hh.
|
private |
File type.
Definition at line 230 of file file_path.hh.
|
staticprivate |
Prefix path for output files.
Definition at line 236 of file file_path.hh.
|
staticprivate |
dictionary of placeholders
Definition at line 233 of file file_path.hh.
|
staticprivate |
Prefix path for input files (directory of the main input file).
Definition at line 239 of file file_path.hh.