Commit dd67b338 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add fileName /= operator (similar to std::filesystem::path)

parent 0b703011
......@@ -824,7 +824,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
// If dest is a directory, create the destination file name.
if (destFile.type() == fileName::DIRECTORY)
{
destFile = destFile/src.name();
destFile /= src.name();
}
// Make sure the destination directory exists.
......@@ -864,7 +864,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
// If dest is a directory, create the destination file name.
if (destFile.type() == fileName::DIRECTORY)
{
destFile = destFile/src.name();
destFile /= src.name();
}
// Make sure the destination directory exists.
......@@ -880,7 +880,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
// If dest is a directory, create the destination file name.
if (destFile.type() == fileName::DIRECTORY)
{
destFile = destFile/src.components().last();
destFile /= src.components().last();
}
// Make sure the destination directory exists.
......
......@@ -533,6 +533,30 @@ void Foam::fileName::operator=(const char* str)
}
Foam::fileName& Foam::fileName::operator/=(const string& other)
{
fileName& s = *this;
if (s.size())
{
if (other.size())
{
// Two non-empty strings: can concatenate
s.append("/");
s.append(other);
}
}
else if (other.size())
{
// Or, if the first string is empty
s = other;
}
return *this;
}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
Foam::fileName Foam::operator/(const string& a, const string& b)
......
......@@ -130,7 +130,7 @@ public:
fileName(Istream& is);
// Member functions
// Member Functions
//- Is this character valid for a fileName?
inline static bool valid(char c);
......@@ -188,7 +188,7 @@ public:
fileName clean() const;
// Interrogation
// Interrogation
//- Return the file type: FILE, DIRECTORY, LINK or UNDEFINED.
// LINK is only returned if followLink=false
......@@ -210,7 +210,7 @@ public:
inline bool isBackup() const;
// Decomposition
// Decomposition
//- Return basename (part beyond last /), including its extension
// The result normally corresponds to a Foam::word
......@@ -316,7 +316,7 @@ public:
// Member operators
// Assignment
// Assignment
//- Copy, no character validation required
void operator=(const fileName& str);
......@@ -334,6 +334,13 @@ public:
void operator=(const char* str);
// Other operators
//- Append a path element with '/' separator.
// No '/' separator is added if this or the argument are empty.
fileName& operator/=(const string& other);
// IOstream operators
friend Istream& operator>>(Istream& is, fileName& fn);
......
Markdown is supported
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