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) );