diff --git a/dune/vtk/pvdwriter.impl.hh b/dune/vtk/pvdwriter.impl.hh index e7b7a563540a85f18ff7956ba16175ec791d70a5..e814131bf60c38fb9439d0c8d49ac3a513be7ba2 100644 --- a/dune/vtk/pvdwriter.impl.hh +++ b/dune/vtk/pvdwriter.impl.hh @@ -12,13 +12,13 @@ template <class W> void PvdWriter<W> ::writeTimestep (double time, std::string const& fn, std::optional<std::string> dir, bool writeCollection) const { - auto p = Vtk::path(fn); + auto p = Vtk::Path(fn); auto name = p.stem(); p.remove_filename(); - Vtk::path fn_dir = p; - Vtk::path data_dir = dir ? Vtk::path(*dir) : fn_dir; - Vtk::path rel_dir = Vtk::relative(data_dir, fn_dir); + Vtk::Path fn_dir = p; + Vtk::Path data_dir = dir ? Vtk::Path(*dir) : fn_dir; + Vtk::Path rel_dir = Vtk::relative(data_dir, fn_dir); std::string pvd_fn = fn_dir.string() + '/' + name.string(); std::string seq_fn = data_dir.string() + '/' + name.string() + "_t" + std::to_string(timesteps_.size()); @@ -52,7 +52,7 @@ template <class W> std::string PvdWriter<W> ::write (std::string const& fn, std::optional<std::string> /*dir*/) const { - auto p = Vtk::path(fn); + auto p = Vtk::Path(fn); auto name = p.stem(); p.remove_filename(); p /= name.string(); diff --git a/dune/vtk/reader.impl.hh b/dune/vtk/reader.impl.hh index 542f8371976b89338bdbc57d52aaf1d1b53766a3..c3a0bf01d1ff337891f3bc679c43d98ea203927c 100644 --- a/dune/vtk/reader.impl.hh +++ b/dune/vtk/reader.impl.hh @@ -25,7 +25,7 @@ void VtkReader<Grid,Creator>::read (std::string const& filename, bool fillCreato std::ifstream input(filename, std::ios_base::in | std::ios_base::binary); assert(input.is_open()); - std::string ext = Vtk::path(filename).extension().string(); + std::string ext = Vtk::Path(filename).extension().string(); if (ext == ".vtu") { readSerialFileFromStream(input, fillCreator); pieces_.push_back(filename); diff --git a/dune/vtk/timeserieswriter.hh b/dune/vtk/timeserieswriter.hh index ba500528b2cd15922825d297ee58062242a0b83d..7d606895467c94d74d70b45089bcf37bc64eb274 100644 --- a/dune/vtk/timeserieswriter.hh +++ b/dune/vtk/timeserieswriter.hh @@ -47,7 +47,7 @@ namespace Dune std::srand(std::time(nullptr)); // put temporary file to /tmp directory - tmpDir_ = Vtk::path("/tmp/vtktimeserieswriter_" + Vtk::uid(10) + "/"); + tmpDir_ = Vtk::Path("/tmp/vtktimeserieswriter_" + Vtk::uid(10) + "/"); } /// Remove all written intermediate files and remove temporary directory @@ -98,7 +98,7 @@ namespace Dune protected: VtkWriter vtkWriter_; - Vtk::path tmpDir_; + Vtk::Path tmpDir_; mutable bool initialized_ = false; diff --git a/dune/vtk/timeserieswriter.impl.hh b/dune/vtk/timeserieswriter.impl.hh index 3a3ef66bc67c8ecaf5663c6a28aaccb482ed6a47..f1d22f690cd6264a35148a4d843bff3392f1ba55 100644 --- a/dune/vtk/timeserieswriter.impl.hh +++ b/dune/vtk/timeserieswriter.impl.hh @@ -41,8 +41,8 @@ template <class W> void VtkTimeseriesWriter<W> ::writeTimestep (double time, std::string const& fn, std::optional<std::string> tmpDir, bool writeCollection) const { - auto name = Vtk::path(fn).stem(); - auto tmpBase = tmpDir ? Vtk::path(*tmpDir) : tmpDir_; + auto name = Vtk::Path(fn).stem(); + auto tmpBase = tmpDir ? Vtk::Path(*tmpDir) : tmpDir_; auto tmp = tmpBase; tmp /= name.string(); @@ -79,13 +79,13 @@ std::string VtkTimeseriesWriter<W> { assert( initialized_ ); - auto p = Vtk::path(fn); + auto p = Vtk::Path(fn); auto name = p.stem(); p.remove_filename(); - Vtk::path fn_dir = p; - Vtk::path data_dir = dir ? Vtk::path(*dir) : fn_dir; - Vtk::path rel_dir = Vtk::relative(data_dir, fn_dir); + Vtk::Path fn_dir = p; + Vtk::Path data_dir = dir ? Vtk::Path(*dir) : fn_dir; + Vtk::Path rel_dir = Vtk::relative(data_dir, fn_dir); std::string serial_fn = fn_dir.string() + '/' + name.string() + "_ts"; std::string parallel_fn = data_dir.string() + '/' + name.string() + "_ts"; diff --git a/dune/vtk/utility/filesystem.cc b/dune/vtk/utility/filesystem.cc index 96459982fa42768d1c83de671fbb4883c3f85278..42eb07cb48d16efb9396e42de4ff2ae9921ee9db 100644 --- a/dune/vtk/utility/filesystem.cc +++ b/dune/vtk/utility/filesystem.cc @@ -21,9 +21,10 @@ template <class... Args> void inline _ignore_(Args&&...) {} -namespace Dune { namespace Vtk { +namespace Dune { +namespace Vtk { -std::string path::string() const +std::string Path::string() const { if (empty()) return "."; @@ -31,12 +32,12 @@ std::string path::string() const auto it = begin(); auto result = *it; for (++it; it != end(); ++it) - result += preferred_separator + *it; + result += preferredSeparator + *it; return result; } -void path::split(std::string p) +void Path::split(std::string p) { std::string separators = "/\\"; bool relative = true; @@ -62,7 +63,7 @@ void path::split(std::string p) } -path path::stem() const +Path Path::stem() const { auto f = filename().string(); auto pos = f.find_last_of('.'); @@ -73,7 +74,7 @@ path path::stem() const } -path path::extension() const +Path Path::extension() const { auto f = filename().string(); auto pos = f.find_last_of('.'); @@ -84,7 +85,7 @@ path path::extension() const } -bool path::is_absolute(std::string p) +bool Path::isAbsolute(std::string p) { if (p[0] == '/') return true; @@ -97,15 +98,15 @@ bool path::is_absolute(std::string p) } -path& path::operator/=(path const& p) +Path& Path::operator/=(Path const& p) { insert(end(), p.begin(), p.end()); - original += preferred_separator + p.original; + original += preferredSeparator + p.original; return *this; } -bool path::is_file() const +bool Path::isFile() const { std::string p = this->string(); struct stat info; @@ -113,7 +114,7 @@ bool path::is_file() const } -bool path::is_directory() const +bool Path::isDirectory() const { std::string p = this->string(); struct stat info; @@ -121,7 +122,7 @@ bool path::is_directory() const } -path current_path() +Path currentPath() { char cwd_[FILENAME_MAX]; _ignore_(GET_CURRENT_DIR(cwd_, sizeof(cwd_))); @@ -130,20 +131,20 @@ path current_path() } -bool exists(path const& p) +bool exists(Path const& p) { - return p.is_file() || p.is_directory(); + return p.isFile() || p.isDirectory(); } -bool create_directories(path const& p) +bool createDirectories(Path const& p) { - if (p.is_directory()) + if (p.isDirectory()) return true; - auto parent = p.parent_path(); - if (!parent.empty() && !parent.is_directory()) - create_directories(parent); + auto parent = p.parentPath(); + if (!parent.empty() && !parent.isDirectory()) + createDirectories(parent); #ifdef _WIN32 int ret = _mkdir(p.string().c_str()); @@ -169,7 +170,7 @@ bool create_directories(path const& p) } } -path relative(path const& a, path const& b) +Path relative(Path const& a, Path const& b) { // find common base path auto a_it = a.begin(); @@ -180,7 +181,7 @@ path relative(path const& a, path const& b) } // combine remaining parts of a to result path - path rel("."); + Path rel("."); for (; a_it != a.end(); ++a_it) rel /= *a_it; diff --git a/dune/vtk/utility/filesystem.hh b/dune/vtk/utility/filesystem.hh index ab7e148b7e7b6446ab6d0a163ddbedd95ab0692d..827273a2ceef956bb1bbcf37fe2cf27a1d939fb7 100644 --- a/dune/vtk/utility/filesystem.hh +++ b/dune/vtk/utility/filesystem.hh @@ -9,9 +9,8 @@ namespace Dune { namespace Vtk { - // A minimalistic filesystem class - class path + class Path : public std::vector<std::string> { using Super = std::vector<std::string>; @@ -20,58 +19,58 @@ namespace Dune public: #ifdef _WIN32 - static constexpr char preferred_separator = '\\'; + static constexpr char preferredSeparator = '\\'; #else - static constexpr char preferred_separator = '/'; + static constexpr char preferredSeparator = '/'; #endif public: - path() = default; + Path() = default; // NOTE: implicit conversion is allowed here template <class String> - path(String const& p) + Path(String const& p) : original(p) { split(p); } template <class InputIt> - path(InputIt it, InputIt end_it) + Path(InputIt it, InputIt end_it) : Super(it, end_it) { original = this->string(); } template <class String> - path(std::initializer_list<String> const& list) - : path(list.begin(), list.end()) + Path(std::initializer_list<String> const& list) + : Path(list.begin(), list.end()) {} /// Removes filename path component - path& remove_filename() + Path& removeFilename() { this->pop_back(); return *this; } /// Returns the path of the parent path - path parent_path() const + Path parentPath() const { - return empty() ? path() : path(begin(), --end()); + return empty() ? Path() : Path(begin(), --end()); } /// Returns filename path component - path filename() const + Path filename() const { - return empty() ? path() : path(back()); + return empty() ? Path() : Path(back()); } /// Returns the stem path component - path stem() const; + Path stem() const; /// Returns the file extension path component - path extension() const; + Path extension() const; /// Return the path as string std::string string() const; @@ -80,30 +79,30 @@ namespace Dune /** In Linux, test whether the path starts with `/`, in Windows whether it starts * with `[a-z]:\\`. **/ - static bool is_absolute(std::string p); + static bool isAbsolute(std::string p); - bool is_absolute() const { return is_absolute(original); } + bool isAbsolute() const { return isAbsolute(original); } - bool is_relative() const { return !is_absolute(); } + bool isRelative() const { return !isAbsolute(); } /// Check whether path is a regular file - bool is_file() const; + bool isFile() const; /// Check whether path is a regular file - bool is_directory() const; + bool isDirectory() const; /// Lexicographically compares two paths - bool operator==(path const& p) + bool operator==(Path const& p) { return this->string() == p.string(); } /// Appends elements to the path - path& operator/=(path const& p); + Path& operator/=(Path const& p); /// output of the path template <class CharT, class Traits> - friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& out, path const& p) + friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& out, Path const& p) { out << '"' << p.string() << '"'; return out; @@ -120,16 +119,16 @@ namespace Dune }; /// Test whether the path is a valid (existing and accessible) file / directory - bool exists(path const&); + bool exists(Path const&); /// Create directory and non existing parent directories. - bool create_directories(path const&); + bool createDirectories(Path const&); /// Returns the current path - path current_path(); + Path currentPath(); /// Find the path of `a` relative to directory of `b` - path relative(path const& a, path const& b); + Path relative(Path const& a, Path const& b); } // end namespace Vtk } // end namespace Dune diff --git a/dune/vtk/writerinterface.impl.hh b/dune/vtk/writerinterface.impl.hh index fbd7d5010ca1d5f98287751512dc3d7a98a41e80..830070c081c4dd7e28ce098fdb7bc246ddf49d88 100644 --- a/dune/vtk/writerinterface.impl.hh +++ b/dune/vtk/writerinterface.impl.hh @@ -28,13 +28,13 @@ std::string VtkWriterInterface<GV,DC> { dataCollector_->update(); - auto p = Vtk::path(fn); + auto p = Vtk::Path(fn); auto name = p.stem(); p.remove_filename(); - Vtk::path fn_dir = p; - Vtk::path data_dir = dir ? Vtk::path(*dir) : fn_dir; - Vtk::path rel_dir = Vtk::relative(data_dir, fn_dir); + Vtk::Path fn_dir = p; + Vtk::Path data_dir = dir ? Vtk::Path(*dir) : fn_dir; + Vtk::Path rel_dir = Vtk::relative(data_dir, fn_dir); std::string serial_fn = data_dir.string() + '/' + name.string(); std::string parallel_fn = fn_dir.string() + '/' + name.string(); diff --git a/src/test/parallel_reader_writer_test.cc b/src/test/parallel_reader_writer_test.cc index c15ccf602b8d392e82a21298f48b31cc7c87b18e..ddb20e6a802cc22b18886951cd3ed71995bd5b79 100644 --- a/src/test/parallel_reader_writer_test.cc +++ b/src/test/parallel_reader_writer_test.cc @@ -79,7 +79,7 @@ using HasParallelGridFactory = Std::is_detected<HasParallelGridFactoryImpl, Grid template <class Test> -void compare (Test& test, Vtk::path const& dir, Vtk::path const& name) +void compare (Test& test, Vtk::Path const& dir, Vtk::Path const& name) { test.check(compare_files(dir.string() + '/' + name.string() + ".vtu", dir.string() + '/' + name.string() + "_2.vtu")); diff --git a/src/test/reader_writer_test.cc b/src/test/reader_writer_test.cc index d9e6fbbfb410527f38c8ab47b55759c731b2d0d1..cc86f7b6c439b3693f5edb559ad4a270643e75f5 100644 --- a/src/test/reader_writer_test.cc +++ b/src/test/reader_writer_test.cc @@ -80,7 +80,7 @@ static TestCases test_cases = { }; template <class Test> -void compare (Test& test, Vtk::path const& dir, Vtk::path const& name) +void compare (Test& test, Vtk::Path const& dir, Vtk::Path const& name) { test.check(compare_files(dir.string() + '/' + name.string() + ".vtu", dir.string() + '/' + name.string() + "_2.vtu"));