17 #include <boost/algorithm/string.hpp>
19 #include <unordered_map>
45 return fs::exists(fs::path(strFilename));
48 std::tuple<std::string, std::string::size_type, std::string::size_type>
51 char const close_char,
52 std::string::size_type pos)
54 auto const pos_curly_brace_open = in.find_first_of(open_char, pos);
55 if (pos_curly_brace_open == std::string::npos)
57 return std::make_tuple(
"", std::string::npos, std::string::npos);
59 auto const pos_curly_brace_close =
60 in.find_first_of(close_char, pos_curly_brace_open);
61 if (pos_curly_brace_close == std::string::npos)
63 return std::make_tuple(
"", std::string::npos, std::string::npos);
65 return std::make_tuple(
66 in.substr(pos_curly_brace_open + 1,
67 pos_curly_brace_close - (pos_curly_brace_open + 1)),
68 pos_curly_brace_open, pos_curly_brace_close);
73 auto const position = str.find(keyword);
74 if (position != std::string::npos)
76 return str.substr(0, position);
83 std::string::size_type begin, std::string::size_type end,
84 std::string
const& keyword, T& data)
86 std::string precision_specification =
89 if (precision_specification.empty())
94 std::unordered_map<std::type_index, char> type_specification;
95 type_specification[std::type_index(
typeid(
int))] =
'd';
96 type_specification[std::type_index(
typeid(
double))] =
'f';
97 type_specification[std::type_index(
typeid(std::string))] =
's';
99 auto const& b = precision_specification.back();
101 if (b ==
'e' || b ==
'E' || b ==
'f' || b ==
'F' || b ==
'g' || b ==
'G')
103 type_specification[std::type_index(
typeid(
double))] = b;
104 precision_specification = precision_specification.substr(
105 0, precision_specification.length() - 1);
108 std::string
const generated_fmt_string =
109 "{" + precision_specification +
110 type_specification[std::type_index(
typeid(data))] +
"}";
111 result = result.substr(0, begin) +
fmt::format(generated_fmt_string, data) +
112 result.substr(end + 1, result.length() - (end + 1));
117 std::string
const& mesh_name,
122 char const open_char =
'{';
123 char const close_char =
'}';
124 std::string::size_type begin = 0;
125 std::string::size_type end = std::string::npos;
126 std::string result = format_specification;
128 while (begin != std::string::npos)
130 auto length_before_substitution = result.length();
132 std::string str =
"";
133 std::tie(str, begin, end) =
141 begin = end - (length_before_substitution - result.length());
152 char c[
sizeof(double)];
156 for (
unsigned short i = 0; i <
sizeof(double) / 2; i++)
158 b.c[i] = a.c[
sizeof(double) / 2 - i - 1];
161 for (
unsigned short i =
sizeof(
double) / 2; i <
sizeof(double); i++)
163 b.c[i] = a.c[
sizeof(double) +
sizeof(
double) / 2 - i - 1];
171 auto const filename_path = fs::path(filename);
172 return (filename_path.parent_path() / filename_path.stem()).string();
177 return fs::path(pathname).filename().string();
188 return fs::path(path).extension().string();
197 const std::string& source)
199 auto filePath = fs::path(file_name);
200 if (filePath.has_parent_path())
202 return filePath.string();
204 return (fs::path(source) /= filePath).string();
209 return fs::path(pathname).parent_path().string();
212 std::string
joinPaths(std::string
const& pathA, std::string
const& pathB)
214 return (fs::path(pathA) /= fs::path(pathB)).string();
221 OGS_FATAL(
"The project directory has not yet been set.");
230 OGS_FATAL(
"The project directory has already been set.");
238 bool const success = fs::remove(fs::path(filename));
241 DBUG(
"Removed '{:s}'", filename);
247 for (
auto const& file : files)
void DBUG(char const *fmt, Args const &... args)
std::string containsKeyword(std::string const &str, std::string const &keyword)
std::string constructFormattedFileName(std::string const &format_specification, std::string const &mesh_name, int const timestep, double const t, int const iteration)
void removeFile(std::string const &filename)
std::string const & getProjectDirectory()
Returns the directory where the prj file resides.
std::string getFileExtension(const std::string &path)
std::string extractPath(std::string const &pathname)
bool substituteKeyword(std::string &result, std::string &parenthesized_string, std::string::size_type begin, std::string::size_type end, std::string const &keyword, T &data)
std::tuple< std::string, std::string::size_type, std::string::size_type > getParenthesizedString(std::string const &in, char const open_char, char const close_char, std::string::size_type pos)
bool IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
std::string copyPathToFileName(const std::string &file_name, const std::string &source)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::string dropFileExtension(std::string const &filename)
bool isProjectDirectorySet()
Returns true if the project directory is set.
std::string joinPaths(std::string const &pathA, std::string const &pathB)
std::string extractBaseName(std::string const &pathname)
double swapEndianness(double const &v)
std::string format(const char *format_str,...)
void setProjectDirectory(std::string const &dir)
Sets the project directory.
bool hasFileExtension(std::string const &extension, std::string const &filename)
void removeFiles(std::vector< std::string > const &files)