Commit 1334467e authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

rename Vtk::path to Vtk::path and use camelCase function names

parent 6b0d1620
......@@ -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();
......
......@@ -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);
......
......@@ -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;
......
......@@ -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";
......
......@@ -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;
......
......@@ -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
......@@ -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();
......
......@@ -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"));
......
......@@ -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"));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment