Commit eaed36c2 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

renamed path to Path and use camelCase names

parent 0bf4fa59
......@@ -134,6 +134,7 @@ namespace Dune
void readString(std::istream& stream, std::string& name)
{
DUNE_THROW(Dune::NotImplemented, "Method readString() not yet implemented");
name = "Hallo";
}
......
......@@ -21,31 +21,29 @@
template <class... Args>
void inline _ignore_(Args&&...) {}
namespace Dune
{
namespace Gmsh4
{
namespace Dune {
namespace Gmsh4 {
std::string Path::string() const
{
std::string Path::string() const
{
if (empty())
return ".";
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;
Gmsh4::trim(p);
Gmsh4::split(p.begin(), p.end(), separators.begin(), separators.end(),
trim(p);
Dune::Vtk::split(p.begin(), p.end(), separators.begin(), separators.end(),
[this,&relative](auto first, auto end)
{
auto token = std::string(first, end);
......@@ -62,33 +60,33 @@ namespace Dune
}
}
});
}
}
Path Path::stem() const
{
Path Path::stem() const
{
auto f = filename().string();
auto pos = f.find_last_of('.');
if (f == "." || f == ".." || pos == std::string::npos)
return {f};
else
return {f.substr(0,pos)};
}
}
Path Path::extension() const
{
Path Path::extension() const
{
auto f = filename().string();
auto pos = f.find_last_of('.');
if (f == "." || f == ".." || pos == std::string::npos)
return {};
else
return {f.substr(pos)};
}
}
bool Path::is_absolute(std::string p)
{
bool Path::isAbsolute(std::string p)
{
if (p[0] == '/')
return true;
......@@ -97,63 +95,63 @@ namespace Dune
return true;
return false;
}
}
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;
return stat(p.c_str(), &info) == 0 && (info.st_mode & S_IFREG) != 0;
}
}
bool Path::is_directory() const
{
bool Path::isDirectory() const
{
std::string p = this->string();
struct stat info;
return stat(p.c_str(), &info) == 0 && (info.st_mode & S_IFDIR) != 0;
}
}
Path current_path()
{
Path currentPath()
{
char cwd_[FILENAME_MAX];
_ignore_(GET_CURRENT_DIR(cwd_, sizeof(cwd_)));
std::string cwd(cwd_);
return { Gmsh4::trim(cwd) };
}
return { trim(cwd) };
}
bool exists(Path const& p)
{
return p.is_file() || p.is_directory();
}
bool exists(Path const& p)
{
return p.isFile() || p.isDirectory();
}
bool create_directories(Path const& p)
{
if (p.is_directory())
bool createDirectories(Path const& p)
{
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
#ifdef _WIN32
int ret = _mkdir(p.string().c_str());
#else
#else
mode_t mode = 0755;
int ret = mkdir(p.string().c_str(), mode);
#endif
#endif
if (ret == 0)
return true;
......@@ -170,10 +168,10 @@ namespace Dune
default:
return false;
}
}
}
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();
auto b_it = b.begin();
......@@ -188,7 +186,6 @@ namespace Dune
rel /= *a_it;
return rel;
}
}
} // end namespace Gmsh4
} // end namespace Dune
} } // end namespace Dune::Gmsh4
......@@ -9,7 +9,6 @@ namespace Dune
{
namespace Gmsh4
{
// A minimalistic filesystem class
class Path
: public std::vector<std::string>
......@@ -20,9 +19,9 @@ 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:
......@@ -49,14 +48,14 @@ namespace Dune
{}
/// 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());
}
......@@ -80,17 +79,17 @@ 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)
......@@ -123,10 +122,10 @@ namespace Dune
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);
......
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