18 #include <boost/filesystem.hpp>
23 #include <type_traits>
33 if (sub_paths.size() == 1) {
36 boost::filesystem::path path = sub_paths[0];
37 for (
unsigned int i=1; i<sub_paths.size(); ++i)
38 path = path / sub_paths[i];
46 std::shared_ptr<boost::filesystem::path>
FilePath::output_dir=std::make_shared<boost::filesystem::path>(
".");
47 std::shared_ptr<boost::filesystem::path>
FilePath::root_dir=std::make_shared<boost::filesystem::path>(
".");
53 if (*
output_dir == boost::filesystem::path(
".")) {
54 WarningOut() <<
"Creating FileName object before set_io_dirs is called. No file path resolving." << std::endl;
55 abs_file_path_ = std::make_shared<boost::filesystem::path>(file_path);
61 abs_file_path_ = std::make_shared<boost::filesystem::path>(file_path);
90 : abs_file_path_(
std::make_shared<
boost::filesystem::path>(
"/__NO_FILE_NAME_GIVEN__") ),
91 file_type_(output_file)
96 void FilePath::set_io_dirs(
const string working_dir,
const string root,
const string input,
const string output) {
105 root_dir = std::make_shared<boost::filesystem::path>(root);
107 boost::filesystem::path abs_root_path = boost::filesystem::canonical( boost::filesystem::current_path() / root );
108 root_dir = std::make_shared<boost::filesystem::path>(abs_root_path);
115 boost::filesystem::path full_output_path;
118 full_output_path = boost::filesystem::path(root) / output;
122 boost::filesystem::path output_path = boost::filesystem::path(root) / output;
124 full_output_path = boost::filesystem::canonical( boost::filesystem::current_path() / output_path);
127 full_output_path = boost::filesystem::path(output);
130 output_dir = std::make_shared<boost::filesystem::path>( full_output_path );
138 boost::filesystem::path input_path;
140 input_path = boost::filesystem::path(
".") / main_yaml;
142 input_path = boost::filesystem::path(main_yaml);
144 if (! boost::filesystem::exists(input_path))
145 THROW(ExcFileOpen() << EI_Path(input_path.string()));
150 return input_path.filename().string();
162 size_t i = path.find(
it->first,0);
163 if (i != std::string::npos) {
164 ASSERT(
it->second !=
"")(
it->first).warning(
"Substituting placeholder with empty value.");
165 path.replace(i,
it->first.size(),
it->second);
172 return boost::filesystem::current_path().string() +
"/";
205 return path.string();
210 template <
class Stream>
221 if (! stream.is_open())
240 ASSERT(path.length()).error(
"Empty path.");
242 if (path[0] ==
'/') {
251 FilePath::operator string()
const {
252 return abs_file_path_->string();
259 boost::filesystem::create_directories(dir);
260 }
catch (boost::filesystem::filesystem_error &e) {
267 {
return *
abs_file_path_ == boost::filesystem::path(
string(other) ); }
271 return ( stream <<
string(fp) );
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than) only for debug mode.
Dedicated class for storing path to input and output files.
FileType
Possible types of file.
static void set_dirs(const string root, const string input, const string output)
Method for set input and output directories.
std::shared_ptr< boost::filesystem::path > abs_file_path_
Final absolute path to the file.
string cut_extension() const
static std::shared_ptr< boost::filesystem::path > root_dir
Prefix path for input files (directory of the main input file).
static std::map< string, string > placeholder
dictionary of placeholders
static string convert_for_check_absolute(string path)
Prepare path string for check absolute path.
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.
static std::shared_ptr< boost::filesystem::path > output_dir
Prefix path for output files.
string parent_path() const
void substitute_value(string &path)
static const string get_absolute_working_dir()
static void add_placeholder(string key, string value)
Add new item to place holder.
static void create_dir(const boost::filesystem::path &dir)
FileType file_type_
File type.
bool operator==(const FilePath &other) const
Equality comparison operators for FilePaths.
void open_stream(Stream &stream) const
static string set_dirs_from_input(const string main_yaml, const string input, const string output)
Method for set input and output directories.
EI_NestedMessage make_nested_message(Exc &e)
std::ostream & operator<<(std::ostream &stream, const FilePath &fp)
Allow redirect FilePath to stream.
string create_path_from_vec(vector< string > sub_paths)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
static constexpr bool value
#define WarningOut()
Macro defining 'warning' record of log.