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);
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>
213 if ( std::is_same<Stream, ifstream>::value )
ASSERT(
file_type_ == FileType::input_file);
214 if ( std::is_same<Stream, ofstream>::value )
ASSERT(
file_type_ == FileType::output_file);
221 if (! stream.is_open())
240 ASSERT(path.length()).error(
"Empty path.");
242 if (path[0] ==
'/') {
251 FilePath::operator string()
const {
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) );
FileType
Possible types of file.
std::ostream & operator<<(std::ostream &stream, const FilePath &fp)
Allow redirect FilePath to stream.
#define ASSERT_GT(a, b)
Definition of comparative assert macro (Greater Than)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
static std::shared_ptr< boost::filesystem::path > root_dir
Prefix path for input files (directory of the main input file).
EI_NestedMessage make_nested_message(Exc &e)
static string set_dirs_from_input(const string main_yaml, const string input, const string output)
Method for set input and output directories.
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.
void open_stream(Stream &stream) const
static void add_placeholder(string key, string value)
Add new item to place holder.
std::shared_ptr< boost::filesystem::path > abs_file_path_
Final absolute path to the file.
string create_path_from_vec(vector< string > sub_paths)
string cut_extension() const
static string convert_for_check_absolute(string path)
Prepare path string for check absolute path.
string parent_path() const
static const string get_absolute_working_dir()
Dedicated class for storing path to input and output files.
bool operator==(const FilePath &other) const
Equality comparison operators for FilePaths.
static std::map< string, string > placeholder
dictionary of placeholders
static std::shared_ptr< boost::filesystem::path > output_dir
Prefix path for output files.
#define WarningOut()
Macro defining 'warning' record of log.
static void create_dir(const boost::filesystem::path &dir)
static void set_dirs(const string root, const string input, const string output)
Method for set input and output directories.
void substitute_value(string &path)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
FileType file_type_
File type.
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)