Flow123d  jenkins-Flow123d-windows32-release-multijob-51
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
FilePath Class Reference

Dedicated class for storing path to input and output files. More...

#include <file_path.hh>

Collaboration diagram for FilePath:
Collaboration graph
[legend]

Public Types

enum  FileType { input_file, output_file }
 Possible types of file. More...
 

Public Member Functions

 TYPEDEF_ERR_INFO (EI_Path, string)
 
 DECLARE_EXCEPTION (ExcAbsOutputPath,<< "Can not set absolute path "<< EI_Path::qval<< "for an output file.")
 
 FilePath ()
 
 FilePath (const string file_path, const FileType ft)
 
 operator string () const
 

Static Public Member Functions

static void set_io_dirs (const string working_dir, const string root_input, const string input, const string output)
 
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 ()
 

Static Private Member Functions

static bool is_absolute_path (const string path)
 
static bool create_output_dir ()
 
static void create_canonical_path (const string working_dir, const string output)
 

Private Attributes

string abs_file_path
 Final absolute path to the file. More...
 

Static Private Attributes

static std::map< string, string > placeholder
 dictionary of placeholders More...
 
static string output_dir =""
 Prefix path for output files. More...
 
static string root_dir =""
 Prefix path for input files (directory of the main input file). More...
 

Detailed Description

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 32 of file file_path.hh.

Member Enumeration Documentation

Possible types of file.

Enumerator
input_file 
output_file 

Definition at line 40 of file file_path.hh.

Constructor & Destructor Documentation

FilePath::FilePath ( )
inline

Default constructor, necessary when using Input::Record::opt_val() to initialize a FilePath.

Definition at line 48 of file file_path.hh.

FilePath::FilePath ( const 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 relative path prepend absolute path of the directory of the main input file (root directory).
  • Replace ${INPUT} place holder with the input directory given at command line.

For output files:

  • Forbids absolute output paths.
  • For relative output path prepends it by the output directory given at the command line.

Definition at line 21 of file file_path.cc.

Member Function Documentation

void FilePath::add_placeholder ( string  key,
string  value 
)
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}.

Example usage:
FilePath::add_placeholder_item("${SUBST_VAL}", "path/value");
Parameters
[in]keyKey of new item.
[in]valueValue of new item.

Definition at line 85 of file file_path.cc.

Here is the caller graph for this function:

void FilePath::create_canonical_path ( const string  working_dir,
const string  output 
)
staticprivate

Create canonical path of output directory given by relative path.

Definition at line 130 of file file_path.cc.

Here is the caller graph for this function:

bool FilePath::create_output_dir ( )
staticprivate

Check if directory stored in output_dir doesn't exist and create its

Definition at line 121 of file file_path.cc.

Here is the caller graph for this function:

FilePath::DECLARE_EXCEPTION ( ExcAbsOutputPath  ,
<< "Can not set absolute path "<< EI_Path::qval<< "for an output file."   
)
const string FilePath::get_absolute_working_dir ( )
static

Return absolute path of actual working directory.

Definition at line 112 of file file_path.cc.

bool FilePath::is_absolute_path ( const string  path)
staticprivate

Test if get path is absolute for used operating system.

Definition at line 101 of file file_path.cc.

Here is the caller graph for this function:

FilePath::operator string ( ) const
inline

This class is implicitly convertible to string.

Definition at line 75 of file file_path.hh.

void FilePath::set_io_dirs ( const string  working_dir,
const string  root_input,
const string  input,
const string  output 
)
static

Set:

  • working directory (used only if the output directory is relative)
  • root directory (of the main input file)
  • input directory to replace ${INPUT} place holder
  • output directory used as prefix to the output files (relative output dirs are relative to the working directory)

Definition at line 42 of file file_path.cc.

Here is the caller graph for this function:

void FilePath::substitute_value ( )
private

Substitutes placeholders in abs_file_path.

Definition at line 90 of file file_path.cc.

Here is the caller graph for this function:

FilePath::TYPEDEF_ERR_INFO ( EI_Path  ,
string   
)

Member Data Documentation

string FilePath::abs_file_path
private

Final absolute path to the file.

Definition at line 126 of file file_path.hh.

string FilePath::output_dir =""
staticprivate

Prefix path for output files.

Definition at line 132 of file file_path.hh.

map< string, string > FilePath::placeholder
staticprivate

dictionary of placeholders

Definition at line 129 of file file_path.hh.

string FilePath::root_dir =""
staticprivate

Prefix path for input files (directory of the main input file).

Definition at line 135 of file file_path.hh.


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