mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add fileName /= operator (similar to std::filesystem::path)
This commit is contained in:
@ -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 dest is a directory, create the destination file name.
|
||||||
if (destFile.type() == fileName::DIRECTORY)
|
if (destFile.type() == fileName::DIRECTORY)
|
||||||
{
|
{
|
||||||
destFile = destFile/src.name();
|
destFile /= src.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the destination directory exists.
|
// 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 dest is a directory, create the destination file name.
|
||||||
if (destFile.type() == fileName::DIRECTORY)
|
if (destFile.type() == fileName::DIRECTORY)
|
||||||
{
|
{
|
||||||
destFile = destFile/src.name();
|
destFile /= src.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the destination directory exists.
|
// 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 dest is a directory, create the destination file name.
|
||||||
if (destFile.type() == fileName::DIRECTORY)
|
if (destFile.type() == fileName::DIRECTORY)
|
||||||
{
|
{
|
||||||
destFile = destFile/src.components().last();
|
destFile /= src.components().last();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the destination directory exists.
|
// 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 * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::fileName Foam::operator/(const string& a, const string& b)
|
Foam::fileName Foam::operator/(const string& a, const string& b)
|
||||||
|
|||||||
@ -130,7 +130,7 @@ public:
|
|||||||
fileName(Istream& is);
|
fileName(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
//- Is this character valid for a fileName?
|
//- Is this character valid for a fileName?
|
||||||
inline static bool valid(char c);
|
inline static bool valid(char c);
|
||||||
@ -334,6 +334,13 @@ public:
|
|||||||
void operator=(const char* str);
|
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
|
// IOstream operators
|
||||||
|
|
||||||
friend Istream& operator>>(Istream& is, fileName& fn);
|
friend Istream& operator>>(Istream& is, fileName& fn);
|
||||||
|
|||||||
Reference in New Issue
Block a user